‘壹’ 51单片机为基础用汇编语言编写用数码管显示一个同时有"加""减""乘""除"法功能的计算器程序,急用参考
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:MOV SP,#7EH
MOV 22H,#00H
CLR P2.0
CLR P2.3
MOV 20H,#00H
MOV 21H,#00H
MOV 30H, #00H
MOV 31H, #00H
MOV 32H, #00H ;初始化
SU: MOV 7DH,#0FFH
MOV 7EH,#0FFH
MOV 7FH,#0FFH
KEYI:ACALL KS1
CJNE A,#0F0H,LK1
ACALL DIR
AJMP KEYI
LK1:ACALL DIR
ACALL DIR
ACALL KS1
CJNE A, #0F0H,LK2
ACALL DIR
AJMP KEYI
LK2: ACALL KS1
MOV R2,A
ORL A,#0FH
MOV P0,A
ANL A,#0FH
ADD A,R2 ;键特征值
CJNE A,#0EEH,JZHI1
MOV A,#00H
PUSH ACC
JZHI1: CJNE A,#0DEH,JZHI2
MOV A,#01H
PUSH ACC
JZHI2: CJNE A,#0BEH, JZHI3
MOV A,#02H
PUSH ACC
JZHI3: CJNE A,#7EH,JZHI4
MOV A,#03H
PUSH ACC
JZHI4: CJNE A, #0EDH, JZHI5
MOV A,#04H
PUSH ACC
JZHI5: CJNE A,#0DDH, JZHI6
MOV A, #05H
PUSH ACC
JZHI6: CJNE A,#0BDH, JZHI7
MOV A, #06H
PUSH ACC
JZHI7: CJNE A,#07DH, JZHI8
MOV A, #07H
PUSH ACC
JZHI8: CJNE A,#0EBH, JZHI9
MOV A, #08H
PUSH ACC
JZHI9: CJNE A,#0DBH, JZHI10
MOV A, #09H
PUSH ACC
JZHI10: CJNE A,#0BBH, JZHI11
MOV 20H,#01H
JZHI11: CJNE A,#07BH,FAN
MOV 21H, #01H
LCALL GMI
SETB P2.2 ;灭绿灯
LJMP SU ;改密
FAN: MOV A, 81H
CJNE A,#7FH, KEYI
JNB (20H).0, KEYITMP
MOV 20H,#00H
JBC (21H).0,LOOP
POP ACC
CJNE A,32H,NOTE
MOV 7FH,A
POP ACC
CJNE A,31H,NOTE
MOV 7EH,A
POP ACC
CJNE A,30H,NOTE
MOV 7DH,A
CLR P2.2
KEYITMP:LJMP KEYI
NOTE:LCALL BAOJ ;NOT是保留字不能做标号
SUTMP:LJMP SU
BAOJ:MOV SP,#7EH
INC 22H
JNB (22H).1, SUTMP
CLR P2.1
SETB P2.3
ACALL DELY1
CPL P2.1
CPL P2.3
MOV 22H,#00H
RET
GMI:JNB P2.2,SUTMP
LOOP:POP 32H
POP 31H
POP 30H
RET
DIR:MOV R0,#7DH
MOV R3,#01H
LD1: MOV A,@R0
MOV P1,A
MOV P3,R3
LCALL DELY
INC R0
MOV A,R3
JB ACC.2,LD2
RL A
MOV R3,A
SJMP LD1
LD2:RET ;显示
DELY:MOV R7,#249
DL:DJNZ R7,DL
RET ;1ms延时
DELY1:MOV R5,#200
MOV R4,#50
LOOP1:MOV R3,#248
NOP
LOOP2:DJNZ R3,LOOP2
DJNZ R5,LOOP1
DJNZ R4,LOOP1
RET ;10s延时
KS1:MOV P0,#0F0H
MOV A,P0
ANL A, #0F0H
RET ;键是否按下
end
‘贰’ 如何使用51单片机1602液晶显示和按键实现进制转换计算器设计
8位AD,最大255; uchar num; num=AD_receive();//把AD采集回来的数据保存 write_com(0x80);//1602从0x80开始显示数据 write_data(num/100+0x30); //显示字符百位,后面以此类推 write_data(num%100/10+0x30);//十位数 write_data(num%10+0x30);//个位数 至于1602的驱动程序,网上多得是,找找就有了
‘叁’ 单片机做计算器的程序
1、直接调用库函数。
‘肆’ 怎样用51单片机做计算器啊
1、硬件仿真图
4、程序源代码
#include <reg51.h>#include <intrins.h>
#include <ctype.h>
#include <stdlib.h>
#define uchar unsigned char
#define uint unsigned int
uchar operand1[9], operand2[9];
uchar operator;
void delay(uint);
uchar keyscan();
void disp(void);
void buf(uint value);
uint compute(uint va1,uint va2,uchar optor);
uchar code table[] = {0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,0xff};
uchar dbuf[8] = {10,10,10,10,10,10,10,10};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
uchar keyscan()
{
uchar skey;
P1 = 0xfe;
while((P1 & 0xf0) != 0xf0)
{
delay(3);
while((P1 & 0xf0) != 0xf0)
{
switch(P1)
{
case 0xee: skey = '7'; break;
case 0xde: skey = '8'; break;
case 0xbe: skey = '9'; break;
case 0x7e: skey = '/'; break;
default: skey = '#';
}
while((P1 & 0xf0) != 0xf0)
;
}
}
P1 = 0xfd;
while((P1 & 0xf0) != 0xf0)
{
delay(3);
while((P1 & 0xf0) != 0xf0)
{
switch(P1)
{
case 0xed: skey = '4'; break;
case 0xdd: skey = '5'; break;
case 0xbd: skey = '6'; break;
case 0x7d: skey = '*'; break;
default: skey = '#';
}
while((P1 & 0xf0) != 0xf0)
;
}
}
P1 = 0xfb;
while((P1 & 0xf0) != 0xf0)
{
delay(3);
while((P1 & 0xf0) != 0xf0)
{
switch(P1)
{
case 0xeb: skey = '1'; break;
case 0xdb: skey = '2'; break;
case 0xbb: skey = '3'; break;
case 0x7b: skey = '-'; break;
default: skey = '#';
}
while((P1 & 0xf0) != 0xf0)
;
}
}
P1 = 0xf7;
while((P1 & 0xf0) != 0xf0)
{
delay(3);
while((P1 & 0xf0) != 0xf0)
{
switch(P1)
{
case 0xe7: skey = '$'; break;
case 0xd7: skey = '0'; break;
case 0xb7: skey = '='; break;
case 0x77: skey = '+'; break;
default: skey = '#';
}
while((P1 & 0xf0) != 0xf0)
;
}
}
return skey;
}
void main()
{
uint value1, value2, value;
uchar ckey, cut1 = 0, cut2 = 0;
uchar operator;
uchar i, bool = 0;
init:
buf(0);
disp();
value = 0;
cut1 = cut2 = 0;
bool = 0;
for(i = 0;i < 9;i++)
{
operand1[i] = '