Tutorial Microcontroller MCS-51 ATMEL ISP
 

 

Super MCS51 Trainer

Standart MCS51 Trainer

Standart AVR Trainer

Programmer USBASP

Standart ARM Trainer

 

Baby NURSE CALL WITH BODY TEMPERATURE SENSOR, SENSOR BASED VOICE AND INFANT bedwetting AT89S51 MICROCONTROLLER WITH SOUND OUTPUT

A nurse call button is a button found around a hospital bed that allows patients in health care settings to alert a nurse or other health care staff member remotely of their need for help. When the button is pressed, a signal alerts staff at the nurse's station, and usually, a nurse or nurse assistant responds to such a call. Some systems also allow the patient to speak directly to the staffer; others simply beep or buzz at the station, requiring a staffer to actually visit the patient's room to determine the patient's needs.

Figure 1. Master Minimum System AT89S52

 

Figure 2. ISD 2560 Voice Recorder

Figure 3. Multi Point serial MAX 485

 

           SLAVE1CODE EQU 00H
           SLAVE2CODE EQU 01H
           SLAVE3CODE EQU 02H
           SLAVE4CODE EQU 03H
           ZERO EQU 11000000B
           ONE EQU 11111001B
           TWO EQU 10100100B
           THREE EQU 10110000B
           FOUR EQU 10011001B
           FIVE EQU 10010010B
           SIX EQU 10000010B
           SEVEN EQU 11111000B
           EIGHT EQU 10000000B
           NINE EQU 10010000B
           SUHU_TUBUH EQU 00000000B
           BAYI EQU 00000111B
           BED1 EQU 00001100B
           BED2 EQU 00010010B
           BED3 EQU 00011000B
           BED4 EQU 00011111B
           TINGGI EQU 00100101B
           RENDAH EQU 00101010B
           NGOMPOL EQU 00101110B
           NANGIS EQU 00110011B
           SATU EQU 00111000B
           DUA EQU 00111101B
           TIGA EQU 01000010B
           EMPAT EQU 01000111B
           LIMA EQU 01001011B
           ENAM EQU 01010000B
           TUJUH EQU 01010101B
           DELAPAN EQU 01011011B
           SEMBILAN EQU 01100001B
           PULUH EQU 01100110B
           DERAJAT_CEL EQU 01101010B
           KOMA EQU 01110011B
           ORG 00H
           SJMP BEGIN
           ORG 03H
           MOV R7,#250
DEL_INT:   MOV R2,#200
           DJNZ R2,$
           DJNZ R7,DEL_INT
           MOV R3,#1
           RETI
           ;***************************
           ; interrupt initialization
           ;***************************
BEGIN:     MOV IP,#00000001B
           MOV IE,#10000000B
           ;****************************
           ; serial port initialization
           ;****************************
           MOV SCON,#11111010B ;enable multiprocessor ability
           MOV TMOD,#00100000B
           MOV TH1,#0E8H
           SETB TR1
           ;********************************
           ; voice rec. chip initialization
           ;********************************
           MOV P1,#0
           MOV P2,#0.
           MOV R3,#0
           ;************************
           ; seven segments testing
           ;************************
           ACALL DEL1s
           MOV A,#9
LOOP_WHILE:PUSH ACC
           ACALL CONVERSION
           MOV P0,A
           ACALL DEL1s
           POP ACC
           DEC ACC
           CJNE A,#255,LOOP_WHILE
           MOV P0,A
           SETB EX0 ;enable interrupt 0
           ;******************************************
           ; on line checking & wait the confirmation
           ;******************************************
RECHK_SLV: MOV A,#SLAVE1CODE
           ACALL SEND_COMMAND
SEND_EXIST:CLR P3.4 ;order RS485 to receive
           MOV R6,#255
MORE_R7:   MOV R7,#255
CEK_LG:    JNB RI,DEC_R7
           CLR RI
           MOV A,SBUF
           CJNE A,#SLAVE1CODE,SLV2_CHK
           SJMP PICK_SLV1
SLV2_CHK:  CJNE A,#SLAVE2CODE,SLV3_CHK
           AJMP PICK_SLV2
SLV3_CHK:  CJNE A,#SLAVE3CODE,SLV4_CHK
           AJMP PICK_SLV3
SLV4_CHK:  AJMP PICK_SLV4
DEC_R7:    DJNZ R7,CEK_LG
           DJNZ R6,MORE_R7
           CJNE A,#SLAVE1CODE,SLV2
           SJMP CHECK_UP_2
