數碼管只能顯示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();
}
}
|