简单8051的键盘扩展。
单片机源程序如下:
- $NOMOD51
- $include (C8051F340.INC)
- ; Reset Vector
- ORG 0000H
- LJMP INICONF ; Locate a jump to the start of
- ; code at the reset vector.
- ; ORG 0003H
- ; LJMP IT0INT
- ; ORG 000BH
- ; LJMP T0INT
- ; ORG 0013H
- ; LJMP INT1INT
- ; ORG 0023H
- ; LJMP COMINT3
- ;-------------------------------------------
- ;KEEP THE FOLLOWING CODE SEGMENT UNCHANGED
- INICONF:
- ; Disable the WDT.
- ANL PCA0MD, #10111111B ; clear Watchdog Enable bit
- ;Use Internal H-F Oscillator(12M)/1 as System clock, =12MHz
- ORL OSCICN, #00000011B
- ; Enable the Port I/O Crossbar
- ORL XBR0, #00000001B ; UART0 TX0, RX0 routed to Port pins P0.4 and P0.5
- ORL XBR1, #01000000B ; enable Crossbar
- ; Port I/O Output Configuration
- ORL P0MDOUT, #11111111B
- ORL P1MDOUT, #11111111B
- ORL P2MDOUT, #11111111B
- ; External Memory Configuration
- ORL EMI0CF, #00001100B
- ;-------------------------------------------
- ; INSERT YOUR OWN PROGRAM HERE
- MOV 30H,#41H
- MOV 31H,#42H
- MOV 32H,#43H
- MOV 33H,#44H
- MOV A,#03H
- MOV DPTR,#7FF8H
- MOVX @DPTR,A
- START: MOV DPTR,#7FFBH
- MOVX A,@DPTR
- ANL A,#0FH
- CJNE A,#0FH,NEXT
- SJMP START
- NEXT: LCALL DELAYKEY
- MOVX A,@DPTR
- ANL A,#0FH
- CJNE A,#0FH,NEXT1
- SJMP START
- NEXT1: JNB ACC.0, BRT0
- JNB ACC.1, BRT1
- JNB ACC.2, BRT2
- JNB ACC.3, BRT3
- SJMP DONE
- BRT0: MOV R4,30H
- MOV 41H,#01H
- SJMP DONE
- BRT1: MOV R4,31H
- MOV 41H,#02H
- SJMP DONE
- BRT2: MOV R4,32H
- MOV 41H,#03H
- SJMP DONE
- BRT3: MOV R4,33H
- MOV 41H,#04H
- SJMP DONE
- DONE: ACALL CHANGE
- ACALL DISPLAY
- SJMP START
- ;
- CHANGE: MOV A,R4
- MOV R1,A
- MOV A,@R1
- SUBB A,37H
- MOV 40H,A
- RET
- DISPLAY: MOV R0,#40H
- MOV R3,#0FEH
- MOV A,R3
- DISPLAY1: MOV DPTR,#7FFAH
- MOVX @DPTR,A
- MOV A,@R0
- MOV DPTR,#TAB
- MOVC A,@A+DPTR
- MOV DPTR,#7FF9H
- MOVX @DPTR,A
- ACALL DELAY
- MOV A,R3
- JNB ACC.7,DISPLAY2
- RL A
- MOV R3,A
- SJMP DISPLAY1
- DISPLAY2: RET
- ;
- ORG 0150H
- DELAY: MOV A,41H
- MOV B,#27H
- MUL AB
- MOV R7,A
- DELAY1: MOV R6,#0FFH
- DELAY2: MOV R1,#0FFH
- DELAY3: DJNZ R1,DELAY3
- DJNZ R6,DELAY2
- DJNZ R7,DELAY1
- RET
- ;
- ORG 0200H
- DELAYKEY: MOV R5,#02H
- DELAYKEY1:MOV R2,#0FFH
- DELAYKEY2:DJNZ R2,DELAYKEY2
- DJNZ R5,DELAYKEY1
- RET
- ;
- TAB: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,77H,7CH,39H,5EH,79H,71H,00H,0FFH,40H
- ;-----------------------------------------------------------------------------
- ; End of file.
- END
复制代码
所有资料51hei提供下载:
查询式键盘扩展部分.zip
(1.21 KB, 下载次数: 4)
|