SLV2:      CJNE A,#SLAVE2CODE,SLV3
           SJMP CHECK_UP_3
SLV3:      CJNE A,#SLAVE3CODE,SLV4
           SJMP CHECK_UP_4
SLV4:      SJMP RECHK_SLV
CHECK_UP_2:MOV A,#SLAVE2CODE
           ACALL SEND_COMMAND
           SJMP SEND_EXIST
CHECK_UP_3:MOV A,#SLAVE3CODE
           ACALL SEND_COMMAND
           SJMP SEND_EXIST
CHECK_UP_4:MOV A,#SLAVE4CODE
           ACALL SEND_COMMAND
           SJMP SEND_EXIST
PICK_SLV1: MOV A,#SLAVE1CODE ;order Slave1 ADC to sample data
           ACALL SEND_COMMAND
           CLR SM2 ;obtain Slave1 ADC data
           ACALL RECV_DATA
           MOV R6,A ;ADC data was already in R6
           MOV A,#SLAVE1CODE ;order Slave1 to obtain other data
           ACALL SEND_COMMAND
           ACALL RECV_DATA
           MOV R5,A ;other data was already in R5
           MOV R4,#1 ;slave 1 code
           MOV A,R6
           CJNE A,#23,NOT_EQ_23_1 ;23D = 36.5 celcius degree
           SJMP NEXT_SENSOR_1
NOT_EQ_23_1:
           JC UNDER_23_1
           CJNE A,#25,NOT_EQ_25_1 ;25D = 37.5 celcius degree
           SJMP NEXT_SENSOR_1
NOT_EQ_25_1:
JC UNDER_25_1 SETB F0 ;action above 37.5 degree SJMP ABOVE_25_1 UNDER_25_1:SJMP NEXT_SENSOR_1 UNDER_23_1:CLR F0 ;action under 36.5 degree ABOVE_25_1:MOV A,#1 ACALL CONVERSION MOV P0,A ACALL VOICE_DEGREE
NEXT_SENSOR_1: 
MOV A,R5 ANL A,#00001100B JNZ CRY_SENSOR_1 MOV A,#1 ;crying & urinating are detected ACALL CONVERSION MOV P0,A ACALL VOICE_CRY ACALL VOICE_URIN SJMP NO_CRY_URIN_1 CRY_SENSOR_1: CJNE A,#00000100B,URIN_SENSOR_1 MOV A,#1 ;crying is detected ACALL CONVERSION MOV P0,A ACALL VOICE_CRY SJMP NO_CRY_URIN_1 URIN_SENSOR_1: CJNE A,#00001000B,NO_CRY_URIN_1 MOV A,#1 ;urinating is detected ACALL CONVERSION MOV P0,A ACALL VOICE_URIN NO_CRY_URIN_1: MOV P0,#11111111B SETB SM2 SJMP CHECK_UP_2
PICK_SLV2: MOV A,#SLAVE2CODE ;order Slave2 ADC to sample data
           ACALL SEND_COMMAND
           CLR SM2 ;obtain Slave2 ADC data
           ACALL RECV_DATA
           MOV R6,A
           MOV A,#SLAVE2CODE ;order Slave2 to obtain other data
           ACALL SEND_COMMAND
           ACALL RECV_DATA
           MOV R5,A
           MOV R4,#2 ;slave 2 code
           MOV A,R6
           CJNE A,#23,NOT_EQ_23_2 ;23D = 36.5 celcius degree
           SJMP NEXT_SENSOR_2
           NOT_EQ_23_2: JC UNDER_23_2
           CJNE A,#25,NOT_EQ_25_2 ;25D = 37.5 celcius degree
           SJMP NEXT_SENSOR_2
           NOT_EQ_25_2: JC UNDER_25_2
           SETB F0 ;action above 37.5 degree
           SJMP ABOVE_25_2
           UNDER_25_2: SJMP NEXT_SENSOR_2
           UNDER_23_2: CLR F0 ;action under 36.5 degree
           ABOVE_25_2: MOV A,#2 ;display the slave code at 7 segments
           ACALL CONVERSION
           MOV P0,A
           ACALL VOICE_DEGREE
