#include<reg52.h>
sbit SEG1=P3^7;
sbit SEG2=P2^0;
sbit SEG3=P2^1;
sbit SEG4=P2^2;
unsigned char i=0;
unsigned int cnt=0;
unsigned long sec=0;
unsigned char code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
unsigned char cache[4]={
0x3f,0x3f,0x3f,0x3f};
void main()
{
TMOD=1;
TH0=(65535-1000)/256;
TL0=(65535-1000)%256;
TR0=1;
while(1)
{
if(TF0=1)
{
TF0=0;
TH0=(65535-1000)/256;
TL0=(65535-1000)%256;
cnt++;
if(cnt==1000)
{
cnt=0;
sec++;
cache[0]=table[sec%10];
cache[1]=table[sec/10%10];
cache[2]=table[sec/100%10];
cache[3]=table[sec/1000%10];
}
if (i == 0)
{SEG1=1;SEG2=0;SEG3=0;SEG4=0; i++; P0=cache[0]; }
else if (i == 1)
{SEG1=0;SEG2=1;SEG3=0;SEG4=0; i++; P0=cache[1]; }
else if (i == 2)
{SEG1=0;SEG2=0;SEG3=1;SEG4=0; i++; P0=cache[2]; }
else if (i == 3)
{SEG1=0;SEG2=0;SEG3=0;SEG4=1; i=0; P0=cache[3]; }
}
}
}
开发板上数码管显示乱码。。。。
sbit SEG1=P3^7;
sbit SEG2=P2^0;
sbit SEG3=P2^1;
sbit SEG4=P2^2;
unsigned char i=0;
unsigned int cnt=0;
unsigned long sec=0;
unsigned char code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
unsigned char cache[4]={
0x3f,0x3f,0x3f,0x3f};
void main()
{
TMOD=1;
TH0=(65535-1000)/256;
TL0=(65535-1000)%256;
TR0=1;
while(1)
{
if(TF0=1)
{
TF0=0;
TH0=(65535-1000)/256;
TL0=(65535-1000)%256;
cnt++;
if(cnt==1000)
{
cnt=0;
sec++;
cache[0]=table[sec%10];
cache[1]=table[sec/10%10];
cache[2]=table[sec/100%10];
cache[3]=table[sec/1000%10];
}
if (i == 0)
{SEG1=1;SEG2=0;SEG3=0;SEG4=0; i++; P0=cache[0]; }
else if (i == 1)
{SEG1=0;SEG2=1;SEG3=0;SEG4=0; i++; P0=cache[1]; }
else if (i == 2)
{SEG1=0;SEG2=0;SEG3=1;SEG4=0; i++; P0=cache[2]; }
else if (i == 3)
{SEG1=0;SEG2=0;SEG3=0;SEG4=1; i=0; P0=cache[3]; }
}
}
}
开发板上数码管显示乱码。。。。
