0% found this document useful (0 votes)
31 views

Transmitter Code

This document contains code for a wireless security system transmitter and receiver. The transmitter code initializes serial communication and sends alert codes for different sensors like flood, gas, fire, and intruder via serial transmission. The receiver code initializes an LCD display and serial communication. It receives alert codes from the transmitter, displays them on the LCD, and illuminates corresponding LEDs to indicate the triggered sensor.

Uploaded by

Adnan Aziz
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Transmitter Code

This document contains code for a wireless security system transmitter and receiver. The transmitter code initializes serial communication and sends alert codes for different sensors like flood, gas, fire, and intruder via serial transmission. The receiver code initializes an LCD display and serial communication. It receives alert codes from the transmitter, displays them on the LCD, and illuminates corresponding LEDs to indicate the triggered sensor.

Uploaded by

Adnan Aziz
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 35

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

FIRE EQU P3.4


INTUR EQU P3.5
WATERLD EQU P1.6
GASLD EQU P1.5
FIRELD EQU P1.4
INTURLD EQU P1.3
EMERLD EQU P1.7
INTF

EQU 00H

org 00
AJMP START

ORG 100H
START:
CLR BUZ
MOV R1,#5
acall init_sio

; initialize serial port (2400 Baud)

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

SEND1: CLR WATERLD


SETB BUZ
ACALL SEND1A
SJMP AA

SEND2: CLR GASLD


SETB BUZ
ACALL SEND2A
SJMP BB
SEND4: CLR FIRELD
SETB BUZ
ACALL SEND4A

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

LM: ACALL SEND8A

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

;Start of BAUD RATE WIZARD code


;MOV TMOD,#20h ;Timer 1 in Auto-reload mode

;MOV TH1,#0E8h ;Reload value for 1200 baud @ 11.059 Mhz


;SETB TR1 ;Turn on timer 1
;End of BAUD RATE WIZARD code
; -------------------------------------------------------------------------------init_sio:
anl tmod, #0x0F ; set counter 1 for auto reload - mode 2
orl tmod, #0x20 ; set counter 1 for auto reload - mode 2
mov tcon, #0x41 ; run coutnter 1 and set edge trig ints
mov th1, #0xA0 ; set 300 baud with xtal=11.0592mhz
mov scon, #0x50 ; set serial control reg for 8 bit data and mode 1
ret
;==================================================================
getc:
jnb ri, $

; wait for char

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, $

; wait for transmission

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

; 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
;**************************************************************************
DELAYMS:

;millisecond delay routine

MOV R7,#00H

;put value of 0 in register R7

LOOPA:
INC R7
MOV A,R7

;increase R7 by one (R7 = R7 +1)


;move value in R7 to Accumlator (also known as A)

CJNE A,#0FFH,LOOPA
RET

;compare A to FF hex (256). If not equal go to LOOPA

;return to the point that this routine was called from

;**************************************************************************
DELAYHS:
MOV R6,#00H
LOOPB:

;half second delay above millisecond delay


;put 0 in register R6 (R6 = 0)

INC R6
ACALL DELAYMS
MOV A,R6
JNZ LOOPB

;increase R6 by one (R6 = R6 +1)


;call the routine above. It will run and return to here.
;move value in R6 to A
;if A is not 0, go to 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

; FINAL AND TESTED FOR WIRELES MONITOR on 15/08/11

LCD_BUF EQU 30H


LCD_BUF1 EQU 40H
BUZ EQU P3.3 ;
LED1 EQU P3.4 ; BUZZER AD LED AT THE RECEIVER
LED2 EQU P3.5
LED3 EQU P3.7
LED4 EQU P1.0
LED5 EQU P1.1
BUZSTOPKEY EQU P3.2

ORG 00
AJMP START
ORG 100H
ORG 00BH
ret
org 023h
AJMP RECDATA
RETI

START: MOV SP,#20H

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

;COMMAND BYTE FOR

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

;COMMAND BYTE FOR

ACALL delay_sec

