AT89S52汇编实现l通过按键中断切换led灯的四种闪烁模式(单灯左移,单灯右移,双灯左移,双灯右移)

;通过P1口控制8路LED的四种闪烁模式,单独LED灯左移,单独LED灯右移,相邻两个灯左移,相邻两个灯右移
;通过一个外部中断0来检测按键的跳变沿来切换闪烁模式,第一次按键按下弹起,灯的闪烁状态由
单独LED灯左移变为单独LED灯右移,再按下按键,灯的闪烁状态由单独LED灯右移变为邻两个灯左移,依次循环4种闪烁模式。

ORG 0000H LJMP MAIN ORG 0003H LJMP RESET ORG 0100H
MOV SP,#60H ;================================================================================================================= ;================================================================================================================= MAIN: SETB IT0 SETB EX0 SETB EA START: MOV R0,#0 MOV R2,#8 MOOD0: CJNE R0,#0,MOOD1 MOV R2,#8 MOV A,#0FEH LOOP0: MOV P1,A LCALL DELAY500MS RL A DJNZ R2,LOOP0 LJMP MOOD0 MOOD1: CJNE R0,#1,MOOD2 MOV R2,#8 MOV A,#0FEH LOOP1: MOV P1,A LCALL DELAY500MS RR A DJNZ R2,LOOP1 LJMP MOOD1 MOOD2: CJNE R0,#2,MOOD3 MOV R2,#8 MOV A,#0FCH LOOP2: MOV P1,A LCALL DELAY500MS RL A RL A DJNZ R2,LOOP2 LJMP MOOD2 MOOD3: CJNE R0,#3,START MOV R2,#8 MOV A,#0FCH LOOP3: MOV P1,A LCALL DELAY500MS RR A RR A DJNZ R2,LOOP3 LJMP MOOD3 RESET: INC R0 RETURN:RETI DELAY500MS: ;误差 -0.000000000127us MOV R7,#7AH DL1: MOV R6,#0DEH DL0: MOV R5,#07H DJNZ R5,$ DJNZ R6,DL0 DJNZ R7,DL1 NOP RET END

 

posted @ 2018-12-04 17:39  Scrazy  阅读(1285)  评论(0编辑  收藏  举报