资源预览内容
第1页 / 共11页
第2页 / 共11页
第3页 / 共11页
第4页 / 共11页
第5页 / 共11页
第6页 / 共11页
第7页 / 共11页
第8页 / 共11页
第9页 / 共11页
第10页 / 共11页
亲,该文档总共11页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
用矩阵键盘做一个计算器#include <reg52.h> /52系列单片机头文件#define uchar unsigned char#define uint unsigned int sbit dula=P26;/申明U1锁存器的锁存端sbit wela=P27;/申明U2锁存器的锁存端unsigned char a1,a2,num;unsigned char code table=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f;void delayms(uint xms)unsigned int i,j;for(i=xms;i>0;i-) /i=xms即延时约xms毫秒for(j=110;j>0;j-);void display(uchar tum,uchar dat)uchar i;dula=0;P0=tabledat; /显示函数只送段选数据dula=1;dula=0;wela=0;i=0xff;i=i&(0x01)<<(tum);P0=i;wela=1;wela=0;void matrixkeyscanuchar temp,a3;P3=0xfe;temp=P3;temp=temp&0xf0;if(temp!=0xf0)delayms(10);temp=P3;temp=temp&0xf0;if(temp!=0xf0)temp=P3;switch(temp)case 0xee:a3=1;break;case 0xde:a3=2;break;case 0xbe:a3=3;break;case 0x7e:a3=4;break;if(num>0)a2=a3;display(1,a2);if(num=0)a1=a3;display(0,a1);num+; while(temp!=0xf0)temp=P3;temp=a3&0xf0;P3=0xfd;temp=P3;temp=temp&0xf0;if(temp!=0xf0)delayms(10);temp=P3;temp=temp&0xf0;if(temp!=0xf0)temp=P3;switch(temp)case 0xed:a3=5;break;case 0xdd:a3=6;break;case 0xbd:a3=7;break;case 0x7d:a3=8;break;if(num>0)a2=a3;display(1,a2);if(num=0)a1=a3;display(0,a1);num+; while(temp!=0xf0)temp=P3;temp=temp&0xf0;P3=0xfb;temp=P3;temp=temp&0xf0;if(temp!=0xf0)delayms(10);temp=P3;temp=temp&0xf0;if(temp!=0xf0)temp=P3;switch(temp)case 0xeb:a3=9;if(num>0)a2=a3;display(1,a2);if(num=0)a1=a3;display(0,a1);num+; break;case 0xdb:a3=0;if(num>0)a2=a3;display(1,a2);if(num=0)a1=a3;display(0,a1);num+; break;case 0xbb:a3=11; display(2,a1+a2);break;case 0x7b:a3=11;display(2,a1-a2);break;while(temp!=0xf0)temp=P3;temp=temp&0xf0;P3=0xf7;temp=P3;temp=temp&0xf0;if(temp!=0xf0)delayms(10);temp=P3;temp=temp&0xf0;if(temp!=0xf0)temp=P3;switch(temp)case 0xe7:a3=11;display(2,a1*a2); break;case 0xd7:a3=11;display(2,a1/a2); break;case 0xb7:a3=11;break;case 0x77:a3=11;break;while(temp!=0xf0)temp=P3;temp=temp&0xf0;void mainwhile(1)matrixkeyscan;/不停调用键盘扫描程序
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号