完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
矩阵键盘和数码管实现简易计算器,但是在烧录后只能显示第一次按下的数字,后边就没反应了不知道是哪里写作了求大神帮忙看看
#include #include #define uchar unsigned char #define uint unsigned int ***it duan=P2^6; ***it wei=P2^7; uchar temp; uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; uchar code weima[]={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf}; void display(unsigned long a); uchar keyscan(); void delay(uint xms); void main() { unsigned long num1=0,num2=0,dispbuf=0; unsigned char key,flag=1,fuhao; while(1) { if(flag==1) { key=keyscan(); if(key<10) { num1=num1*10+key; dispbuf=num1; } else if(key==12) { fuhao='+'; flag=2; } else if(key==13) { fuhao='-'; flag=2; } else if(key==14) { fuhao='*'; flag=2; } else if(key==15) { fuhao='/'; flag=2; } } else if(flag==2) { key=keyscan(); if(key<10) { num2=num2*10+key; dispbuf=num2; } else if(key==11) { switch(fuhao) { case'+':dispbuf=num1+num2;break; case'-':dispbuf=num1-num2;break; case'*':dispbuf=num1*num2;break; case'/':dispbuf=num1/num2;break; } } } display(dispbuf); } } void maco(unsigned char du,unsigned char we) { duan=1; P0=table[du]; duan=0; P0=0xff; wei=1; P0=weima[we]; wei=0; } void display(unsigned long x) { int i; unsigned char a[6]; if(x==0) { maco(0,1); } else { for(i=0;x!=0;i++) { a[i]=x%10; x/=10; } switch(i) { case 1: maco(a[0],1); while(1); case 2: while(1) { maco(a[1],1); delay(1); maco(a[0],2); delay(1); } case 3: while(1) { maco(a[2],1); delay(1); maco(a[1],2); delay(1); maco(a[0],3); delay(1); } case 4: while(1) { maco(a[3],1); delay(1); maco(a[2],2); delay(1); maco(a[1],3); delay(1); maco(a[0],4); delay(1); } case 5: while(1) { maco(a[4],1); delay(1); maco(a[3],2); delay(1); maco(a[2],3); delay(1); maco(a[1],4); delay(1); maco(a[0],5); delay(1); } case 6: while(1) { maco(a[5],1); delay(1); maco(a[4],2); delay(1); maco(a[3],3); delay(1); maco(a[2],4); delay(1); maco(a[1],5); delay(1); maco(a[0],6); delay(1); } } } } |
|
相关推荐
1个回答
|
|
你认为这里死循环while(1);程序能够跑下去吗?
...... switch(i) { case 1: maco(a[0],1); while(1); case 2: while(1) { maco(a[1],1); delay(1); maco(a[0],2); delay(1); }.......................... |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
308 浏览 0 评论
431 浏览 0 评论
《DNK210使用指南 -CanMV版 V1.0》第三十四章 image图像滤波实验
372 浏览 0 评论
【RA-Eco-RA2E1-48PIN-V1.0开发板试用】简介、环境搭建、工程测试
395 浏览 0 评论
730 浏览 1 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11629 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-7 15:26 , Processed in 0.710521 second(s), Total 72, Slave 54 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号