Sei sulla pagina 1di 7

;At start/reset/lock command

org 0h
ljmp main ;avoid interrupt area

;set the LED's
org 500h
main: clr p3.0 ;green LED disabled
setb p3.1 ;Red LED enabled

;set interrupts

mov IE,#10000101b ;interrupt enable register

;LCD program to display the starting commets

mov dptr,#mycom ;
c1: clr a ;
movc a,@a+dptr ;
acall comwrt ; call command subroutine
acall delaylcd ; give lcd some time
JZ send_dat ;
inc dptr ;
sjmp c1 ;

send_dat: mov dptr,#mydata ;
D1: clr a ;
movc a,@a+dptr ;
acall datawrt ; call command subroutine
acall delaylcd ; give lcd some time
inc dptr ;
JZ again ;
sjmp D1 ;
again: ljmp stay ;

comwrt: mov p1,a ; send command to p1
clr p3.4 ; RS=0 for command
clr p3.5 ; R/W=0 for write
setb p3.6 ; E=1 for H to L pulse
acall delaylcd ; give lcd some time
clr p3.6 ; E=0 for H to L
ret

datawrt: mov p1,a ;send data to p1
setb p3.4 ;RS=1 for data
clr p3.5 ;R/W=0 for command
setb p3.6 ;E=1 for high pulse
acall delaylcd ;give lcd some time
clr p3.6 ;E=0 for H to L pulse
ret

delaylcd: mov r4,#250 ;
here2 : mov r5,#255 ;
here: djnz r5,here ;
djnz r4,here2 ;
ret

;stay here till interrupts initiated

stay: sjmp stay ;

;Data(S) to be displayed at LCD

org 800h

mycom: DB 38h,0eh,01,06,80h,0 ;commands and null ;
mydata: DB "KG SAFE LOCKED",0 ;data and null

mycom2: DB 38h,0eh,01,06,80h,0 ;commands and null
mydata2: DB "ENTER PASSWORD",0 ;data and null

mycom3: DB 38h,0eh,01,06,80h,0 ;commands and null
mydata3: DB "*",0 ;data and null

mycom4: DB 38h,0eh,01,06,80h,0 ;commands and null
mydata4: DB "INVALID",0 ;data and null

mycom5: DB 38h,0eh,01,06,80h,0 ;commands and null
mydata5: DB "ACCESS GRANTED",0 ;data and null

;ASCII look up table for each row

code0: DB '0', '1' , '2' ; row 0
code1: DB '3' , '4' , '5' ; row 1
code2: DB '6' , '7' , '8' ; row 2
code3: DB '9' , 'A' , 'B' ; row 3




;ISR for unlock key command (ext. 0 interrupt)

;to display 'enter password on lcd'

org 003h

mov dptr,#mycom2 ;
c12: clr a ;
movc a,@a+dptr ;
acall comwrt2 ; call command subroutine
acall delaylcd2 ; give lcd some time
JZ send_dat2 ;
inc dptr ;
sjmp c12 ;

send_dat2: mov dptr,#mydata2 ;
D12: clr a ;
movc a,@a+dptr ;
acall datawrt2 ; call command subroutine
acall delaylcd2 ; give lcd some time
inc dptr ;
JZ again2 ;
sjmp D12 ;
again2: sjmp keypad ;

comwrt2: mov p1,a ; send command to p1
clr p3.4 ; RS=0 for command
clr p3.5 ; R/W=0 for write
setb p3.6 ; E=1 for H to L pulse
acall delaylcd2 ; give lcd some time
clr p3.6 ; E=0 for H to L
ret

datawrt2: mov p1,a ;send data to p1
setb p3.4 ;RS=1 for data
clr p3.5 ;R/W=0 for command
setb p3.6 ;E=1 for high pulse
acall delaylcd2 ;give lcd some time
clr p3.6 ;E=0 for H to L pulse
ret

delaylcd2: mov r4,#250 ;
here22 : mov r5,#255 ;
here02: djnz r4,here02 ;
djnz r5,here22 ;
ret


;keypad enabling (acall)
;p0.0-p0.3 connected to rows(4)
;p2.0-p2.2 connected to columns(3)


keypad: mov p2,#0FFH ; make p2 input port
k1: mov p0,#0 ; make p0 output port
mov a,p2 ; read all columns,ensure allkeysopen
ANL a,#00000111b ; mask unused bits
CJNE a,#00000111b,k1 ; check till all keys released

k2: acall delay ; call 20 ms delay
mov a,p2 ; see if any key pressed
ANL a,#00000111b ; mask unused bits
CJNE a,#00000111b,k1 ; check till all keys released
sjmp k2 ;

over1: mov p0,#11111110b ; ground row 0
mov a,p2 ;
ANL a,#00000111b ; mask unused bits
CJNE a,#00000111b,rowa ; key row 0,find column
mov p0,#11111101b ; ground row 1

mov a,p2 ;
ANL a,#00000111b ; mask unused bits
CJNE a,#00000111b,rows ; key row 1,find column

mov p0,#11111011b ; ground row 2
mov a,p2 ;
ANL a,#00000111b ; mask unused bits
CJNE a,#00000111b,rowd ; key row 2,find column

mov p0,#11110111b ; ground row 3
mov a,p2 ;
ANL a,#00000111b ; mask unused bits
CJNE a,#00000111b,rowf ; key row 3,find column

LJMP k2 ; none,false input

