数码管只能显示0 1 3 5,但是不显示2和4,不知道自己程序哪里出了问题,希望大家帮忙看一下程序哪一步需要修改。
单片机源程序如下:
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar code table[]={~0xc0,~0xf9,~0xa4,~0xb0,~0x99,~0x92,~0x82,~0xf8,~0x80,~0x90};//数码管段选
uchar code wela[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};//数码管位选
sbit beep=P2^3;
sbit switch1=P2^6;//段选LE
sbit switch2=P2^7;//位选LE
uchar x;
void delay(uint z)//unit是宏定义
{
uint x,y;
for(x=z;x>0;x--)
for(y=0;y<100;y++);
}
void display()
{
uchar x;
for(x=0;x<6;++x)
{ P0=0x00;
switch1=1;
switch1=0;
switch2=1;
P0=wela[x];
switch2=0;
switch1=1;
P0=table[x];
switch1=0;
delay(8);
switch2=1;
}
}
void main()
{
beep=0;
while(1)
{
display();
}
}
|