Beep BIT P2.3
LED1 EQU 08H
LED2 EQU 09H
LED3 EQU 0AH
LED4 EQU 0BH
LedT0 EQU 0CH ;0-3 轮流点亮4个数据管
ORG 0000H
LJMP START ;转入主程序
ORG 000BH
;=================================================
;定时器0中断入口
INT_TO:
PUSH ACC
PUSH PSW
CLR TF0 ;清定时0中断标志
MOV TH0,#0F6H ;2.5MS
MOV TL0,#03DH ;
MOV A,#11110000B ;关数码管
ORL P2,A
MOV A,LedT0
CJNE A,#0,INT_T0_1
MOV A,LED1
MOVC A,@A+DPTR
MOV P0,A
CLR P2.7
MOV LedT0,#1
LJMP INT_T0_END
INT_T0_1:
MOV A,LedT0
CJNE A,#1,INT_T0_2
MOV A,LED2
MOVC A,@A+DPTR
MOV P0,A
CLR P2.6
MOV LedT0,#2
LJMP INT_T0_END
INT_T0_2:
MOV A,LedT0
CJNE A,#2,INT_T0_3
MOV A,LED3
MOVC A,@A+DPTR
MOV P0,A
CLR P2.5
MOV LedT0,#3
LJMP INT_T0_END
INT_T0_3:
MOV A,LED4
MOVC A,@A+DPTR
MOV P0,A
CLR P2.4
MOV LedT0,#0
LJMP INT_T0_END
INT_T0_END:
POP PSW
POP ACC
RETI
;=============================================
START:
MOV SP,#60H
MOV TMOD,#01H ;设定T0为十六位定时模式。
MOV TH0,#0F6H ;2.5MS
MOV TL0,#03DH ;
SETB TR0 ;开定时器0
SETB ET0 ;致能定时0中断
CLR TF0 ;清定时0中断标志
SETB EA ;开总中断
MOV LedT0,#00H
MOV DPTR,#TABLE
MOV LED1,#10H
MOV LED2,#10H
MOV LED3,#10H
MOV LED4,#10H
;=============================================
SCAN:
;按键扫描
JNB P3.2,KEY_SW1
JNB P3.3,KEY_SW2
JNB P3.4,KEY_SW3
JNB P3.5,KEY_SW4
LJMP SCAN
;=============================================
KEY_SW1:
LCALL DELAY_10MS ;去抖动
JB P3.2,SCAN
MOV LED3,#0H
MOV LED4,#01
CLR P1.0 ;点亮LED
CLR Beep
CALL DELAY_100MS
SETB Beep
CALL DELAY_2S
MOV LED3,#10H
MOV LED4,#10H
SETB P1.0
JMP SCAN
;=============================================
KEY_SW2:
LCALL DELAY_10MS ;去抖动
JB P3.3,SCAN
MOV LED3,#0H
MOV LED4,#02
CLR P1.1 ;点亮LED
CLR Beep
CALL DELAY_100MS
SETB Beep
CALL DELAY_2S
MOV LED3,#10H
MOV LED4,#10H
SETB P1.1
JMP SCAN
;=============================================
KEY_SW3:
LCALL DELAY_10MS ;去抖动
JB P3.4,SCAN
MOV LED3,#0H
MOV LED4,#03
CLR P1.2 ;点亮LED
CLR Beep
CALL DELAY_100MS
SETB Beep
CALL DELAY_2S
MOV LED3,#10H
MOV LED4,#10H
SETB P1.2
JMP SCAN
;=============================================
KEY_SW4:
LCALL DELAY_10MS ;去抖动
JB P3.5,SCAN
MOV LED3,#0H
MOV LED4,#04
CLR P1.3 ;点亮LED
CLR Beep
CALL DELAY_100MS
SETB Beep
CALL DELAY_2S
MOV LED3,#10H
MOV LED4,#10H
SETB P1.3
JMP SCAN
;=============================================
DELAY_2S:
MOV R3,#200
JMP DELAY10MS
DELAY_100MS:
MOV R3,#10
JMP DELAY10MS
DELAY_10MS:
MOV R3,#1
;=============================
DELAY10MS:
MOV R4,#20
DELAY10MSA:
MOV R5,#247
DJNZ R5,$
DJNZ R4,DELAY10MSA
DJNZ R3,DELAY10MS
RET
;=============================================
TABLE:
DB 00101000B ;0
DB 11101011B ;1
DB 00110010B ;2
DB 10100010B ;3
DB 11100001B ;4
DB 10100100B ;5
DB 00100100B ;6
DB 11101010B ;7
DB 00100000B ;8
DB 10100000B ;9
DB 01100000B ;A
DB 00100101B ;b
DB 00111100B ;C
DB 00100011B ;d
DB 00110100B ;E
DB 01110100B ;F
DB 11110111B ;-
DB 11111111B ;
END
上一篇:多机红外通信发送端程序
下一篇:TLC0831转换示例程序
推荐阅读最新更新时间:2024-03-16 15:51