求解答!!独立按键控制数码管加减,然后减到0再按一次,首位灯管就全亮了【如图】,按多少次减就要加多少次才正常显示,蒙了
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit DU = P2^6;
sbit WE = P2^7;
sbit key_s2 = P3^0;
sbit key_s4 = P3^2;
uchar num;
uchar code tabel[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,};
void delay(uint z)
{
uint x,y;
for(x = z;x > 0;x --)
for(y = 114; y > 0;y--);
}
void main()
{
WE = 1;
P0 = 0xFE;
WE = 0;
while(1)
{
if(key_s2 == 0)
{
delay(20);
if(key_s2 == 0)
{
num++;
if(num != 9)
while(!key_s2);
}
}
if(key_s4 == 0)
{
delay(20);
if(key_s4 == 0)
{
if(num > 0);
num--;
while(!key_s4);
}
}
DU = 1;
P0 = tabel[num];
DU = 0;
}
}
此帖出自
小平头技术问答
num--;这个应该在if语句中,你现在这样写不对
一周热门 更多>