#include"DS12C887.h"
#include<intrins.h>
#define miaogeAD 0x07
#define miaoshiAD 0x06
#define fengeAD 0x04
#define fenshiAD 0x03
#define hourgeAD 0x01
#define hourshiAD 0x00
#define dateAD 0x88+2
#define weekAD 0x8f
#define monthAD 0x88
volatile unsigned char SecondOld=70,MinuteOld=70,HourOld=25,DateOld=32,WeekOld=8,MonthOld=13;
extern volatile bit Z_flag;
void WriteData(unsigned char Address,Data)
{
CS=0;
AS=1;
DS=1;
rw=1;
// _nop_();
// _nop_();
// AS=1;
// _nop_();
// _nop_();
// _nop_();
// CS=0;
// AS=0;
DataPort=Address;
// _nop_();
// _nop_();
// _nop_();
AS=0;
rw=0;
DataPort=Data;
// _nop_();
// _nop_();
// _nop_();
rw=1;
// _nop_();
AS=1; CS=1;
}
unsigned char ReadData(unsigned char Address)
{
unsigned char ReadDat;
AS=1;
DS=1;
// rw=0;
// DS=1;
rw=1;
// _nop_();
// _nop_();
// AS=1;
// _nop_();
// _nop_();
// _nop_();
CS=0;
// AS=0;
DataPort=Address;
// _nop_();
// _nop_();
// _nop_();
AS=0;
DS=0;
// _nop_();
// _nop_();
// _nop_();
DataPort=0xff;
ReadDat=DataPort;
DS=1;
// _nop_();
AS=1;
CS=1;
return ReadDat;
}
void set_time()
{
WriteData(0,0);
WriteData(1,0);
WriteData(2,49);//写分钟
WriteData(3,0); //闹钟分
WriteData(4,2);//写小时
WriteData(5,0); //闹钟小时
WriteData(6,1); //写星期
WriteData(7,30); //写日
WriteData(8,9); //写月
WriteData(9,13);
}
void DS12C887_init()
{
WriteData(0x0a,0x20);
delayms(50);
WriteData(0x0b,0x26);
set_time();
}
void ReadMonth()
{
volatile unsigned char Month,monthge,monthshi;
Month=ReadData(0x08);
if(MonthOld!=Month)
{
monthshi=Month/10;
monthge=Month%10;
init_12864();
write_LCD_command(monthAD);
delayms(1);
write_LCD_data(monthshi+48);
write_LCD_data(monthge+48);
MonthOld=Month;
}
}
void ReadWeek()
{
volatile unsigned char Week,temp;
volatile unsigned char code week[]={"一二叁四五六日"};
Week=ReadData(0x06);
if(WeekOld!=Week)
{
temp=(Week-1)<<1;
init_12864();
write_LCD_command(weekAD);
write_LCD_data(*(week+temp));
write_LCD_data(*(week+temp+1));
WeekOld=Week;
}
}
void ReadDate()
{
volatile unsigned char Date,datege,dateshi;
Date=ReadData(0x07);
if(DateOld!=Date)
{
dateshi=Date/10;
datege=Date%10;
init_12864();
write_LCD_command(dateAD);
delayms(1);
write_LCD_data(dateshi+48);
write_LCD_data(datege+48);
DateOld=Date;
}
ReadWeek();
ReadMonth();
}
void ReadHour()
{
volatile unsigned char Hour,hourge,hourshi;
unsigned char code sun[]={
0x04,0x20,0x42,0x42,0x20,0x04,0x03,0xC0,0x0F,0xF0,0x8F,0xF1,0x5F,0xFA,0x1F,0xF8,
0x1F,0xF8,0x5F,0xFA,0x8F,0xF1,0x0F,0xF0,0x03,0xC0,0x20,0x04,0x42,0x42,0x04,0x20};
unsigned char code mon[]={
0x00,0x10,0x00,0x08,0x00,0x0C,0x00,0x0E,0x00,0x0E,0x00,0x1F,0x00,0x1F,0x00,0x3F,
0x00,0x3F,0x00,0x7F,0x01,0xFF,0x87,0xFE,0x7F,0xFE,0x3F,0xFC,0x1F,0xF8,0x07,0xE0};
unsigned char code sleep[]={
0x1E,0x10,0x04,0x08,0x08,0x0C,0x10,0x0E,0x3C,0x0E,0x00,0x1F,0x0E,0x1F,0x04,0x3F,
0x08,0x3F,0x1C,0x7F,0x00,0xFF,0x03,0xFE,0x5F,0xFE,0x3F,0xFC,0x1F,0xF8,0x07,0xE0};
Hour=ReadData(0x04);
if(HourOld!=Hour)
{
hourshi=Hour/10;
hourge=Hour%10;
init_BMP();
Display(hourge,hourgeAD);
Display(hourshi,hourshiAD);
HourOld=Hour;
if((Hour>=7)&&(Hour<=17))
{
init_BMP();
display_BMP1(sun,4);
}
if((Hour>=18)&&(Hour<=21))
{
init_BMP();
display_BMP1(mon,4);
}
if((Hour>=22)||(Hour<=6))
{
init_BMP();
display_BMP1(sleep,4);
}
}
ReadDate();
}
void ReadMinute()
{
volatile unsigned char Minute,fenge,fenshi;
Minute=ReadData(0x02);
if(MinuteOld!=Minute)
{
fenshi=Minute/10;
fenge=Minute%10;
init_BMP();
Display(fenge,fengeAD);
Display(fenshi,fenshiAD);
MinuteOld=Minute;
DisplayTemperture();
}
ReadHour();
}
void ReadSecond()
{
unsigned char Second,miaoge,miaoshi,Hour,NUMBER=0;
Second=ReadData(0x00);
if(SecondOld!=Second)
{
miaoshi=Second/10;
miaoge=Second%10;
init_BMP();
Display(miaoge,miaogeAD);
Display(miaoshi,miaoshiAD);
SecondOld=Second;
Z_flag=~Z_flag;
Hour=ReadData(0x04);
if((Hour>=6)&&(Hour<=7))
{
NUMBER=1;
}
if((Hour>=11)&&(Hour<=13))
{
NUMBER=1;
}
if((Hour>=22)||(Hour<=1))
{
NUMBER=1;
}
switch(NUMBER)
{
case 0:
if(Z_flag==0)
{
JiariScan();
}
else
{
init_12864();
LCD_ShowBuf(3,0,"蛇年大吉");
}
break;
case 1:
if(Z_flag==0)
{
eepromscan();
}
else
{
init_12864();
LCD_ShowBuf(3,0,"好好学习");
}
break;
}
ReadMinute();
}
}
/*void ReadHour1()
{
unsigned char Hour,hourge,hourshi;
Hour=ReadData(0x04);
if(HourOld!=Hour)
{
hourshi=Hour/10;
hourge=Hour%10;
init_BMP();
Display(hourge,hourgeAD);
Display(hourshi,hourshiAD);
HourOld=Hour;
ReadDate();
}}
void ReadMinute1()
{
unsigned char Minute,fenge,fenshi;
Minute=ReadData(0x02);
{
fenshi=Minute/10;
fenge=Minute%10;
init_BMP();
Display(fenge,fengeAD);
Display(fenshi,fenshiAD);
}
} */
void ReadSecond1(unsigned char LedAddress,unsigned char AddressFlag)
{
unsigned char Second,miaoge,miaoshi;
volatile bit flag;
volatile unsigned char code fanbai[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
Second=ReadData(0x00);
if(SecondOld!=Second)
{
miaoshi=Second/10;
miaoge=Second%10;
init_BMP();
Display(miaoge,miaogeAD);
Display(miaoshi,miaoshiAD);
SecondOld=Second;
flag=~flag;
if(flag==1)
{
switch(AddressFlag)
{
case 0:
init_BMP();
display_BMP(fanbai,LedAddress);
display_BMP(fanbai,LedAddress+1);
break;
case 1:
init_12864();
LCD_ShowBuf(2,LedAddress," ");
break;
}
}
else
{
volatile unsigned char Minute,fenge,fenshi,Hour,hourshi,hourge,Week,temp,Date,datege,dateshi,Month,monthge,monthshi;
volatile unsigned char code week[]={"一二叁四五六日"};
Minute=ReadData(0x02);
fenshi=Minute/10;
fenge=Minute%10;
init_BMP();
Display(fenge,fengeAD);
Display(fenshi,fenshiAD);
Hour=ReadData(0x04);
hourshi=Hour/10;
hourge=Hour%10;
init_BMP();
Display(hourge,hourgeAD);
Display(hourshi,hourshiAD);
Week=ReadData(0x06);
temp=(Week-1)<<1;
init_12864();
write_LCD_command(weekAD);
write_LCD_data(*(week+temp));
write_LCD_data(*(week+temp+1));
Date=ReadData(0x07);
dateshi=Date/10;
datege=Date%10;
init_12864();
write_LCD_command(dateAD);
delayms(1);
write_LCD_data(dateshi+48);
write_LCD_data(datege+48);
Month=ReadData(0x08);
monthshi=Month/10;
monthge=Month%10;
init_12864();
write_LCD_command(monthAD);
delayms(1);
write_LCD_data(monthshi+48);
write_LCD_data(monthge+48);
}
}
}
void eepromscan()
{
// volatile unsigned char code course[]={"自磁通毛控信微概"};
volatile unsigned char i,DayTemp[3],CourseTemp[10],Clock_MonthTemp,Clock_DateTemp,Clock_WeekTemp,Clock_HourTemp,Eeprom_WeekTemp;
volatile unsigned int DateCount=0,CourseCount=0;
DateCount=0;
CourseCount=0;
Clock_MonthTemp=ReadData(0x08); //读时钟月
//
Clock_DateTemp=ReadData(0x07); //读时钟日
//
Clock_WeekTemp=ReadData(0x06); //读时钟星期
//
Clock_HourTemp=ReadData(0x04); //读时钟小时
//
while