You are on page 1of 12

Code LCD :

$mod51 $debug org 0

main: mov a,#38h lcall command lcall delay mov a,#0eh lcall command lcall delay mov a,#'z' lcall datw lcall delay mov a,#'y' lcall datw lcall delay mov a,#'a' lcall datw lcall delay mov a,#'d' lcall datw lcall delay command:

mov p2,a clr p3.0 clr p3.1 setb p3.2 lcall delay clr p3.2 ret datw: mov p2,a setb p3.0 clr p3.1 setb p3.2 lcall delay clr p3.2 ret

delay: mov r1,#50 loop1: mov r0,#250 loop0: nop DJNZ r0,loop0 DJNZ r1,loop1 ret end

code keypad:
$mod51

$debug org 0

main: back:mov a,#38h lcall command lcall delay mov a,#0eh lcall command lcall delay

lcall scan

command: mov p2,a clr p3.0 clr p3.1 setb p3.2 lcall delay clr p3.2 ret

datw: mov p2,a setb p3.0

clr p3.1 setb p3.2 lcall delay clr p3.2 ret

delay: mov r1,#200 loop1: mov r0,#200 loop0: nop DJNZ r0,loop0 DJNZ r1,loop1 ret

scan: lcall col_1 lcall col_2 lcall col_3 lcall col_4 lcall scan

col_1: clr p1.4 mov a,p1 anl a,#0fh

mov r2,a cjne r2,#1110b,s1 mov a,#'1' lcall datw lcall delay

s1:cjne r2,#1101b,s2 mov a,#'5' lcall datw lcall delay

s2:cjne r2,#1011b,s3 mov a,#'9' lcall datw lcall delay

s3:cjne r2,#0111b,s4 mov a,#'D' lcall datw lcall delay

s4:setb p1.4 ret

col_2: clr p1.5 mov a,p1 anl a,#0fh mov r2,a cjne r2,#1110b,s5 mov a,#'2' lcall datw lcall delay

s5:cjne r2,#1101b,s6 mov a,#'6' lcall datw lcall delay

s6:cjne r2,#1011b,s7 mov a,#'A' lcall datw lcall delay

s7:cjne r2,#0111b,s8 mov a,#'E' lcall datw lcall delay

s8:setb p1.5 ret

col_3: clr p1.6 mov a,p1 anl a,#0fh mov r2,a cjne r2,#1110b,s9 mov a,#'3' lcall datw lcall delay

s9:cjne r2,#1101b,s10 mov a,#'7' lcall datw lcall delay

s10:cjne r2,#1011b,s11 mov a,#'B' lcall datw lcall delay

s11:cjne r2,#0111b,s12 mov a,#'F'

lcall datw lcall delay

s12:setb p1.6 ret

col_4: clr p1.7 mov a,p1 anl a,#0fh mov r2,a cjne r2,#1110b,s13 mov a,#'4' lcall datw lcall delay

s13:cjne r2,#1101b,s14 mov a,#'8' lcall datw lcall delay

s14:cjne r2,#1011b,s15 mov a,#'C' lcall datw lcall delay

s15:cjne r2,#0111b,s16 mov a,#' ' lcall datw lcall delay

cjne r2,#0111b,s17 s17:mov a,#01h lcall command lcall delay ljmp back

s16:setb p1.7 ret

end

code Interrupt:
$mod51 $debug org 0 ljmp main

org 000BH cpl p2.1 s:jnb tf0,s

clr tf0 reti

org 0001BH clr p2.2 mov r0,#7 loop: djnz r0,loop setb p2.2

s1:jnb tf1,s1 clr tf1 reti

org 0030H main: mov tmod,#11h mov tl0,#0a4h mov th0,#0ffh

mov tl1,#18h mov th1,#0fch

mov IE,#10001010b setb tr0

setb tr1

back:mov a,p3 mov p1,a sjmp back

end

Code serial:
//transfer: mov tmod,#20h mov th1,-3 mov scon,#50h setb tr1

back:mov a,p1 mov sbuf,a s:jnb ti,s clr ti

sjmp back end

//receive: mov tmod,#20h mov th1,-3 mov scon,#50h setb tr1

s:jnb ri,s mov a,sbuf mov p2,a

clr ri sjmp s end

You might also like