发送端ORG 0000H
JMP START
ORG 0100H
START:
ACALL INIT
MAIN:
MOV P2,#0F0H
MOV A,P2
XRL A,#0F0H
JZ MAIN
ACALL KEYSCAN
MOV A,30H
MOV DPTR,#TABLE2
MOVC A,@A+DPTR
MOV P1,A
SETB P0.5
CLR P0.4
CLR P0.3
ACALL DELAY2
SETB P0.3
ACALL DELAY
ALOOP1:
MOV 40H,A
MOV SBUF,#0E1H
JNB TI,$;·¢ËÍÖжÏ
CLR TI
JNB RI,$;½ÓÊÕÖжÏ
CLR RI
MOV A,SBUF;¶þºÅ»úÓ¦´ðÐźÅ
XRL A,#0E2H;Òì»òÅж¨ÊÇ·ñ×¼±¸Íê±Ï£¨ÅжϷ¢ËÍÏûÏ¢ÊÇ·ñΪ#0E2£©
JNZ ALOOP1;¿ªÊ¼·¢ËÍÊý¾Ýʱ¶¨Òå³õʼµØÖ·,Õâ¸öµØÖ·ÀïÃæ´æ´¢Òª·¢Ë͵ÄÊý¾Ý
MOV R0,#40H
MOV R6,#00H;УÑéºÍ
ALOOP2:
MOV SBUF,@R0
MOV A,R6
ADD A,@R0
MOV R6,A
JNB TI,$
CLR TI
MOV SBUF,R6
JNB TI,$;·¢ËÍÖжÏ
CLR TI
JNB RI,$;½ÓÊÕÓ¦´ðÖжÏ
CLR RI
MOV A,SBUF
XRL A,#00H
JNZ ALOOP2
JMP MAIN
INIT:
MOV A,#00000001B
MOV P1,A
ACALL ENABLE
MOV A,#00111000B
MOV P1,A
ACALL ENABLE
MOV A,#00001111B
MOV P1,A
ACALL ENABLE
MOV A,#00000110B
MOV P1,A
ACALL ENABLE
MOV A,#00H
MOV P1,A
ACALL ENABLE
CLR EA
MOV TMOD,#20H
MOV TH1,#0F4H
MOV TL1,#0F4H
MOV PCON,#00H
SETB TR1
MOV SCON,#50H
KEYSCAN:MOV P2,#0F0H;ÏȶÁÁÐÔÙ¶ÁÐÐ
MOV A,P2
ANL A,#0F0H
MOV R3,A
MOV P2,#0FH
MOV A,P2
ANL A,#0FH
ORL A,R3
CJNE A,#0FFH,KEYPRO;¼ì²â¼üÖµÊÇ·ñ³É¹¦¶ÁÈë
RET
KEYPRO: MOV R3,A
MOV DPTR,#KEYVALUE
MOV R4,#0FFH;´æ¼üÖµ±íµ½¼üÂë±íµÄÆ«ÒÆÁ¿
KEY1: INC R4 ;ɨÃè¼üÂë±íÀïÃæµÄÊýÖµ
MOV A,R4
MOVC A,@A+DPTR
CJNE A,03H,KEY1
MOV A,R4
MOV 30H,A
DELAY1: MOV R6,#60H;ÑÓʱ³ÌÐò
DE2: MOV R7,#90H
DJNZ R7,$
DJNZ R6,DE2
RET
ENABLE: CLR P0.5;дÃüÁî
CLR P0.4
CLR P0.3
ACALL DELAY2
SETB P0.3
RET
DELAY2: MOV P1,#0FFH
CLR P0.5
SETB P0.4
CLR P0.3
NOP
SETB P0.3
JB P1.7,DELAY2
RET
DELAY:
MOV R5,#10H;ÑÓʱ³ÌÐò
D1:
MOV R6,#30H
D2:
MOV R7,#90H
DJNZ R7,$
DJNZ R6,D2
DJNZ R5,D1
RET
KEYVALUE:DB 0E7H,0D7H,0B7H,077H,0EBH,0DBH,0BBH,07BH,0EDH,0DDH,0BDH,07DH,0EEH,0DEH,0BEH,07EH;¼üÂë¾ØÕó
TABLE2: DB 30H,31H,33H,38H,64H,69H,61H,6EH,6BH,65H,79H,74H,67H,3CH,5FH,3EH
END
接收端
ORG 0000H
JMP START
ORG 0100H
START:
ACALL INIT
JMP BLOOP1
BLOOP1:
JNB RI,$
CLR RI
MOV A,SBUF
XRL A,#0E1H
JNZ BLOOP1
MOV SBUF,#0E2H
JNB TI,$
CLR TI
MOV R0,#40H
MOV R6,#00H
BLOOP2:
JNB RI,$
CLR RI
MOV A,SBUF
MOV @R0,A
ADD A,R6
MOV R6,A
JNB RI,$
CLR RI
MOV A,SBUF
XRL A,R6
JZ END1
MOV SBUF,#0FFH
JNB TI,$
CLR TI
SJMP BLOOP1
END1:
MOV SBUF,#00H
JNB TI,$
CLR TI
MOV P2,@R0
SETB RS
CLR RW
CLR E
ACALL DELAY
SETB E
ACALL DELAY1
JMP BLOOP1
INIT:
RS EQU P1.4
RW EQU P1.3
E EQU P1.2
MOV P2,#00000001B
ACALL ENABLE
MOV P2,#00111000B
ACALL ENABLE
MOV P2,#00001111B
ACALL ENABLE
MOV P2,#00000110B
ACALL ENABLE
MOV P2,#00H
ACALL ENABLE
CLR EA
MOV TMOD,#20H
MOV TH1,#0F4H
MOV TL1,#0F4H
MOV PCON,#00H
SETB TR1
MOV SCON ,#50H
RET
ENABLE: CLR RS
CLR RW
CLR E
ACALL DELAY
SETB E
RET
DELAY: MOV P2,#0FFH
CLR RS
SETB RW
CLR E
NOP
SETB E
JB P2.7,DELAY
RET
DELAY1:
MOV R5,#10H;ÑÓʱ³ÌÐò
D1:
MOV R6,#30H
D2:
MOV R7,#90H
DJNZ R7,$
DJNZ R6,D2
DJNZ R5,D1
RET
END
乱码粘贴到keil中就好了
|