用矩阵键盘做一个计算器.docx

上传人:牧羊曲112 文档编号:3120566 上传时间:2023-03-10 格式:DOCX 页数:11 大小:37.10KB
返回 下载 相关 举报
用矩阵键盘做一个计算器.docx_第1页
第1页 / 共11页
用矩阵键盘做一个计算器.docx_第2页
第2页 / 共11页
用矩阵键盘做一个计算器.docx_第3页
第3页 / 共11页
用矩阵键盘做一个计算器.docx_第4页
第4页 / 共11页
用矩阵键盘做一个计算器.docx_第5页
第5页 / 共11页
亲,该文档总共11页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《用矩阵键盘做一个计算器.docx》由会员分享,可在线阅读,更多相关《用矩阵键盘做一个计算器.docx(11页珍藏版)》请在三一办公上搜索。

1、用矩阵键盘做一个计算器#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&

2、gt0;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(t

3、emp!=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

4、(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&0xf

5、0;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!

6、=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;/不停调用键盘扫描程序

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号