这个简单程序有错木有 求解
时间:10-02
整理:3721RD
点击:
数字时钟
//******************************************
//******************************************
//******************************************
//**************电子时钟设计****************
/******************葛 刚******************/
/******************************************/
#include<reg51.h>
unsigned char counter;
unsigned char second;
unsigned char minute;
unsigned char hour;
sbit DUAN=P2^6;
sbit WELA=P2^7;
sbit FM=P2^3;
unsigned char code table[]=
{0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
0x76,0x79,0x38,0x3f,0};
/************延时函数********/
void Delay()
{
unsigned char i,j;
for(j=0;j<10;j++)
for(i=0;i<10;i++);
}
void displaysecond(unsigned int x)
{
WELA=1;
P0=0xfe;
WELA=0;
DUAN=1;
P0=table[x%10];
DUAN=0;
Delay();
WELA=1;
P0=0xfd;
WELA=0;
DUAN=1;
P0=table[x/10];
DUAN=0;
}
void displayminute(unsigned int y)
{
WELA=1;
P0=0xfc;
WELA=0;
DUAN=1;
P0=table[y%10];
DUAN=0;
Delay();
WELA=1;
P0=0xf7;
WELA=0;
DUAN=1;
P0=table[y/10];
DUAN=0;
}
void displayhour(unsigned int z)
{ DUAN=1;
P0=table[z%10];
DUAN=0;
WELA=1;
P0=0xef;
WELA=0;
Delay();
DUAN=1;
P0=table[z/10];
DUAN=0;
WELA=1;
P0=0xdf;
WELA=0;
}
void main(void)
{
counter=0;
second=0;
minute=0;
hour=0;//初始化
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=0;
ET0=1;
TR0=1;
while(1)
{
displaysecond(second);
displayminute(minute);
displayhour(hour);
}
}
/*************************************/
void timer0() interrupt 1 using 1
{
TR0=0;
counter++;
if(counter==20)
{
counter=0;
second++;
if(second==60)
{
second=0;
minute++;
if(minute==60)
{
minute=0;
hour++;
if(hour==24)
{
hour=0;
}
}
}
}
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
}
//******************************************
//******************************************
//******************************************
//**************电子时钟设计****************
/******************葛 刚******************/
/******************************************/
#include<reg51.h>
unsigned char counter;
unsigned char second;
unsigned char minute;
unsigned char hour;
sbit DUAN=P2^6;
sbit WELA=P2^7;
sbit FM=P2^3;
unsigned char code table[]=
{0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
0x76,0x79,0x38,0x3f,0};
/************延时函数********/
void Delay()
{
unsigned char i,j;
for(j=0;j<10;j++)
for(i=0;i<10;i++);
}
void displaysecond(unsigned int x)
{
WELA=1;
P0=0xfe;
WELA=0;
DUAN=1;
P0=table[x%10];
DUAN=0;
Delay();
WELA=1;
P0=0xfd;
WELA=0;
DUAN=1;
P0=table[x/10];
DUAN=0;
}
void displayminute(unsigned int y)
{
WELA=1;
P0=0xfc;
WELA=0;
DUAN=1;
P0=table[y%10];
DUAN=0;
Delay();
WELA=1;
P0=0xf7;
WELA=0;
DUAN=1;
P0=table[y/10];
DUAN=0;
}
void displayhour(unsigned int z)
{ DUAN=1;
P0=table[z%10];
DUAN=0;
WELA=1;
P0=0xef;
WELA=0;
Delay();
DUAN=1;
P0=table[z/10];
DUAN=0;
WELA=1;
P0=0xdf;
WELA=0;
}
void main(void)
{
counter=0;
second=0;
minute=0;
hour=0;//初始化
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=0;
ET0=1;
TR0=1;
while(1)
{
displaysecond(second);
displayminute(minute);
displayhour(hour);
}
}
/*************************************/
void timer0() interrupt 1 using 1
{
TR0=0;
counter++;
if(counter==20)
{
counter=0;
second++;
if(second==60)
{
second=0;
minute++;
if(minute==60)
{
minute=0;
hour++;
if(hour==24)
{
hour=0;
}
}
}
}
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
}