NEXT_SENSOR_2: MOV A,R5
           ANL A,#00001100B
           JNZ CRY_SENSOR_2
           MOV A,#2 ;crying & urinating are detected
           ACALL CONVERSION
           MOV P0,A
           ACALL VOICE_CRY
           ACALL VOICE_URIN
           SJMP NO_CRY_URIN_2
           CRY_SENSOR_2: CJNE A,#00000100B,URIN_SENSOR_2
           MOV A,#2 ;crying is detected
           ACALL CONVERSION
           MOV P0,A
           ACALL VOICE_CRY
           SJMP NO_CRY_URIN_2
           URIN_SENSOR_2: CJNE A,#00001000B,NO_CRY_URIN_2
           MOV A,#2 ;urinating is detected
           ACALL CONVERSION
           MOV P0,A
           ACALL VOICE_URIN
           NO_CRY_URIN_2: MOV P0,#11111111B
           SETB SM2
           AJMP CHECK_UP_3
PICK_SLV3: MOV A,#SLAVE3CODE ;order Slave3 ADC to sample data
           ACALL SEND_COMMAND
           CLR SM2 ;obtain Slave3 ADC data
           ACALL RECV_DATA
           MOV R6,A
           MOV A,#SLAVE3CODE ;order Slave3 to obtain other data
           ACALL SEND_COMMAND
           ACALL RECV_DATA
           MOV R5,A
           MOV R4,#3 ;slave 3 code
           MOV A,R6
           CJNE A,#23,NOT_EQ_23_3 ;23D = 36.5 celcius degree
           SJMP NEXT_SENSOR_3
NOT_EQ_23_3: JC UNDER_23_3
           CJNE A,#25,NOT_EQ_25_3 ;25D = 37.5 celcius degree
           SJMP NEXT_SENSOR_3
NOT_EQ_25_3: JC UNDER_25_3
           SETB F0 ;action above 37.5 degree
           SJMP ABOVE_25_3
UNDER_25_3: SJMP NEXT_SENSOR_3
UNDER_23_3: CLR F0 ;action under 36.5 degree
ABOVE_25_3: MOV A,#3
           ACALL CONVERSION
           MOV P0,A
           ACALL VOICE_DEGREE
NEXT_SENSOR_3: MOV A,R5
           ANL A,#00001100B
           JNZ CRY_SENSOR_3
           MOV A,#3 ;crying & urinating are detected
           ACALL CONVERSION
           MOV P0,A
           ACALL VOICE_CRY
           ACALL VOICE_URIN
           SJMP NO_CRY_URIN_3
CRY_SENSOR_3: CJNE A,#00000100B,URIN_SENSOR_3
           MOV A,#3 ;crying is detected
           ACALL CONVERSION
           MOV P0,A
           ACALL VOICE_CRY
           SJMP NO_CRY_URIN_3
URIN_SENSOR_3: CJNE A,#00001000B,NO_CRY_URIN_3
           MOV A,#3 ;urinating is detected
           ACALL CONVERSION
           MOV P0,A
           ACALL VOICE_URIN
NO_CRY_URIN_3: MOV P0,#11111111B
           SETB SM2
           AJMP CHECK_UP_4
PICK_SLV4: MOV A,#SLAVE4CODE ;order Slave4 ADC to sample data
           ACALL SEND_COMMAND
           CLR SM2 ;obtain Slave4 ADC data
           ACALL RECV_DATA
           MOV R6,A
           MOV A,#SLAVE4CODE ;order Slave4 to obtain other data
           ACALL SEND_COMMAND
           ACALL RECV_DATA
           MOV R5,A
           MOV R4,#4 ;slave 4 code
           MOV A,R6
           CJNE A,#23,NOT_EQ_23_4 ;23D = 36.5 celcius degree
           SJMP NEXT_SENSOR_4
NOT_EQ_23_4: JC UNDER_23_4
           CJNE A,#25,NOT_EQ_25_4 ;25D = 37.5 celcius degree
           SJMP NEXT_SENSOR_4
NOT_EQ_25_4: JC UNDER_25_4
           SETB F0 ;action above 37.5 degree
           SJMP ABOVE_25_4
UNDER_25_4: SJMP NEXT_SENSOR_4
UNDER_23_4: CLR F0 ;action under 36.5 degree
ABOVE_25_4: MOV A,#4
           ACALL CONVERSION
           MOV P0,A
           ACALL VOICE_DEGREE
NEXT_SENSOR_4: MOV A,R5
           ANL A,#00001100B
           JNZ CRY_SENSOR_4
           MOV A,#4 ;crying & urinating are detected
           ACALL CONVERSION
           MOV P0,A
           ACALL VOICE_CRY
           ACALL VOICE_URIN
           SJMP NO_CRY_URIN_4
           CRY_SENSOR_4: CJNE A,#00000100B,URIN_SENSOR_4
           MOV A,#4 ;crying is detected
           ACALL CONVERSION
           MOV P0,A
           ACALL VOICE_CRY
           SJMP NO_CRY_URIN_4
           URIN_SENSOR_4: CJNE A,#00001000B,NO_CRY_URIN_4
           MOV A,#4 ;urinating is detected
           ACALL CONVERSION
           MOV P0,A
           ACALL VOICE_URIN
           NO_CRY_URIN_4: MOV P0,#11111111B
           SETB SM2
           AJMP RECHK_SLV
           ;*******************
           ; prosedur-prosedur
           ;*******************
           ;***************
           ; 1s delay proc.
           ;***************
