P0=dispcode[(sec/10)%10]; /*秒十位 */
delay(1);
LED3=0;
LED1=1;
LED2=1;
LED4=1;
P0=dispcode[min%10]; /*分个位 */
delay(1);
LED4=0;
LED1=1;
LED2=1;
LED3=1;
P0=dispcode[(min/10)%10]; /*分十位 */
delay(1);
}
/*DS1302初始化函数*/
void ds1302_init()
{
ds1302_clk=0;
ds1302_rst=0;
ds1302_rst=1; /*使能DS1302*/
EnableWP(); /*允许写DS1302*/
ds1302_rst=0; /*复位*/
}
void main() /*主程序*/
{
uchar data buffer1[32]=
{32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,
52,53,54,55,56,57,58,59,60,61,62,63};
uchar data buffer2[8]={45,45,15,13,3,4,01,13};
WriteSec(0);
P0=0x00;
P1=0x07;
delay(100);
delay(100);
ds1302_init();
ReadRTC(buffer2,8);
DisableWP(); /*禁止写保护*/
WriteControl(0xaa); /*向慢速充电控制寄存器写入控制字节*/
WriteRam(buffer1,31); /*写DS1302RAM*/
WriteRTC(buffer2,8); /*写DS1302时钟*/
EnableWP(); /*允许写保护*/
ReadRam(buffer1,31); /*读DS1302RAM*/
ReadRTC(buffer2,8); /*读DS1302时钟*/
sec=ReadSec(); /*读秒*/
min=ReadMin(); /*读分*/
hr=ReadHr(); /*读时*/
day=ReadDay(); /*读日*/
month=ReadMonth(); /*读月*/
week=ReadWeek(); /*读星期*/
year=ReadYear(); /*读年*/
ACC=0;
WDTRST=0x1E;
WDTRST=0xE1; /*初始化看门狗*/
while (1)
{ led();
WDTRST=0x1E;
WDTRST=0xE1; /*喂狗指令*/
}
} |