这么简单的问题 随便一本51单片机书上就有 实在不行 参考下面代码
#include
#define uchar unsigned char
#define uint unsigned int
uchar code shu[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar wei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //开启0-7数码管
uint aa=0,chu=0;
char num;
sbit d3=P1^3;
sbit d1=P1^1;
sbit d0=P1^0;
sbit d2=P1^2;
sbit s1=P2^4;
sbit s2=P2^5;
delay(uint z)
{
uint x,y;
for(x=110;x>0;x--)
for(y=z;y>0;y--);
}
void init ()
{
TMOD=0x01;
EA=1;
ET0=1;
TR0=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
void main()
{
d3=0;
d2=0;
P0=0X00;
init();
while(1)
{
//写你想写的代码 num每加一次 表示秒钟增加一次
}
}
void duan() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
if(aa==20)
{
aa=0;
num++;
}
}