DEL1s:     MOV R7,#10
           DELD: MOV R6,#250
           DELC: MOV R5,#200
           DJNZ R5,$
           DJNZ R6,DELC
           DJNZ R7,DELD
           RET
           ;******************
           ; conversion proc.
           ;******************
CONVERSION:CJNE A,#9,EIGHT8
           MOV A,#NINE
           SJMP QUIT
           EIGHT8: CJNE A,#8,SEVEN7
           MOV A,#EIGHT
           SJMP QUIT
           SEVEN7: CJNE A,#7,SIX6
           MOV A,#SEVEN
           SJMP QUIT
           SIX6: CJNE A,#6,FIVE5
           MOV A,#SIX
           SJMP QUIT
           FIVE5: CJNE A,#5,FOUR4
           MOV A,#FIVE
           SJMP QUIT
           FOUR4: CJNE A,#4,THREE3
           MOV A,#FOUR
           SJMP QUIT
           THREE3: CJNE A,#3,TWO2
           MOV A,#THREE
           SJMP QUIT
           TWO2: CJNE A,#2,ONE1
           MOV A,#TWO
           SJMP QUIT
           ONE1: CJNE A,#1,ZERO0
           MOV A,#ONE
           SJMP QUIT
           ZERO0: MOV A,#ZERO
           QUIT: RET
           ;******************
           ; transmit command
           ;******************
