用51单片机做一个键盘显示,其中初始值是100,数值固化在ROM0032H中,然后将数值送
到40H中,其中40H中的为16进制数,中断0为数值设置开始,P1.0增加,P1.1减小,用P0
口显示40H,采用动态扫描方式显示,用P1.2,P1.3,P1.4作为片选控制,43H,42H,41H作为
显示缓冲区,数据大小大于0,小于999, ORG 0000H AJMP MAIN ORG 0003H AJMP INSER ORG 0030H MAIN:MOV A,#00H;开中断 MOVC A,@A+PC DB 64H MOV 40H,A MOV 43H,#01H MOV 42H,#00H MOV 41H,#00H LCALL SHOW SETB EX0 SETB IT0 SETB EA HERE:LCALL SHOW;等待中断 AJMP HERE LOOP1:INC A MOV 40H,A LCALL CHANGE LCALL SHOW MOV A,40H LCALL DELAY INSER:LCALL SHOW;判断增减 JB P1.0,LOOP LCALL DELAY JNB P1.0,LOOP1 AJMP LOOP LOOP2:DEC A MOV 40H,A LCALL CHANGE LCALL SHOW MOV A,40H LCALL DELAY LOOP:LCALL SHOW JB P1.1,INSER LCALL DELAY JNB P1.1,LOOP2 AJMP INSER CHANGE:MOV B,#64H;16进制转10进制 DIV AB JZ LP0 MOV 43H,A MOV A,B MOV B,#0AH DIV AB MOV 42H,A MOV 41H,B LP0:MOV 43H,#11H MOV A,B MOV B,0AH DIV AB JZ LP1 MOV 42H,A MOV 41H,B LP1:MOV 42H,#11H MOV 41H,B RETI SHOW:MOV R0,#41H;显示 MOV DPTR,#TAB CLR P1.3 CLR P1.4 SETB P1.2 MOV A,@R0 MOVC A,@A+DPTR MOV P0,A LCALL D1MS INC R0 CLR P1.2 SETB P1.3 MOV A,@R0 MOVC A,@A+DPTR MOV P0,A LCALL D1MS INC R0 CLR P1.3 SETB P1.4 MOV A,@R0 MOVC A,@A+DPTR MOV P0,A RETI TAB:DB 3FH,06H,5BH,4FH,66H,6DH DB 7DH,07H,7FH,6FH,77H,7CH DB 39H,5EH,79H,71H,40H,00H D1MS:MOV R7,#02H;延时1ms DL:MOV R6,#0FFH DL1:DJNZ R6,DL1 DJNZ R7,DL RETI DELAY:MOV R5,#0FAH;延时5ms L1:MOV R4,#0AH W1:DJNZ R4,W1 DJNZ R5,L1 RETI 搞了几次都不是想象的那样,PROTEUS图传不上 |