基于单片机的 电子时钟设计 10分急~~~~~~~~~

设计要求
设计并制作一个电子时钟,该电子时钟具有实时时钟显示、时钟校正、设置闹钟等功能:
(1)可实时显示“年”、“月”、“日”、“时”、“分”、“秒”、“星期”,一分钟误差小于10秒;
(2)有校时及预置时间功能;
(3)可设置一组闹钟功能;
(4)具有整点报时功能。
符合要求的发个到我邮箱[email protected]谢谢 急~~~~~~~~~~
发个好的 给我谢谢

第1个回答  2010-05-24
郭天祥的十天学会单片机上有这东西,你自己找下。完整的程序。
第2个回答  2010-05-24
#include<reg52.h>
#include<absacc.h>
#include<intrins.h>
#define unit unsigned int
#define uchar unsigned char
//#define HZ 12
sbit key0=P0^0; // 分钟调整
sbit key1=P0^1; // 小时调整

sbit P2_0=P2^7; //秒 指示灯
sbit MN_RXD=P3^6;
sbit MN_TXD=P3^7;

uchar data CLOCK[4]={0,0,0,12};//存放时钟时间(百分秒,秒,分,和时位)

//数码管显示表0-f 灭
uchar code TABLE[]={0xBE,0x06,0xEA,0x6E,0x56,0x7C,0xFC,0x0E,0xFE,0x7E,0x00};
//**********************************
//模拟串口发送一个字节数据 函数
//**********************************
void SendData(unsigned char senddata)
{
unsigned char i;
for(i=0;i<8;i++)
{
if((senddata&0x01)==0)
MN_RXD=0;
else
MN_RXD=1;
_nop_();
MN_TXD=0;
_nop_();
MN_TXD=1;
senddata=senddata>>1;
}
}

//**********************************
//显示程序函数
//**********************************
void display(void)
{
// unsigned int n;
uchar temp;
temp=CLOCK[1]; temp=temp%10; SendData(TABLE[temp]);
temp=CLOCK[1]; temp=temp/10; SendData(TABLE[temp]);
temp=CLOCK[2]; temp=temp%10; SendData(TABLE[temp]);
temp=CLOCK[2]; temp=temp/10; SendData(TABLE[temp]);
temp=CLOCK[3]; temp=temp%10; SendData(TABLE[temp]);
temp=CLOCK[3]; temp=temp/10; SendData(TABLE[temp]);

/*
for(n=0;n<5000;n++);

for(n=0;n<6;n++)
{
SendData(TABLE[10]);
}
*/
}

//**********************************
//按键控制函数
//**********************************
void keycan()
{
unsigned int n;
EA=0;
if(key0==0) // 分钟调整
{
for(n=0;n<10000;n++); //延时去抖动
while(key0==0);
CLOCK[2]=CLOCK[2]+1;
if(CLOCK[2]==60) //到一时
{
CLOCK[2]=0;
}
display();

}
if(key1==0) // 小时调整
{
for(n=0;n<10000;n++); //延时去抖动
while(key1==0);
CLOCK[3]=CLOCK[3]+1;
if(CLOCK[3]==24)
{
CLOCK[3]=0;
}
display();

}
EA=1;
}

//**********************************
//T0中断服务函数
//**********************************
void time0() interrupt 1 //using 1
{
TH0=0xD8; TL0=0xF0; //重置初值
// TH0=0xB1; TL0=0xE0;
//时钟处理
CLOCK[0]=CLOCK[0]+1;

}
//**********************************
//主函数
//**********************************
void main()
{
EA=1;
ET0=1;
TMOD=0x01; //T0方式1定时
TH0=0xD8; TL0=0xF0; //D8F0 定时10ms
// TH0=0xB1; TL0=0xE0; //定时 20ms
TR0=1;
for(;;)
{
if(CLOCK[0]==100) //到一秒 10ms*100
{
CLOCK[0]=0;
P2_0=~P2_0;
CLOCK[1]=CLOCK[1]+1;
if(CLOCK[1]==60) //到一分
{
CLOCK[1]=0;
CLOCK[2]=CLOCK[2]+1;
if(CLOCK[2]==60) //到一时
{
CLOCK[2]=0;
CLOCK[3]=CLOCK[3]+1;
if(CLOCK[3]==24)
{
CLOCK[3]=0;
}
}
}
display();
}

keycan();
}

}本回答被提问者采纳