SEND_COMMAND: 
SETB P3.4 ;order RS485 to transmit MOV R7,#2 SEND_CODE: JNB TI,SEND_CODE CLR TI MOV SBUF,A DJNZ R7,SEND_CODE RET ;***************** ; receive command ;***************** RECV_DATA: CLR P3.4 ;order RS485 to receive JNB RI,$ CLR RI MOV A,SBUF RET ;********************************* ; voice announcer for temperature ;********************************* VOICE_DEGREE: CLR P3.7 ;PD is low MOV P2,#SUHU_TUBUH ;insert "suhu tubuh" address CLR P3.5 ;trigger SETB P3.5 CJNE R3,#1,$ ;wait interrupt MOV R3,#0 ;delay??? MOV P2,#BAYI ;insert "bayi" address CLR P3.5 ;trigger SETB P3.5 CJNE R3,#1,$ ;wait interrupt & delay MOV R3,#0 CJNE R4,#1,BED_2 ;check R4(R4 is for slave code) MOV P2,#BED1 ;insert "bed1" address SJMP TRIGGER BED_2: CJNE R4,#2,BED_3 MOV P2,#BED2 ;insert "bed2" address SJMP TRIGGER BED_3: CJNE R4,#3,BED_4 MOV P2,#BED3 ;insert "bed3" address SJMP TRIGGER BED_4: MOV P2,#BED4 ;insert "bed4" address TRIGGER:CLR P3.5 ;trigger SETB P3.5 CJNE R3,#1,$ ;wait interrupt & delay MOV R3,#0 JNB F0,LOW_TEMP ;check F0(F0 is for high or low temperature) MOV P2,#TINGGI ;insert "tinggi" address SJMP TRIGGER_2 LOW_TEMP: MOV P2,#RENDAH ;insert "rendah" address TRIGGER_2: CLR P3.5 ;trigger SETB P3.5 CJNE R3,#1,$ ;wait interrupt & delay MOV R3,#0 MOV A,R6 ;binary to decimal conversion(25,0 up to 49,5 celcius degree) ADD A,#50 MOV B,#2 DIV AB PUSH A MOV A,B CJNE A,#1,CLEAR_F0 SETB F0 ;F0 status indicate the number behind decimal point presence SJMP FILL_A CLEAR_F0: CLR F0 FILL_A: POP A MOV B,#10 DIV AB ;B contains LSD ACALL DEC2ADD ;insert msd address CLR P3.5 ;trigger SETB P3.5 CJNE R3,#1,$ ;wait interrupt & delay MOV R3,#0 MOV P2,#PULUH ;insert "puluh" address CLR P3.5 ;trigger SETB P3.5 CJNE R3,#1,$ ;wait interrupt & delay MOV R3,#0 MOV A,B CJNE A,#0,POINT_OK SJMP POINT_STATUS POINT_OK: ACALL DEC2ADD ;insert lsd address CLR P3.5 ;trigger SETB P3.5 CJNE R3,#1,$ ;wait interrupt & delay MOV R3,#0 POINT_STATUS: JNB F0,SPELL_DEG MOV P2,#KOMA ;insert "comma" address CLR P3.5 ;trigger SETB P3.5 CJNE R3,#1,$ ;wait interrupt & delay MOV R3,#0 MOV P2,#LIMA ;insert "lima" address CLR P3.5 ;trigger SETB P3.5 CJNE R3,#1,$ ;wait interrupt & delay MOV R3,#0 SPELL_DEG: MOV P2,#DERAJAT_CEL CLR P3.5 ;trigger SETB P3.5 CJNE R3,#1,$ ;wait interrupt & delay MOV R3,#0 SETB P3.7 ;PD is high RET ;**************************** ; voice announcer for crying ;**************************** VOICE_CRY: CLR P3.7 ;PD is low MOV P2,#BAYI ;insert "bayi" address CLR P3.5 ;trigger SETB P3.5 CJNE R3,#1,$ ;wait interrupt & delay MOV R3,#0 CJNE R4,#1,BED_21 ;check R4(R4 is for slave code) MOV P2,#BED1 ;insert "bed1" address SJMP TRIGGER_3 BED_21: CJNE R4,#2,BED_31 MOV P2,#BED2 ;insert "bed2" address SJMP TRIGGER_3 BED_31: CJNE R4,#3,BED_41 MOV P2,#BED3 ;insert "bed3" address SJMP TRIGGER_3 BED_41: MOV P2,#BED4 ;insert "bed4" address TRIGGER_3: CLR P3.5 ;trigger SETB P3.5 CJNE R3,#1,$ ;wait interrupt & delay MOV R3,#0 MOV P2,#NANGIS ;insert "nangis" address CLR P3.5 ;trigger SETB P3.5 CJNE R3,#1,$ ;wait interrupt & delay MOV R3,#0 SETB P3.7 ;PD is high RET ;******************************* ; voice announcer for urinating ;******************************* VOICE_URIN:CLR P3.7 ;PD is low MOV P2,#BAYI ;insert "bayi" address CLR P3.5 ;trigger SETB P3.5 CJNE R3,#1,$ ;wait interrupt & delay MOV R3,#0 CJNE R4,#1,BED_22 ;check R4(R4 is for slave code) MOV P2,#BED1 ;insert "bed1" address SJMP TRIGGER_4 BED_22: CJNE R4,#2,BED_32 MOV P2,#BED2 ;insert "bed2" address SJMP TRIGGER_4 BED_32: CJNE R4,#3,BED_42 MOV P2,#BED3 ;insert "bed3" address SJMP TRIGGER_4 BED_42: MOV P2,#BED4 ;insert "bed4" address TRIGGER_4: CLR P3.5 ;trigger SETB P3.5 CJNE R3,#1,$ ;wait interrupt & delay MOV R3,#0 MOV P2,#NGOMPOL ;insert "ngompol" address CLR P3.5 ;trigger SETB P3.5 CJNE R3,#1,$ ;wait interrupt & delay MOV R3,#0 SETB P3.7 ;PD is high RET ;******************************* ; decimal to address conversion ;******************************* DEC2ADD: CJNE A,#9,EIGHT8ADD MOV P2,#SEMBILAN SJMP QUIT_CONV EIGHT8ADD: CJNE A,#8,SEVEN7ADD MOV P2,#DELAPAN SJMP QUIT_CONV SEVEN7ADD: CJNE A,#7,SIX6ADD MOV P2,#TUJUH SJMP QUIT_CONV SIX6ADD: CJNE A,#6,FIVE5ADD MOV P2,#ENAM SJMP QUIT_CONV FIVE5ADD: CJNE A,#5,FOUR4ADD MOV P2,#LIMA SJMP QUIT_CONV FOUR4ADD: CJNE A,#4,THREE3ADD MOV P2,#EMPAT SJMP QUIT_CONV THREE3ADD: CJNE A,#3,TWO2ADD MOV P2,#TIGA SJMP QUIT_CONV TWO2ADD: CJNE A,#2,ONE1ADD MOV P2,#DUA SJMP QUIT_CONV ONE1ADD: MOV P2,#SATU QUIT_CONV: RET

NEXT