MOV

B,#01H

;COMMAND BYTE FOR

LCALL LCD_CMD

mov dptr,#msg3
acall puts
acall crlf

mov R0,#LCD_BUF1
MOV DPTR,#msg3
ACALL COPYCR
MOV

B,#80H

;COMMAND BYTE FOR

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

;COMMAND BYTE FOR

ACALL delay_sec
ACALL delay_sec

MOV

B,#01H

;COMMAND BYTE FOR

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

;COMMAND BYTE FOR

MOV

B,#0C0H

;COMMAND BYTE FOR

LCALL LCD_CMD
ACALL LINE1
ACALL delay_sec
ACALL delay_sec

MOV

B,#01H

;COMMAND BYTE FOR

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

;COMMAND BYTE FOR

mov R0,#LCD_BUF1
MOV DPTR,#msg8
ACALL COPYCR
MOV

B,#0C0H

;COMMAND BYTE FOR

LCALL LCD_CMD
ACALL LINE1
ACALL delay_sec
ACALL delay_sec

MOV

B,#01H

;COMMAND BYTE FOR

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

;COMMAND BYTE FOR

mov R0,#LCD_BUF1
MOV DPTR,#msg10
ACALL COPYCR
MOV

B,#0C0H

;COMMAN DBYTE FOR

LCALL LCD_CMD
ACALL LINE1
ACALL delay_sec
ACALL delay_sec

MOV

B,#01H

;COMMAND BYTE FOR

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

;COMMAND BYTE FOR

LL:

MOV @R0,A
INC R0
DJNZ R1,LL

MOV A,#5
ACALL delay_sec ; REM

KK: MOV A,LCD_BUF


CJNE A,#'F',DK
CLR LED2
SETB BUZ
ACALL LCDDT
SJMP DN

DK: CJNE A,#'G',DL


CLR LED3
SETB BUZ
ACALL LCDDT
SJMP DN

DL:

CJNE A,#'*',DM
CLR LED4
SETB BUZ

ACALL LCDDT
SJMP DN

DM: CJNE A,#'I',DN


CLR LED5
SETB BUZ
ACALL LCDDT

DN:

JNB BUZSTOPKEY,SK
MOV

a,#50

LCALL delay_ms
;JNB P1.0,$
;

SETB LED

; indication led off

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

SK: ; mov dptr,#blank


;acall DISPLAY
; MOV

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

;GET MESSAGE BYTE


;SEND TO LCD BUFF
;INR POINTER

r3,C10

;pop b
;pop acc
RET

;TAKE NEXT ONE

;**********************************************************************
;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

tmod, #0x20 ; set counter 1 for auto reload - mode 2

mov

tcon, #0x40 ; run coutnter 1 and set edge trig ints

mov

th1, #0x0A0 ; set counter 1 for 300 baud with xtal=11.0592mhz

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:

;SWITCH ON LED AND BACKLIT

AGAIN: MOV A,@R0


MOV SBUF,A
ACALL PUTC
INC R0
DJNZ R3,AGAIN
ACALL CRLF

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

; wait for transmission

; ================================================================
; ================================================================
; 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

delay_ms: push acc


push b

mov b,#0
dd:
djnz b,$

; 500us @12mhz

djnz b,$

; 500us @12mhz

djnz acc,dd

pop b
pop acc
ret

; Delay for one second times the value in accumulator

delay_sec: push acc


push b

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:

DB " Welcome to ",0

MSG2:

DB " Intelligent ",0

MSG3:

DB " Wireless

MSG4:

DB "Security System ",0

msg5:

DB " Designed By ",0

MSG6:

DB " ADNAN AZIZ ",0

",0

MSG7:

DB "(MSC Ele & Elec)",0

MSG8:

DB "

MSG9:

DB " Supervision of ",0

MSG10:

DB " DR.Yanting HU. ",0

MSG11:

DB "Wireless-Monitor",0

blank:

DB "
DB "

END

Under the ",0

",0
",0

You might also like