好文档 - 专业文书写作范文服务资料分享网站

51单片机双显示小数计算器(可打印修改) (2)

天下 分享 时间: 加入收藏 我要投稿 点赞

自己制作的单片机程序,既可以用数码管显示,也可以用1602显示,且可以显示小数~~~#include#include

#define uint unsigned int#define uchar unsigned charuchar code tabledu[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};uchar code tabledu1[16]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0xf7,0xfc,0xb9,0xde,0xf9,0xf1};uchar code tablewe[8]={0,1,2,3,4,5,6,7};uchar code table[]=%uchar dispbuf[4]={0,0,0,0}; float dispbuf1[4]={0,0,0,0};

uchar aa,temp,key,keypos,flag,fuhao,a0,b0,c0,d0,e0,flag1,flag2,a1,b1,c1,d1;float num1,num2,num3,flag3=1; int num5,num6,num7,n2;long n1;

sbit RS=P2^5;sbit RW=P2^6;sbit E=P2^7;sbit key1=P3^2;sbit key2=P3^3;sbit key3=P3^4;void keyscan1();void ukeyscan1(); void delay(uint z){

uint x,y;

for(x=z;x>0;x--) for(y=110;y>0;y--);}

void change(uchar *p,uchar count){

count=4-count;while(count<3) {

*(p+count)=*(p+count+1); count++; }}

float jisuan(float x,char y,float z){

float m;

if(y==10)m=x+z;if(y==11)m=x-z;if(y==12)m=x*z;if(y==13)m=x/z;return m;

}

bit Busy(void){

bit busy_flag = 0;RS = 0;RW = 1;E = 1;delay(1);

busy_flag = (bit)(P0 & 0x80);E = 0;

return busy_flag;}

void wcmd(uchar del){

while(Busy());RS=0;RW=0;E=0;P0=del;delay(1);E=1;delay(1);E=0;}

void wdata(uchar del){

while(Busy());RS=1;RW=0;E=0;P0=del;delay(1);E=1;delay(1);E=0;}

void keyscan() {

P1=0xfe; temp=P1;

temp=temp&0xf0; while(temp!=0xf0) {

delay(5); temp=P1; temp=temp&0xf0; while(temp!=0xf0) { temp=P1;

switch(temp) { case 0xee:key=1; break; case 0xde:key=2; break; case 0xbe:key=3; break; case 0x7e:key=4; break; }

while(temp!=0xf0) { temp=P1; temp=temp&0xf0; }

if ((key>=0)&&(key<10)) { keypos++;

if(flag2==0) {

if(keypos<=4)

{ change(dispbuf,keypos); dispbuf[3]=key; }

}

else dispbuf1[keypos-1]=key;

} } }

P1=0xfd; temp=P1;

temp=temp&0xf0; while(temp!=0xf0) { delay(5); temp=P1;

51单片机双显示小数计算器(可打印修改) (2)

自己制作的单片机程序,既可以用数码管显示,也可以用1602显示,且可以显示小数~~~#include#include#defineuintunsignedint#defineucharunsignedcharucharcodetabledu[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x0
推荐度:
点击下载文档文档为doc格式
3jkr58pr0u4vbt01gdv99bpag891im0044d
领取福利

微信扫码领取福利

微信扫码分享