⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1-9按键加减.txt

📁 关于单片机中流水线处理,红绿灯转化等实验
💻 TXT
字号:
	CURR_NUM	EQU	30H

	org	0000H		
	jmp	MAIN

;*******************************************	
	org	0030H		;Start program from 0030H		
MAIN:
	mov	P0,#0FFH	;Initialize the port	
	mov	P1,#0FFH	
	mov	P2,#0FFH	
	mov	P3,#0FFH
	
	mov	CURR_NUM,#00H	;Initilize the var
	clr	P3.3		;Clear the common line

MAIN_LOOP:
	jb	P2.7,KEY_2	;Wait for key down,ADD
	call	DELAY
	call	NUM_ADD
	jmp	NEXT_LOOP
	
KEY_2:
	jb	P2.6,NEXT_LOOP	;Wait for key down,SUB
	call	DELAY
	call	NUM_SUB
	jmp	NEXT_LOOP	

NEXT_LOOP:
	call	DISPLAY_NUM
	jmp	MAIN_LOOP

	ret
;****************************************************
DISPLAY_NUM:
	;Get the code of led
	mov	a,CURR_NUM
	mov	dptr,#TAB_LED
	movc	a,@a+dptr

	mov	P0,a		;Display the number
	mov	P2,#11111011B

	ret
;****************************************************
NUM_ADD:
	;Get next value
	mov	a,CURR_NUM
	mov	dptr,#TAB_NEXT
	movc	a,@a+dptr
	mov	CURR_NUM,a
	
	ret
;****************************************************
NUM_SUB:
	;Get previos value
	mov	a,CURR_NUM
	mov	dptr,#TAB_PRE
	movc	a,@a+dptr
	mov	CURR_NUM,a
	
	ret
;****************************************************
DELAY:
	mov	r7,#200
DELAY_LOOP:
	mov	r6,#200
	djnz	r6,$
	mov	r6,#200
	djnz	r6,$

	djnz	r7,DELAY_LOOP
	ret
;****************************************************
;****************************************************
;LED code
TAB_LED:	
	DB	0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
              ;   0    1    2    3   4   5   6   7    8   9    
;===================================================
;For sub
TAB_PRE:	
	DB	09H,00H,01H,02H,03H,04H,05H,06H,07H,08H
;===================================================
;For add
TAB_NEXT:	
	DB	01H,02H,03H,04H,05H,06H,07H,08H,09H,00H
;****************************************************
END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -