#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar x,t;
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e};
void main()
{
x=0;
t=0;
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;//启动定时器0
P1=0xff;
P2=0xc0;
while(1)
{
if(t==20)
{
t=0;
x++;
if(x==16)
x=0;
P2=table[x];
}
}
}
void exter0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t++;
}
上面的有效,可以使得四位数码管从0-Fl亮。
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar x,t;
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e};
void main()
{
x=0;
t=0;
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;//启动定时器0
}
void exter0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t++;
P1=0xff;
P2=0xc0;
while(1)
{
if(t==20)
{
t=0;
x++;
if(x==16)
x=0;
P2=table[x];
}
}
}
这样数码管就不能亮了。求高手啊!!!