房天下 > 房天下问答 > 业主生活 > 其他
  • 矩阵键盘在数码管上显示1-16的平方,只显示个位

    如题,就是我用protues仿真只显示个位数,其他不显示#include <reg52.h>#define uint unsigned int#define uchar unsigned charsbit dula=P2^6;sbit wela=P2^7;int num;uchar temp,rnum,i,bai,shi,ge,aa;uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0};uchar fanhui();void display(uchar,uchar,uchar);void delay(uint z){ uint x,y; if(x=z,x>0,x--) {if(y=110,y>0,y--);}}void main(){ uchar aa1, aa2; while(1) { aa1 = fanhui(); display(bai, shi, ge); //用显示,当延时,消抖 aa2 = fanhui(); //再读 if (aa1 == aa2) aa = aa1; //两者相等,确认到aa i = aa * aa; bai = i / 100; shi = (i % 100) / 10; ge = i % 10; display(bai, shi, ge); }} uchar fanhui(){ P3=0xfe; temp=P3; temp=temp&0xf0; while(temp!=0xf0) { dula=1; P0=0; dula=0; delay(10); temp=P3; temp=temp&0xf0; while(temp!=0xf0) { temp=P3; switch(temp) { case 0xe

    提问者:快乐男主妇

    发布于2010-11-19

共1个回答
  • 新月驿站 丨Lv 3
    while(1) { aa1 = fanhui(); display(bai, shi, ge); //用显示,当延时,消抖. aa2 = fanhui(); //再读. if (aa1 == aa2) aa = aa1; //两者相等,确认到aa---------如果不相等呢?aa = ? i = aa * aa; bai = i / 100; shi = (i % 100) / 10; ge = i % 10; display(bai, shi, ge); }另外,按键检测程序太长了!4*4的,程序可以在10行之内(不包括大括号占的行数)。到我的空间找找看。 **************************************************好了。你的延时函数里面的:for,都写成什么了?//-----------------------------------------------------void delay(uint z){ uint x, y; for (x = z; x > 0; x--) for (y = 110; y > 0; y--);}//-----------------------------------------------------void display(uchar bai, uchar shi, uchar ge){ wela = 1; P0 = 0xff; wela = 0; //消隐. dula = 1; P0 = table[bai]; dula = 0; wela = 1; P0 = 0xfd; wela = 0; delay(10); wela = 1; P0 = 0xff; wela = 0; dula = 1; P0 = table[shi]; dula = 0; wela = 1; P0 = 0xfb; wela = 0; delay(10); wela = 1; P0 = 0xff; wela = 0; dula = 1; P0 = table[ge]; dula = 0; wela = 1; P0 = 0xf7; wela = 0; delay(10);} //-----------------------------------------------------void main(){ while(1) { i = 128; bai = i / 100; shi = (i % 100) / 10; ge = i % 10; display(bai, shi, ge); }} //-----------------------------------------------------
    +1 2010-11-19 举报
热门人气推荐
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。