rowa:mov dptr,#code0 ; set DPTR=start of row 0
SJMP find ; find column
rows:mov dptr,#code1 ; set DPTR=start of row 1
SJMP find ; find column
rowd:mov dptr,#code2 ; set DPTR=start of row 2
SJMP find ; find column
rowf:mov dptr,#code3 ; set DPTR=start of row 3

find:RRC a ; see if any cy bit is low
JNC match ; if zero get ASCII code
INC dptr ; point to next column address
sjmp find ; keep searching

match: clr a ;
mov r1,20h ;
movc a,@a+dptr ;get ASCII code
mov @r1,a ;send to a location
acall LCD ;to display * on screen
inc r1 ;
djnz r6,k1 ;go to start, to identify more key hits
RETI

delay: mov r4,#100 ;
hw: djnz r4,hw ;
ret


; LCD subroutine for keypad program

LCD: mov dptr,#mycom3 ;
c13: clr a ;
movc a,@a+dptr ;
acall comwrt3 ; call command subroutine
acall delaylcd3 ; give lcd some time
JZ send_dat3 ;
inc dptr ;
sjmp c13 ;

send_dat3: mov dptr,#mydata3 ;
D13: clr a ;
movc a,@a+dptr ;
acall datawrt3 ; call command subroutine
acall delaylcd3 ; give lcd some time
inc dptr ;
JZ again3 ;
sjmp D13 ;
again3: RET ;

comwrt3: mov p1,a ; send command to p1
clr p3.4 ; RS=0 for command
clr p3.5 ; R/W=0 for write
setb p3.6 ; E=1 for H to L pulse
acall delaylcd3 ; give lcd some time
clr p3.6 ; E=0 for H to L
ret

datawrt3: mov p1,a ;send data to p1
setb p3.4 ;RS=1 for data
clr p3.5 ;R/W=0 for command
setb p3.6 ;E=1 for high pulse
acall delaylcd3 ;give lcd some time
clr p3.6 ;E=0 for H to L pulse
ret

delaylcd3: mov r4,#250 ;
here23 : mov r5,#255 ;
here3: djnz r4,here3 ;
djnz r5,here23 ;
ret




;ISR for enter key command

org 0013h

;check if entered password is correct or not

mov r1,20h ;
banga: CJNE @r1,#'2',invalid ;
inc r1 ;
CJNE @r1,#'4',invalid ;
inc r1 ;
CJNE @r1,#'0',invalid ;
inc r1 ;
CJNE @r1,#'8',invalid ;
ljmp correct ;


;if correct,then diplay 'ACCESS GRANTED' and switch on green
;LED and switch off red LED

correct: clr p3.1 ;switch off red LED
setb p3.0 ;switch on green LED
mov IE,#0h ;disable interrupt

mov dptr,#mycom4 ;
c14: clr a ;
movc a,@a+dptr ;
acall comwrt4 ; call command subroutine
acall delaylcd4 ; give lcd some time
JZ send_dat4 ;
inc dptr ;
sjmp c14 ;

send_dat4: mov dptr,#mydata4 ;
D14: clr a ;
movc a,@a+dptr ;
acall datawrt4 ; call command subroutine
acall delaylcd4 ; give lcd some time
inc dptr ;
JZ again4 ;
sjmp D14 ;
again4: RETI ;

comwrt4: mov p1,a ; send command to p1
clr p3.4 ; RS=0 for command
clr p3.5 ; R/W=0 for write
setb p3.6 ; E=1 for H to L pulse
acall delaylcd4 ; give lcd some time
clr p3.6 ; E=0 for H to L
ret

datawrt4: mov p1,a ;send data to p1
setb p3.4 ;RS=1 for data
clr p3.5 ;R/W=0 for command
setb p3.6 ;E=1 for high pulse
acall delaylcd4 ;give lcd some time
clr p3.6 ;E=0 for H to L pulse
ret

delaylcd4: mov r4,#250 ;
here24 : mov r5,#255 ;
here4: djnz r4,here4 ;
djnz r5,here24 ;
ret




;if incorrect, then display 'INCORRECT'

invalid: mov dptr,#mycom5 ;
c15: clr a ;
movc a,@a+dptr ;
acall comwrt5 ; call command subroutine
acall delaylcd5 ; give lcd some time
JZ send_dat5 ;
inc dptr ;
sjmp c15 ;

send_dat5: mov dptr,#mydata5 ;
D15: clr a ;
movc a,@a+dptr ;
acall datawrt5 ; call command subroutine
acall delaylcd5 ; give lcd some time
inc dptr ;
JZ again5 ;
sjmp D15 ;
again5: RETI ;

comwrt5: mov p1,a ; send command to p1
clr p3.4 ; RS=0 for command
clr p3.5 ; R/W=0 for write
setb p3.6 ; E=1 for H to L pulse
acall delaylcd5 ; give lcd some time
clr p3.6 ; E=0 for H to L
ret

datawrt5: mov p1,a ;send data to p1
setb p3.4 ;RS=1 for data
clr p3.5 ;R/W=0 for command
setb p3.6 ;E=1 for high pulse
acall delaylcd5 ;give lcd some time
clr p3.6 ;E=0 for H to L pulse
ret

delaylcd5: mov r4,#250 ;
here25 : mov r5,#255 ;
here5: djnz r4,here5 ;
djnz r5,here25 ;

RET



end

Potrebbero piacerti anche