刚学C,改了一个,看看行不行.
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f};
uchar t0,num;
void display(uchar shu);
void init();
void delay(uint z);
void keyscan();
void main()
{
init();
while(1)
{
display(num);
}
}
void init()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t0++;
if(t0==20)
{
t0=0;
num++;
if(num==1)
P1=0xfe;
else if(num==2)
P1=0xfd;
else if(num==3)
P1=0xfb;
else if(num==4)
P1=0xf7;
else if(num==5)
P1=0xef;
else if(num==6)
P1=0xdf;
else if(num==7)
P1=0xbf;
else if(num==8)
P1=0;
else
num=0;
}
}
void display(uchar shu)//显示子函数
{
uchar ge;
ge=shu%10;
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
}
void delay(uint z)//延时子函数
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
|