Transmitter Code
Transmitter Code
; ----------------------------------------------------------------------------------------------------------; wireless security system by Adnan Aziz MSc Electrical and Electronics systems
;under the supervision of DR Yanting HU
;-------------------------------------------------------------------------------------------------------------BUZ EQU P1.2
KEY EQU P3.7
WATER EQU P3.2
GAS
EQU P3.3
EQU 00H
org 00
AJMP START
ORG 100H
START:
CLR BUZ
MOV R1,#5
acall init_sio
START1:
ACALL DELAYHS
SETB EMERLD
JNB WATER,SEND1
AA:
JNB GAS,SEND2
BB:
JNB FIRE,SEND4
JB INTF,SEND8
CC:
JNB INTUR,SEND8
JB KEY,LL
CLR BUZ
SETB WATERLD
SETB GASLD
SETB FIRELD
SETB INTURLD
CLR INTF
LL:
SJMP START1
SJMP CC
SEND8: CLR INTURLD
SETB BUZ
SETB INTF
JB KEY,LM
CLR BUZ
SETB WATERLD
SETB GASLD
SETB FIRELD
SETB INTURLD
CLR INTF
SJMP START1
MM:
SJMP START1
SEND1A:
SETB BUZ
Acall putc
MOV A,#'F'
acall putc
MOV A,#'L'
ACALL PUTC
MOV A,#'O'
acall putc
MOV A,#'O'
ACALL PUTC
MOV A,#'D'
acall putc
MOV A,#'I'
ACALL PUTC
MOV A,#'N'
acall putc
MOV A,#'G'
ACALL PUTC
MOV A,#'*'
acall putc
MOV A,#'*'
ACALL PUTC
CLR EMERLD
RET ;
SEND2A:
SETB BUZ
acall putc
MOV A,#'G'
acall putc
MOV A,#'A'
ACALL PUTC
MOV A,#'S'
acall putc
MOV A,#'-'
ACALL PUTC
MOV A,#'L'
acall putc
MOV A,#'E'
ACALL PUTC
MOV A,#'A'
acall putc
MOV A,#'K'
ACALL PUTC
MOV A,#'*'
acall putc
MOV A,#'*'
ACALL PUTC
CLR EMERLD
RET ;
SEND4A:
SETB BUZ
acall putc
MOV A,#'F'
ACALL PUTC
MOV A,#'I'
acall putc
MOV A,#'R '
ACALL PUTC
MOV A,#'E'
acall putc
MOV A,#'-'
ACALL PUTC
MOV A,#'F'
acall putc
MOV A,#'I'
ACALL PUTC
MOV A,#'R'
acall putc
MOV A,#'E'
ACALL PUTC
CLR EMERLD
RET ;
SEND8A: JNB INTF,DK
SETB BUZ
acall putc
MOV A,#'I'
acall putc
MOV A,#'N'
ACALL PUTC
MOV A,#'T'
acall putc
MOV A,#'U '
ACALL PUTC
MOV A,#'R'
acall putc
MOV A,#'D'
ACALL PUTC
MOV A,#'E'
acall putc
MOV A,#'R'
ACALL PUTC
MOV A,#'*'
acall putc
MOV A,#'*'
ACALL PUTC
CLR EMERLD
DK:
RET ;
;==================================================================
; subroutine getc
; Waits for and returns the character recevied by the
; serial port in the accumulator
;
; input : nothing
; output : char in acc
; destroys: nothing
; -------------------------------------------------------------------------------;==================================================================
; subroutine initSIO
clr ri
mov a, sbuf
ret
; subroutine putc
; Transmits the char given in the accumulator and wait
; for transmission completion.
; input : char in acc
; output : nothing
; destroys: nothing
; -------------------------------------------------------------------------------putc:
mov sbuf, a
jnb ti, $
clr ti
ret
;==================================================================
; subroutine puts
; Transmits a string out the serial port.
; The null-terminated string is expected to be in code memory, whose address
; is in DPTR.
; input : string base in DPTR
; output : serial port
; destroys: accumulator
; -------------------------------------------------------------------------------puts:
clr a
movc a, @a+dptr
jz putsDone
acall putc
inc dptr
; SJMP puts
;
sjmp START1
putsDone:
AJMP START
;
==========================================================
; subroutine crlf
; crlf sends a carriage return line feed out the serial port
;
; input : nothing
LF EQU 0AH
CR EQU 0DH
crlf:
mov a, #CR
; print cr
lcall putc
mov a, #LF
; print lf
lcall putc
ret
;**************************************************************************
DELAYMS:
MOV R7,#00H
LOOPA:
INC R7
MOV A,R7
CJNE A,#0FFH,LOOPA
RET
;**************************************************************************
DELAYHS:
MOV R6,#00H
LOOPB:
INC R6
ACALL DELAYMS
MOV A,R6
JNZ LOOPB
RET
end
;==========================================================
RECEIVER CODE
; ----------------------------------------------------------------------------------------------------------; wireless security system by Adnan Aziz MSc Electrical and Electronics systems
;under the supervision of DR Yanting HU
;-------------------------------------------------------------------------------------------------------------RS
EQU P1.7
EN
EQU P1.6
ORG 00
AJMP START
ORG 100H
ORG 00BH
ret
org 023h
AJMP RECDATA
RETI
CLR BUZ
ACALL LCD_INIT
ACALL SER_INIT
mov dptr,#msg1
acall puts
acall crlf
mov R0,#LCD_BUF1
mov dptr,#msg1
ACALL COPYCR
MOV
B,#80H
LCALL LCD_CMD
ACALL LINE1
ACALL delay_sec
mov dptr,#msg2
acall puts
acall crlf
mov R0,#LCD_BUF1
MOV DPTR,#msg2
ACALL COPYCR
MOV
B,#0C0H
LCALL LCD_CMD
ACALL LINE1
ACALL delay_sec
ACALL delay_sec
MOV
B,#01H
LCALL LCD_CMD
mov dptr,#msg3
acall puts
acall crlf
mov R0,#LCD_BUF1
MOV DPTR,#msg3
ACALL COPYCR
MOV
B,#80H
LCALL LCD_CMD
ACALL LINE1
ACALL delay_sec
mov dptr,#msg4
acall puts
acall crlf
mov R0,#LCD_BUF1
MOV DPTR,#msg4
ACALL COPYCR
MOV
B,#0C0H
LCALL LCD_CMD
ACALL LINE1
ACALL delay_sec
ACALL delay_sec
MOV
B,#01H
LCALL LCD_CMD
mov dptr,#msg5
acall puts
acall crlf
mov R0,#LCD_BUF1
MOV DPTR,#msg5
ACALL COPYCR
MOV
B,#80H
LCALL LCD_CMD
ACALL LINE1
ACALL delay_sec
mov dptr,#msg6
acall puts
acall crlf
mov R0,#LCD_BUF1
MOV DPTR,#msg6
ACALL COPYCR
MOV
B,#0C0H
LCALL LCD_CMD
ACALL LINE1
ACALL delay_sec
ACALL delay_sec
MOV
B,#01H
LCALL LCD_CMD
mov dptr,#msg7
acall puts
acall crlf
mov R0,#LCD_BUF1
MOV DPTR,#msg7
ACALL COPYCR
MOV
B,#80H
LCALL LCD_CMD
ACALL LINE1
ACALL delay_sec
mov dptr,#msg8
acall puts
acall crlf
mov R0,#LCD_BUF1
MOV DPTR,#msg8
ACALL COPYCR
MOV
B,#0C0H
LCALL LCD_CMD
ACALL LINE1
ACALL delay_sec
ACALL delay_sec
MOV
B,#01H
LCALL LCD_CMD
mov dptr,#msg9
acall puts
acall crlf
mov R0,#LCD_BUF1
MOV DPTR,#msg9
ACALL COPYCR
MOV
B,#80H
LCALL LCD_CMD
ACALL LINE1
ACALL delay_sec
mov dptr,#msg10
acall puts
acall crlf
mov R0,#LCD_BUF1
MOV DPTR,#msg10
ACALL COPYCR
MOV
B,#0C0H
LCALL LCD_CMD
ACALL LINE1
ACALL delay_sec
ACALL delay_sec
MOV
B,#01H
LCALL LCD_CMD
mov dptr,#msg11
acall puts
acall crlf
mov R0,#LCD_BUF1
MOV DPTR,#msg11
ACALL COPYCR
MOV
B,#80H
LCALL LCD_CMD
ACALL LINE1
ACALL delay_sec
LL:
MOV @R0,A
INC R0
DJNZ R1,LL
MOV A,#5
ACALL delay_sec ; REM
DL:
CJNE A,#'*',DM
CLR LED4
SETB BUZ
ACALL LCDDT
SJMP DN
DN:
JNB BUZSTOPKEY,SK
MOV
a,#50
LCALL delay_ms
;JNB P1.0,$
;
SETB LED
JB BACKLIT,ZZ
SJMP KK
LCDDT: ;MOV
B,#01H
;CLEAR DISP
;LCALL LCD_CMD
MOV R0,#LCD_BUF
MOV
B,#0C0H
LCALL LCD_CMD
;LINE1
L06:
MOV
L30:
MOV
MOV
r3,#10
A,@R0
B,A
;COMMANDBYTE FOR
LCALL LCD_DATA
INC
DJNZ
R0
r3,L30
RET
B,#01H
;CLEAR DISP
; LCALL LCD_CMD
CLR BUZ
SETB LED2
SETB LED3
SETB LED4
SETB LED5
MOV R0,#LCD_BUF
mov R1,#32
MOV A,#0FFH
UU:
MOV @R0,A
DJNZ R1,UU
SJMP KK
LCD_INIT:
MOV
acc,#249
LCALL delay_ms
MOV
B,#28H
;POWER ON DELAY
;FUNCTION SET
LCALL LCD_CMD
MOV
B,#28H
;FUNCTION SET
LCALL LCD_CMD
MOV
B,#28H
LCALL LCD_CMD
MOV
B,#0EH
;FUNCTION SET
;DISP CONTROL
LCALL LCD_CMD
MOV
B,#02H
;RETURN HOME
LCALL LCD_CMD
MOV
B,#01H
;CLEAR DISP
LCALL LCD_CMD
ret
LCD_CMD:
MOV
ANL
A,B
A,#0F0H
MOV
C,ACC.7
MOV
P1.2,C
MOV
C,ACC.6
MOV
P1.3,C
MOV
C,ACC.5
MOV
P1.4,C
;FUNCTION SET
MOV
C,ACC.4
MOV
P1.5,C
CLR
RS
;SELECT COMMAND
SETB
EN
;EN HIGH
EN
;EN LOW
NOP
CLR
NOP
MOV
A,B
SWAP A
ANL
A,#0F0H
MOV
C,ACC.7
MOV
P1.2,C
MOV
C,ACC.6
MOV
P1.3,C
MOV
C,ACC.5
MOV
P1.4,C
MOV
C,ACC.4
MOV
P1.5,C
CLR
RS
SETB
EN
;EN HIGH
EN
;EN LOW
NOP
CLR
MOV
a,#1
LCALL delay_ms
RET
LCD_DATA:
MOV
ANL
A,B
A,#0F0H
MOV
C,ACC.7
MOV
P1.2,C
MOV
C,ACC.6
MOV
P1.3,C
MOV
C,ACC.5
MOV
P1.4,C
MOV
C,ACC.4
MOV
P1.5,C
SETB
RS
SETB
EN
;EN HIGH
EN
;EN LOW
NOP
CLR
NOP
MOV
A,B
SWAP A
ANL
A,#0F0H
MOV
C,ACC.7
MOV
P1.2,C
MOV
C,ACC.6
MOV
P1.3,C
MOV
C,ACC.5
MOV
P1.4,C
MOV
C,ACC.4
MOV
P1.5,C
SETB
RS
SETB
EN
;EN HIGH
EN
;EN LOW
NOP
CLR
MOV
a,#1
LCALL delay_ms
RET
; copier copies data from code area to ram area source address is pointed
;by dptr and destination is pointed by r0. b is counter for nos. of bytes to
; be copied register a,b and r0 is used
; push acc
;push b
COPYCR:
MOV
r3,#16
MOV R0,#LCD_BUF1
C10:
CLR
MOVC A,@A+DPTR
MOV
@R0,A
INC
DPTR
INC
R0
DJNZ
r3,C10
;pop b
;pop acc
RET
;**********************************************************************
;this subroutine sends the data on the first line on to lcd
LINE1:
;LINE1
L05:
SETB RS0
MOV
a,#1
LCALL delay_ms
L10:
MOV
r3,#16
MOV
R0,#LCD_BUF1
MOV
MOV
A,@R0
B,A
LCALL LCD_DATA
INC
DJNZ
R0
r3,L10
RET
SER_INIT:
ANL
TMOD, #0X0F
mov
mov
mov
mov
scon, #0x50 ; set serial control reg for 8 bit data and mode 1
ret
;=================================================================
RECDATA: CLR EA
PUSH ACC
PUSH B
CLR RI
CLR LED1
SETB RS0
mov r0,#LCD_BUF
MOV R1,#10
; IT WAS 7
GETT:
mov a, sbuf
CLR RI
MORE:
JNB RI,$
MOV A,SBUF
MOV @R0,A
INC R0
CLR RI
DJNZ R1,MORE
MOV R0,#LCD_BUF
;
CLR LED
;
LINE2:
CLR RS0
POP B
POP ACC
SETB EA
SETB LED1
RETI
; ================================================================
; subroutine putc
; Transmits the char given in the accumulator and wait
; for transmission completion.
;
; input : char in acc
; output : nothing
; destroys: nothing
; -------------------------------------------------------------------------------putc:
mov sbuf, a
jnb ti, $
clr ti
ret
; ================================================================
; ================================================================
; subroutine puts
; Transmits a string out the serial port.
; The null-terminated string is expected to be in code memory, whose address
; is in DPTR.
; input : string base in DPTR
; output : serial port
; destroys: accumulator
; -------------------------------------------------------------------------------puts:
clr a
movc a, @a+dptr
jz putsDone
acall putc
inc dptr
sjmp puts
putsDone:
ret
;
==========================================================
; subroutine crlf
; crlf sends a carriage return line feed out the serial port
;
; input : nothing
; output : characters out the serial port
; calls : sndchr
; destroys: a
; ==========================================================
LF EQU 0AH
CR EQU 0DH
crlf:
mov a, #CR
; print cr
lcall putc
mov a, #LF
; print lf
lcall putc
ret
update:
PUSH ACC
PUSH B
SETB RS0
MOV
B,A
LCALL LCDDATA
INC
R0
DJNZ R7,EXIT
MOV R7,#32
MOV R0,#LCD_BUF
MOV B,#80H
LCDCMD:
MOV
ANL
A,B
;FUNCTION SET
A,#0F0H
MOV
C,ACC.7
MOV
P1.2,C
MOV
C,ACC.6
MOV
P1.3,C
MOV
C,ACC.5
MOV
P1.4,C
MOV
C,ACC.4
MOV
P1.5,C
CLR
RS
;SELECT COMMAND
SETB
EN
;EN HIGH
EN
;EN LOW
NOP
CLR
NOP
MOV
A,B
SWAP A
ANL
MOV
A,#0F0H
P0,A
CLR
RS
SETB
EN
;EN HIGH
EN
;EN LOW
NOP
CLR
SJMP EXIT
LCDDATA:
MOV
ANL
A,B
A,#0F0H
MOV
C,ACC.7
MOV
P1.2,C
MOV
C,ACC.6
MOV
P1.3,C
MOV
C,ACC.5
MOV
P1.4,C
MOV
C,ACC.4
MOV
P1.5,C
SETB
RS
SETB
EN
;EN HIGH
EN
;EN LOW
NOP
CLR
NOP
MOV
A,B
SWAP A
ANL
A,#0F0H
MOV
C,ACC.7
MOV
P1.2,C
MOV
C,ACC.6
MOV
P1.3,C
MOV
C,ACC.5
MOV
P1.4,C
MOV
C,ACC.4
MOV
P1.5,C
SETB
RS
SETB
EN
;EN HIGH
EN
;EN LOW
NOP
CLR
RET
EXIT: POP B
POP ACC
CLR RS0
RETI
;delay for one ms times the value in accumulator
mov b,#0
dd:
djnz b,$
; 500us @12mhz
djnz b,$
; 500us @12mhz
djnz acc,dd
pop b
pop acc
ret
mov b,a
ddd:
mov a,#250
acall delay_ms
; 250ms
acall delay_ms
;500ms
acall delay_ms
;750ms
acall delay_ms
;1000ms
djnz b,ddd
pop b
pop acc
ret
msg1:
MSG2:
MSG3:
DB " Wireless
MSG4:
msg5:
MSG6:
",0
MSG7:
MSG8:
DB "
MSG9:
MSG10:
MSG11:
DB "Wireless-Monitor",0
blank:
DB "
DB "
END
",0
",0