键盘输入的数字在串口调试助手显示,然后再到数码管(汇编语言版本)

时间:2022-01-26 01:27:51
//实验目的:按下按键就在数码管上显示相应数字,并且传送到串口调试助手上
org 00H
ljmp start

org 30H
start: 	 
        
	   mov P0,#0xff//设置初始值
	   mov dptr,#numb
	   lcall en
	   lcall UART_init 
       here:
	   		lcall  keyin
	        sjmp here  //好比是一个while(1)循环

;首先3/8译码器使能	并且选中第一个数码管用于显示
en:
   	clr   P1.4
	setb  P1.3
	clr   P1.0
	clr   P1.1
	clr   P1.2
ret

//uart初始化
UART_init:

   mov TMOD,#0x20  //0010 0000   说明在定时器1的工作方式2下工作
   mov  TH1,#0xFD
   mov  TL1,#0xFD 
   setb TR1  //定时器1运行控制位=1,说明开始计时
   mov SCON,#0x50 //0101 0000   前两位说明在串口工作方式1  第三位SM2在方式1设置为0  第四位REN=1允许串口接收 
 ret

//延时函数	延时为6ms左右,这个延时主要用于按键去抖动
delay: 	 
       mov R0,#100
	   
	   j1:
	       mov R1,#30
	       djnz R0,j2
		   ljmp quit
	   j2:
		   djnz R1,j2
      	   ljmp j1
       quit:
ret
//按键函数
keyin:
	   j10:
		   clr  P2.3//keyout1
		   setb P2.2//keyout2
		   setb P2.1//keyout3
		   setb P2.0//keyout4
	   j11:
	       jb P2.4,j12
		   lcall delay
		   jb P2.4,j12
		   mov A,#0
		   movc A,@A+dptr
		   mov P0,A
		   mov SBUF,#0

	   j12:
	       jb P2.5,j13
		   lcall delay
		   jb P2.5,j13
		   mov A,#1
		   movc A,@A+dptr
		   mov P0,A
		   mov SBUF,#1
	   j13:
	       jb P2.6,j14
		   lcall delay
		   jb P2.6,j14
		   mov A,#2
		   movc A,@A+dptr
		   mov P0,A
		   mov SBUF,#2
       j14:
	       jb P2.7,j15
		   lcall delay
		   jb P2.7,j15
		   mov A,#3
		   movc A,@A+dptr
		   mov P0,A
		   mov SBUF,#3
	   j15:
		    jnb P2.4,j15
			jnb P2.5,j15
			jnb P2.6,j15
			jnb P2.7,j15



//---------------------------------------
	    j20:
		   setb P2.3//keyout1
		   clr  P2.2//keyout2
		   setb P2.1//keyout3
		   setb P2.0//keyout4
		j21:
	       jb P2.4,j22
		   lcall delay
		   jb P2.4,j22
		   mov A,#4
		   movc A,@A+dptr
		   mov P0,A
		   mov SBUF,#4

	   j22:
	       jb P2.5,j23
		   lcall delay
		   jb P2.5,j23
		   mov A,#5
		   movc A,@A+dptr
		   mov P0,A
		   mov SBUF,#5
	   j23:
	       jb P2.6,j24
		   lcall delay
		   jb P2.6,j24
		   mov A,#6
		   movc A,@A+dptr
		   mov P0,A
		   mov SBUF,#6
       j24:
	       jb P2.7,j25
		   lcall delay
		   jb P2.7,j25
		   mov A,#7
		   movc A,@A+dptr
		   mov P0,A
		   mov SBUF,#7
		j25:
		    jnb P2.4,j25
			jnb P2.5,j25
			jnb P2.6,j25
			jnb P2.7,j25

//---------------------------------------
		j30:
		   setb P2.3//keyout1
		   setb P2.2//keyout2
		   clr  P2.1//keyout3
		   setb P2.0//keyout4
		j31:
	       jb P2.4,j32
		   lcall delay
		   jb P2.4,j32
		   mov A,#8
		   movc A,@A+dptr
		   mov P0,A
		   mov SBUF,#8

	   j32:
	       jb P2.5,j33
		   lcall delay
		   jb P2.5,j33
		   mov A,#9
		   movc A,@A+dptr
		   mov P0,A
		   mov SBUF,#9
	   j33:
	       jb P2.6,j34
		   lcall delay
		   jb P2.6,j34
		   mov A,#10
		   movc A,@A+dptr
		   mov P0,A
		   mov SBUF,#10
       j34:
	       jb P2.7,j35
		   lcall delay
		   jb P2.7,j35
		   mov A,#11
		   movc A,@A+dptr
		   mov P0,A 
		   mov SBUF,#11
		j35:
		    jnb P2.4,j35
			jnb P2.5,j35
			jnb P2.6,j35
			jnb P2.7,j35



//---------------------------------------
		j40:
		   setb P2.3//keyout1
		   setb P2.2//keyout2
		   setb P2.1//keyout3
		   clr  P2.0//keyout4
	 
		j41:
	       jb P2.4,j42
		   lcall delay
		   jb P2.4,j42
		   mov A,#12
		   movc A,@A+dptr
		   mov P0,A
		   mov SBUF,#12

	   j42:
	       jb P2.5,j43
		   lcall delay
		   jb P2.5,j43
		   mov A,#13
		   movc A,@A+dptr
		   mov P0,A
		   mov SBUF,#13
	   j43:
	       jb P2.6,j44
		   lcall delay
		   jb P2.6,j44
		   mov A,#14
		   movc A,@A+dptr
		   mov P0,A
		   mov SBUF,#14
       j44:
	       jb P2.7,j45
		   lcall delay
		   jb P2.7,j45
		   mov A,#15
		   movc A,@A+dptr
		   mov P0,A
		   mov SBUF,#15
		j45:
		    jnb P2.4,j45
			jnb P2.5,j45
			jnb P2.6,j45
			jnb P2.7,j45
ret
    						  
//0-F

numb:
     DB 0x0c0,0x0F9,0x0A4,0x0B0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E
end