单片机汇编语言源程序如下:- ORG 0000H ;程序上电从0000H开始
- AJMP MAIN ;跳转到主程序
- ORG 0004H ;主程序起始地址
-
- KEY0 BIT P3.1 ;定义IO端口
- KEY1 BIT P3.0
- KEY2 BIT P3.2
- KEY3 BIT P3.3
-
- LED0 BIT P2.0
- LED1 BIT P2.1
- LED2 BIT P2.2
- LED3 BIT P2.3
- LED4 BIT P2.4
- LED5 BIT P2.5
- LED6 BIT P2.6
- LED7 BIT P2.7
- MAIN:
- ;初始按键全部弹起
- SETB KEY0
- SETB KEY1
- SETB KEY2
- SETB KEY3
-
- ;初始LED全部熄灭
- SETB LED0
- SETB LED1
- SETB LED2
- SETB LED3
- SETB LED4
- SETB LED5
- SETB LED6
- SETB LED7
-
- SETB LED0 ;初始化LED0熄灭
- CLR LED0 ;给低电平LED0亮
- LCALL DELAY_250MS
- CPL LED0
-
- SETB LED1 ;初始化LED1熄灭
- CLR LED1 ;给低电平LED1亮
- LCALL DELAY_250MS
- CLR LED0
- LCALL DELAY_250MS
- CPL LED1
- SETB LED2 ;初始化LED2熄灭
- CLR LED2 ;给低电平LED2亮
- CPL LED0
- LCALL DELAY_250MS
- CLR LED0
- LCALL DELAY_250MS
- CPL LED0
- CLR LED1
- LCALL DELAY_250MS
- CLR LED0
- LCALL DELAY_250MS
- CPL LED1
- CPL LED2
-
- SETB LED3 ;初始化LED3熄灭
- CLR LED3 ;给低电平LED3亮
- CPL LED0
- LCALL DELAY_250MS
- CLR LED0
- LCALL DELAY_250MS
- CPL LED0
- CLR LED1
- LCALL DELAY_250MS
- CPL LED0
- LCALL DELAY_250MS
- CPL LED1
- CLR LED2
- CPL LED0
- LCALL DELAY_250MS
- CLR LED0
- LCALL DELAY_250MS
- CLR LED1
- CPL LED0
- LCALL DELAY_250MS
- CLR LED0
- LCALL DELAY_250MS
- CPL LED3
- CPL LED0
- CPL LED1
- CPL LED2
-
- LCALL LOOP
-
- LOOP:
- JB KEY0,LOOP1 ;KEY0按下
- LCALL DELAY10MS ;延时去按下抖动
- JB KEY0,LOOP1
- JNB KEY0,[ DISCUZ_CODE_1 ]nbsp;
- LCALL DELAY10MS ;延时去弹起抖动
- CPL LED4
-
- LOOP1:
- JB KEY1,LOOP2 ;KEY1按下
- LCALL DELAY10MS ;延时去按下抖动
- JB KEY1,LOOP
- JNB KEY1,$
- LCALL DELAY10MS ;延时去弹起抖动
- CPL LED5
-
- LOOP2:
- JB KEY2,LOOP3 ;KEY2按下
- LCALL DELAY10MS ;延时去按下抖动
- JB KEY2,LOOP3
- JNB KEY2,$
- LCALL DELAY10MS ;延时去弹起抖动
- CPL LED6
- LJMP LOOP
-
- LOOP3:
- JB KEY3,LOOP ;KEY3按下
- LCALL DELAY10MS ;延时去按下抖动
- JB KEY3,LOOP
- JNB KEY3,$
- LCALL DELAY10MS ;延时去弹起抖动
- CPL LED7
- LJMP LOOP
-
- DELAY10MS:
- NOP
- NOP
- NOP
- PUSH 30H
- PUSH 31H
- MOV 30H,#87
- MOV 31H,#10
- RET
- DELAY_250MS:
- MOV R7,#10
- D1: MOV R6,#100
- D2: MOV R5,#250
- DJNZ R5,$
- DJNZ R6,D2
- DJNZ R7,D1
- RET
-
- END
复制代码
|