汇编计算器(最高3位数运算),想将4*4的矩阵键盘改为4*5的,原用p1.0-p1.3接行,p1.4-p1.7接列可以实现功能,改用p3.3到p3.4接键盘列,键盘扫描程序将读p1改为读p3却不能实现,还需要改其他吗?
- ORG 0000H;
- JMP MAIN;
- ORG 0003H;
- JMP INP0;
- ORG 0030H;
- /*键盘所输入数字依次存入70H-77H*/
- MAIN: MOV R6, #70H;
- MOV SP, #60H;
- CLR 80H;
- CLR 81H;
- SETB EA;
- SETB EX0;
- SETB IT0;
- DISP1: MOV R0, #70H;//从第一位地址存数
- MOV R2, #01H;//位选第一位
- DISP2: MOV A, @R0;
- LCALL SEG7; //跳转段码
- MOV P0, A; //P0输出字形
- MOV P2, R2; //位选输出
- LCALL D1MS; //跳转延时
- MOV P2, #0; //位选关闭,段码不输出
- INC R0; //选择下一位;
- MOV A, R2;
- CLR C; //进位标志清零
- RLC A; //扫描字右移
- MOV R2, A; //保存扫描字
- JNC DISP2; //C=0时, 循环一次未结束,跳转到DISP2
- PASS: LJMP DISP1;
- D1MS: MOV R7, #50H;//延时程序
- DMS: DJNZ R7, DMS;
- RET;
- SEG7: MOV DPTR, #TABLE;//查表程序
- MOVC A, @A+DPTR;
- RET;
- TABLE: DB 0C0H, 0F9H, 0A4H, 0B0H;
- DB 99H, 92H, 82H, 0F8H;
- DB 80H, 90H, 88H, 83H;
- DB 0C6H, 0A1H, 86H, 8EH;
- /*P1.0-1.3,行线; P1.4-1.7,列线;*/
- /*P0,输出字形; P2,输出位选*/
- INP0:
- PUSH ACC;
- PUSH B;
- PUSH PSW;
- START: MOV R4, #00H;
- L1: MOV R3, #0F7H;//设扫描初值,11110111,P3.3=0
- MOV R1, #00H; //取码指针;
- /*首先行扫描*/
- L2: MOV A, R3; //行扫描开始
- MOV P1, A; //扫描值输出至p1
- MOV A, P1; //读入P1的值
- MOV R4, A; //P3口中P3.4-3.7的状态通过A,传送到R4
- SETB C; //进位标志置1
- MOV R5, #04H; //
- l3: RLC A; //按键左移,通过C是否为0,判断此列是否有0;无0则r1进行累加;有0跳转到延时,
- JNC KEY; //C=0,跳转到延时
- INC R1;
- DJNZ R5, L3;
- MOV A, R3;
- SETB C;
- RRC A; //换行扫描
- MOV R3,A;
- JC L2; //C=1,跳转到L2
- KEY: ACALL DELAY;
- D1: MOV A,P1;
- XRL A,R4;
- JNZ D1;
- MOV A, R6; //指定存入地址
- MOV R0, A;
- MOV A, R1; //存入数字
- MOV @R0, A;
- /*判断运算法*/
- MOV A, R1;
- XRL A, #0AH;//判断是否为加法符
- JZ ADD1;
- MOV A, R1;
- XRL A, #0BH;//判断是否为减法符
- JZ SUBB1;
- MOV A, R1;
- XRL A, #0CH;//判断是否为乘法符
- JZ MUL1;
- MOV A, R1;
- XRL A, #0DH;//判断是否为除法符
- JZ DIV1;
- MOV A, R1;
- XRL A, #0EH;//判断是否为等于号
- JZ EQUAL1;
- MOV A, R1;
- XRL A, #0FH;//判断是否为清零键
- JZ ON1;
-
- INC R0; //选择下一个地址
- MOV A, R0; //存入r0的新数值
- MOV R6, A;
- POP PSW;
- POP B;
- pop ACC;
- RET;
- DELAY: MOV R7, #60;//消除抖动延时程序
- DLY1: DJNZ R7, DLY1;
- RET;
- ADD1: MOV A, 80H; //加法程序
- MOV 81H, A;
- LJMP D1;
- MOV A, 81H;
- ADD A, 80H;
- MOV 80H, A;
- RET;
- SUBB1: MOV A, 80H;//减法程序
- MOV 81H, A;
- LJMP DD1;
- MOV A, 80H;
- SUBB A, 81H;
- MOV 80H, A;
- RET;
- MUL1: MOV A, 80H;//乘法程序
- MOV 81H, A;
- LJMP DD1;
- MOV A, 80H;
- MUL AB;
- MOV 80H, A;
- RET;
- DIV1: MOV A, 80H;//除法程序
- MOV 81H, A;
- LJMP DD1;
- MOV A, 80H;
- DIV AB;
- MOV 80H, A;
- RET;
- EQUAL1: MOV A, 80H;//等于程序
- MOV B, #64H;//算百位数
- DIV AB;
- MOV 72H, A; //将此数除100,商数放72h,余数放71h。
- MOV 71H, B;
- MOV A, 71H;
- MOV B, 0AH;//算十位数
- DIV AB;
- MOV 71H, A; //将此数除10,商数放71h,余数放70h。
- MOV 70H, B;
- RET;
- ON1: CLR 70H; //清零程序
- CLR 71H;
- CLR 72H;
- CLR 73H;
- CLR 78H;
- CLR 79H;
- CLR 7AH;
- CLR 80H;
- CLR 81H;
- CLR 82H;
- CLR 88H;
- CLR 89H;
- CLR 8AH;
- MOV R0, 00H;
- MOV R1, 00H;
- MOV R2, 00H;
- MOV R3, 00H;
- MOV R4, 00H;
- MOV R5, 00H;
- MOV R6, 70H;
- MOV R7, 00H;
- RET;
- DD1: MOV B, #0AH;//将所输入两位数转换为十进制,并存入80h中
- MOV A, 78H;
- MUL AB;
- ADD A, 70H;
- MOV 80H, A;
- RET;
- END;
复制代码
|