#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit DU = P2^6;
sbit WE = P2^7;
uchar num;
uchar code table[] = {
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71 };
void delay(uint x) //延时 x ms
{
uint i,j;
for(i = x;i > 0;i--)
for(j = 110;j > 0;j--);
}
void display(uchar temp)
{
DU = 1;
P0 = table[temp];
DU = 0;
P0 = 0xff;
WE = 1;
P0 = 0x00;
WE = 0;
delay(500);
}
void main()
{
WE = 1; //打开U2锁存器
P0 = 0xc0; //送入位选信号
WE = 0;
while(1)
{
display(num);
num++;
if(num == 16)
num = 0;
delay(500);
}
}
|