/****************************************/
/* 带温度显示的电子日历 */
/****************************************/
#include<reg51.h>
#include<intrins.h>
#include<string.h>
#define uchar unsigned char
#define uint unsigned int
sbit DQ=P2^7;
sbit CS1=P2^1; //定义选择芯片左半屏信号
sbit CS2=P2^2; //定义选择芯片右半屏信号
sbit DI=P2^5; //定义选择显示类型
sbit RW=P2^4; //定义读写信号
sbit E=P2^3; //定义数据锁存信号
sbit IO=P1^0; //DS1302数据线
sbit CLK=P1^1; //DS1302时钟线
sbit RST=P1^2; //DS1302复位线
sbit s1=P3^0;
sbit s2=P3^1;
sbit s3=P3^2;
uchar Time_Buffer[7]; //日期缓存,0-6依次为秒、分、时、日、月、周日、年
uint Temp,Temp1;
bit Temp_Flag;
uchar s1num;
uchar flag_year=0,flag_moon=0,flag_day=0,flag_hour=0,flag_min=0,flag_sec=0,flag_week=0;
uchar tempa;
uchar t0_num;
void delayms(uint xms);
void Write_1302(uchar addr,uchar dat);
void keyscan();
void time_adj();
/*--年,月,日,星期,时,分,秒,汉字点阵(16*16)--*/
uchar code Date_Time_Words[]=
{
0x40,0x20,0x10,0x0C,0xE3,0x22,0x22,0x22,0xFE,0x22,0x22,0x22,0x22,0x02,0x00,0x00,//年
0x04,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x00,
0x00,0x00,0x00,0x00,0x00,0xFF,0x11,0x11,0x11,0x11,0x11,0xFF,0x00,0x00,0x00,0x00,//月
0x00,0x40,0x20,0x10,0x0C,0x03,0x01,0x01,0x01,0x21,0x41,0x3F,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,0x00,0x00,//日
0x00,0x00,0x00,0x3F,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xBE,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x2A,0x3E,0x00,0x00,0x00,//星
0x00,0x48,0x46,0x41,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x49,0x41,0x40,0x00,
0x00,0x04,0xFF,0x54,0x54,0x54,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x00,//期
0x42,0x22,0x1B,0x02,0x02,0x0A,0x33,0x62,0x18,0x07,0x02,0x22,0x42,0x3F,0x00,0x00,
0x00,0xFC,0x44,0x44,0x44,0xFC,0x10,0x90,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x00,//时
0x00,0x07,0x04,0x04,0x04,0x07,0x00,0x00,0x03,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,
0x80,0x40,0x20,0x98,0x87,0x82,0x80,0x80,0x83,0x84,0x98,0x30,0x60,0xC0,0x40,0x00,//分
0x00,0x80,0x40,0x20,0x10,0x0F,0x00,0x00,0x20,0x40,0x3F,0x00,0x00,0x00,0x00,0x00,
0x12,0x12,0xD2,0xFE,0x91,0x11,0xC0,0x38,0x10,0x00,0xFF,0x00,0x08,0x10,0x60,0x00,//秒
0x04,0x03,0x00,0xFF,0x00,0x83,0x80,0x40,0x40,0x20,0x23,0x10,0x08,0x04,0x03,0x00
} ;
//星期几的汉字点阵
uchar code Weekday_Words[]=
{
0x00,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,0x00,0x00,//日
0x00,0x00,0x00,0x3F,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x00,
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0x80,0x00,//一
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x06,0x04,0x00,0x00,0x00,//二
0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x18,0x10,0x00,
0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00,//三
0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
0x00,0xFE,0x02,0x02,0x02,0xFE,0x02,0x02,0xFE,0x02,0x02,0x02,0x02,0xFE,0x00,0x00,//四
0x00,0x7F,0x28,0x24,0x23,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x22,0x7F,0x00,0x00,
0x00,0x02,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0xC2,0x82,0x02,0x00,0x00,0x00,//五
0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x30,0x20,0x00,
0x10,0x10,0x10,0x10,0x10,0x91,0x12,0x1E,0x94,0x10,0x10,0x10,0x10,0x10,0x10,0x00,//六
0x00,0x40,0x20,0x10,0x0C,0x03,0x01,0x00,0x00,0x01,0x02,0x0C,0x78,0x30,0x00,0x00
};
//温度显示汉字点阵
uchar code Templt[]=
{
0x10,0x22,0x64,0x0C,0x80,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFF,0x02,0x00,0x00,//温
0x04,0x04,0xFE,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00,
0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0xA5,0xA6,0xA4,0xFC,0x24,0x34,0x26,0x04,0x00,//度
0x40,0x20,0x9F,0x80,0x42,0x42,0x26,0x2A,0x12,0x2A,0x26,0x42,0x40,0xC0,0x40,0x00,
0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//:
0x00,0x00,0x00,0x00,0x31,0x7B,0x7B,0x31,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x02,0x05,0xE2,0x18,0x04,0x02,0x02,0x02,0x02,0x02,0x02,0x04,0x1E,0x00,0x00,//℃
0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x40,0x40,0x40,0x40,0x40,0x20,0x18,0x00,0x00
};
//半角数字点阵
uchar code Digits[]=
{
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//.
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 //' '
};
/*--屏幕显示--*/
void left()//左半屏显示
{
CS1=1;
CS2=0;
}
void right()//右半屏显示
{
CS1=0;
CS2=1;
}
/*--判断LCD是否繁忙--*/
void LCD_Check_Busy()
{
do
{
E=0;
DI=0;
RW=1;
P0=0xff;
E=1;
_nop_();
E=0;
}
while(P0&0x80);//P0.7口
}
/*--向LCD发送命令--*/
void LCD_Write_Command(uchar c)
{
LCD_Check_Busy();
P0=0xFF ;
RW=0;
DI=0;
P0=c ;
E=1;
E=0;
}
/*--向LCD发送数据--*/
void LCD_Write_Date(uchar d)
{
LCD_Check_Busy();
P0=0xFF ;
RW=0;
DI=1;
E=1;
_nop_();
P0=d ;
E=0;
_nop_();
}
/*--设置初始页--*/
void page_first(uchar p)
{
uchar i=p;
p=i|0xb8;
LCD_Check_Busy();
LCD_Write_Command(p);
}
/*--设置初始列--*/
void col_first(uchar c)
{
uchar i=c;
c=i|0x40;
LCD_Check_Busy();
LCD_Write_Command(c);
}
/*--任意位置显示汉字--*/
void Display_Word(uchar page,uchar col,uchar*s)
{
uchar i,j;
page_first(page);//上半部
col_first(col);
for(i=0;i<16;i++)
{
LCD_Write_Date(*s);
s++;
}
page_first(page+1);//下半部
col_first(col);
for(j=0;j<16;j++)
{
LCD_Write_Date(*s);
s++;
}
}
/*--任意位置显示字符--*/
void Display_Char(uchar page,uchar col,uchar*s)
{
uchar i,j;
page_first(page);//上半部
col_first(col);
for(i=0;i<8;i++)
{
LCD_Write_Date(*s);
s++;
}
page_first(page+1);//下半部
col_first(col);
for(j=0;j<8;j++)
{
LCD_Write_Date(*s);
s++;
}
}
/*--初始化LCD --*/
void LCD_initialize()
{
CS1=1;
CS2=1;
LCD_Write_Command(0x38); //8位形式,2行字符
LCD_Write_Command(0x0F); //开显示
LCD_Write_Command(0x01); //清屏
LCD_Write_Command(0x06); //画面不动光标右移
LCD_Write_Command(0xC0);//设置起始行
}
/*--向DS1302写入一字节--*/
void Write_A_Byte_To_1302(uchar x)
{
uchar i;
for(i=0;i<8;i++)
{
IO=x&0x01; CLK=1;CLK=0;x>>=1;
}
}
/*--从DS1302读取一字节--*/
uchar Receive_A_Byte_From_1302()
{
uchar i,b=0x00;
for(i=0;i<8;i++)
{
b |= _crol_((uchar)IO,i);
CLK=1;CLK=0;
}
return b/16*10+b%16;
}
/*--从DS1302指定位置读数据--*/
uchar Read_1302(uchar addr)
{
uchar dat;
RST = 0;CLK=0;RST=1;
Write_A_Byte_To_1302(addr);
dat = Receive_A_Byte_From_1302();
CLK=1;RST=0;
return dat;
}
/*--向DS1302某地址写入数据--*/
void Write_1302(uchar addr,uchar dat)
{
CLK=0; RST=0;
Write_A_Byte_To_1302(addr);
Write_A_Byte_To_1302(dat);
CLK=0;RST=0;
}
/*--读取当前日期时间--*/
void Get_Time()
{
uchar i;
for(i=0;i<7;i++)
{
Time_Buffer[i]=Read_1302(0x81+2*i);
}
}
/*--定时器0每秒刷新LCD显示--*/
void T0_INT() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t0_num++;
left();//显示左半屏
if(flag_year==0)
{
Display_Char(0,16,Digits+ Time_Buffer [6]/10*16);//显示年的十位数,占8列
Display_Char(0,24,Digits+ Time_Buffer [6]%10*16); //显示年的个位数,占8列
}
else
{
if(t0_num<=5)
{
Display_Char(0,16,Digits+ Time_Buffer [6]/10*16);//显示年的十位数,占8列
Display_Char(0,24,Digits+ Time_Buffer [6]%10*16); //显示年的个位数,占8列
}
if(t0_num>5&&t0_num<=10)
{
if(t0_num==10)t0_num=0;
Display_Char(0,16,Digits+ Digits[11]/10*16);//显示年的十位数,占8列
Display_Char(0,24,Digits+ Digits[11]%10*16); //显示年的个位数,占8列
}
}
Display_Char(0,48,Digits+ Time_Buffer [4]/10*16); //显示月的十位数,占8列
Display_Char(0,56,Digits+ Time_Buffer [4]%10*16); //显示月的个位数,占8列
right();//显示右半屏
Display_Char(0,80,Digits+ Time_Buffer [3]/10*16); //显示日的十位数,占8列
Display_Char(0,88,Digits+ Time_Buffer [3]%10*16); //显示日的个位数,占8列
left();//显示左半屏
Display_Char(2,16,Digits+ Time_Buffer [2]/10*16); //显示时的十位数,占8列
Display_Char(2,24,Digits+ Time_Buffer [2]%10*16); //显示时的个位数,占8列
left();//显示左半屏
Display_Char(2,48,Digits+ Time_Buffer [1]/10*16); //显示分的十位数,占8列
Display_Char(2,56,Digits+ Time_Buffer [1]%10*16); //显示分的个位数,占8列
right();//显示右半屏,秒显示在右半屏部分
Display_Char(2,80,Digits+ Time_Buffer [0]/10*16); //显示秒的十位数,占8列
Display_Char(2,88,Digits+ Time_Buffer [0]%10*16); //显示秒的个位数,占8列
right();//显示右半屏
Display_Word(4,64,Weekday_Words+( Time_Buffer [5]-1)*32);//显示周日,占16列
left();//显示左半屏,温度
Display_Char(6,48,Digits+ Temp1/100*16); //显示温度十位数,占8列
Display_Char(6,56,Digits+ Temp1%100/10*16); //显示温度个位数,占8列
right();//显示右半屏
Display_Char(6,64,Digits+ 10*16); //显示温度小数点,占8列
Display_Char(6,72,Digits+ Temp%10*16); //显示温度十分位数,占8列
}
/*--定时器0初始化程序--*/
void Time0_initialize()
{
EA=1;//开总中断
ET0=1;//开定时/计数器0中断
TMOD=0x01;//设置工作方式1
TH0=(65536-50000)/256;//放入计数初值
TL0=(65536-50000)%256;//放入计数初值
TR0=1;//开定时/计数器0
}
/*--显示固定汉字:年月日 ,星期,时分秒*/
void Display()
{
left();//左半屏显示
Display_Char(0,0,Digits+2*16);//显示2
Display_Char(0,8,Digits);//显示0
/*--显示固定汉字:年月日 ,星期,时分秒*/
Display_Word(0,32,Date_Time_Words+0*32); //"年"字的显示
right();//右半屏显示
Display_Word(0,64,Date_Time_Words+1*32); //"月"字的显示
Display_Word(0,96,Date_Time_Words+2*32); //"日"字的显示
left();//左半屏显示
Display_Word(2,32,Date_Time_Words+5*32); //"时"字的显示
right();//右半屏显示
Display_Word(2,64,Date_Time_Words+6*32); //"分"字的显示
Display_Word(2,96,Date_Time_Words+7*32); //"秒"字的显示,秒显示在右半屏
left();//左半屏显示
Display_Word(4,32,Date_Time_Words+3*32); //"星"字的显示
Display_Word(4,48,Date_Time_Words+4*32); //"期"字的显示
left();//左半屏显示
Display_Word(6,0,Templt+0*32); //"温"字的显示
Display_Word(6,16,Templt+1*32); //"度"字的显示
Display_Word(6,32,Templt+2*32); //":"字的显示
right();//右半屏显示
Display_Word(6,80,Templt+3*32); //"℃"字的显示
}
void delayms(uint xms)
{
uint y;
while(xms--)for(y=110;y>0;y--);
}
//us级延时函数
void Delayus(uchar xus)//晶振为12MHz,延时时间为2i+5 us
{
while(--xus);
}
//初始化DS18B20函数
bit Init_DS18B20(void)
{
bit x;
DQ=1;
DQ=0;
Delayus(250);
DQ=1;
Delayus(20);
if(!DQ) x=0;
else x=1;
Delayus(250);
DQ=1;
return x;
}
//读DS18B20函数
uchar Read_DS18B20(void)
{
uchar i=0,Dat=0;
for(i=0;i<8;i++)
{
DQ=1;
DQ=0;
Dat>>=1;
DQ=1;
if(DQ) Dat |= 0x80;
DQ=1;
Delayus(30);
}
return Dat;
}
//写DS18B20函数
void Write_DS18B20(uchar Dat)
{
uchar i=0;
for(i=0;i<8;i++)//循环8次,写入一个字节
{
DQ=1;//未发送前的状态
Dat >>= 1;//将要传送的最低位放入CY
DQ=0;//将总线拉低,产生写时序
DQ=CY;//将要传送的位状态送到总线上
Delayus(30);//延时50us,即保持总线状态,待DS18B20采样
DQ=1;//恢复期,总线置1
}
}
//取温度函数
void GetTemp(void)//获取温度函数
{
uchar a=0,b=0;
TR0=0;//关闭定时器,防止定时器中断干扰DS18B20
Init_DS18B20();
Write_DS18B20(0xcc);//跳过ROM
Write_DS18B20(0x44);//开启温度转换
Init_DS18B20();
Write_DS18B20(0xcc);//跳过ROM
Write_DS18B20(0xbe);//读暂存器
a=Read_DS18B20();//读取高速暂存字节0,温度低8位
b=Read_DS18B20();//读取高速暂存字节1,温度高8位
TR0=1;//完成DS18B20读取后打开定时器
Temp=b;
Temp<<=8;
Temp=Temp|a;//将高、低位温度编码合在一起
if(b>=8)//判断温度值是否为负,如果温度高字节大于等于8说明温度值为负
{
Temp=~Temp+1;//将补码转换成原码
Temp_Flag=1;//温度标志为1,表示温度为负
}
else
{
Temp_Flag=0;//温度标志为0,表示温度为正
}
Temp1=Temp*0.0625*10;//将温度编码转换成温度值 放大10倍 加0.5是为了四舍五入
TR0=1;
}
void keyscan() //键盘扫描函数
{
if(s1==0)
{
delayms(5);
if(s1==0)
{
while(!s1);
s1num++;
if(s1num==1)
{
flag_year=1;
//write_1602com(er+0x09); //设置按键按动一次,秒位置显示光标
//write_1602com(0x0f); //设置光标为闪烁
tempa=(Time_Buffer[6])/10*16+(Time_Buffer[6])%10;//年数据写入DS1302
Write_1302(0x8e,0x00);
Write_1302(0x8c,tempa);//改写年
Write_1302(0x8e,0x80);
}
if(s1num==2)
{
flag_moon=1;
//write_1602com(er+0x09); //设置按键按动一次,秒位置显示光标
//write_1602com(0x0f); //设置光标为闪烁
tempa=(Time_Buffer[4])/10*16+(Time_Buffer[4])%10;//秒数据写入DS1302
Write_1302(0x8e,0x00);
Write_1302(0x88,tempa);//改写月
Write_1302(0x8e,0x80);
}
if(s1num==3)
{
flag_day=1;
//write_1602com(er+0x09); //设置按键按动一次,秒位置显示光标
//write_1602com(0x0f); //设置光标为闪烁
tempa=(Time_Buffer[3])/10*16+(Time_Buffer[3])%10;//秒数据写入DS1302
Write_1302(0x8e,0x00);
Write_1302(0x86,tempa);//改写日
Write_1302(0x8e,0x80);
}
if(s1num==4)
{
flag_hour=1;
//write_1602com(er+0x09); //设置按键按动一次,秒位置显示光标
//write_1602com(0x0f); //设置光标为闪烁
tempa=(Time_Buffer[2])/10*16+(Time_Buffer[2])%10;//秒数据写入DS1302
Write_1302(0x8e,0x00);
Write_1302(0x84,tempa);//改写时
Write_1302(0x8e,0x80);
}
if(s1num==5)
{
flag_min=1;
//write_1602com(er+0x09); //设置按键按动一次,秒位置显示光标
//write_1602com(0x0f); //设置光标为闪烁
tempa=(Time_Buffer[1])/10*16+(Time_Buffer[1])%10;//秒数据写入DS1302
Write_1302(0x8e,0x00);
Write_1302(0x82,tempa);//改写分
Write_1302(0x8e,0x80);
}
if(s1num==6)
{
flag_sec=1;
//write_1602com(er+0x09); //设置按键按动一次,秒位置显示光标
//write_1602com(0x0f); //设置光标为闪烁
tempa=(Time_Buffer[0])/10*16+(Time_Buffer[0])%10;//秒数据写入DS1302
Write_1302(0x8e,0x00);
Write_1302(0x80,0x80|tempa);//改写秒
Write_1302(0x8e,0x80);
}
if(s1num==7)
{
flag_week=1;
//write_1602com(er+0x09); //设置按键按动一次,秒位置显示光标
//write_1602com(0x0f); //设置光标为闪烁
tempa=(Time_Buffer[5])/10*16+(Time_Buffer[5])%10;//秒数据写入DS1302
Write_1302(0x8e,0x00);
Write_1302(0x8a,tempa);//改写星期
Write_1302(0x8e,0x80);
}
if(s1num==8)
{
s1num=0;
flag_year=0;
flag_moon=0;
flag_day=0;
flag_hour=0;
flag_min=0;
flag_sec=0;
flag_week=0;
tempa=(Time_Buffer[0])/10*16+(Time_Buffer[0])%10;//秒数据写入DS1302
Write_1302(0x8e,0x00);
Write_1302(0x80,0x7f&tempa);//改写秒
Write_1302(0x8e,0x80);
}
}
}
}
void time_adj() //走时时间调整函数
{
if(s1num!=0)
{
tempa=(Time_Buffer[0])/10*16+(Time_Buffer[0])%10;
Write_1302(0x8e,0x00);
Write_1302(0x80,0x80|tempa);//改写秒
Write_1302(0x8e,0x80);
if(s2==0)
{
delayms(5);
if(s2==0)
{
while(!s2);
switch(s1num)
{
case 1:
Time_Buffer[6]++;
if(Time_Buffer[6]==100)
Time_Buffer[6]=0;
tempa=(Time_Buffer[6])/10*16+(Time_Buffer[6])%10;
Write_1302(0x8e,0x00);
Write_1302(0x8c,tempa);//改写年
Write_1302(0x8e,0x80);
break;
case 2:
Time_Buffer[4]++;
if(Time_Buffer[4]==13)
Time_Buffer[4]=0;
tempa=(Time_Buffer[4])/10*16+(Time_Buffer[4])%10;
Write_1302(0x8e,0x00);
Write_1302(0x88,tempa);//改写月
Write_1302(0x8e,0x80);
break;
case 3:
Time_Buffer[3]++;
if(Time_Buffer[3]==30)
Time_Buffer[3]=0;
tempa=(Time_Buffer[3])/10*16+(Time_Buffer[3])%10;
Write_1302(0x8e,0x00);
Write_1302(0x86,tempa);//改写日
Write_1302(0x8e,0x80);
break;
case 4:
Time_Buffer[2]++;
if(Time_Buffer[2]==24)
Time_Buffer[2]=0;
tempa=(Time_Buffer[2])/10*16+(Time_Buffer[2])%10;
Write_1302(0x8e,0x00);
Write_1302(0x84,tempa);//改写时
Write_1302(0x8e,0x80);
break;
case 5:
Time_Buffer[1]++;
if(Time_Buffer[1]==60)
Time_Buffer[1]=0;
tempa=(Time_Buffer[1])/10*16+(Time_Buffer[1])%10;
Write_1302(0x8e,0x00);
Write_1302(0x82,tempa);//改写分
Write_1302(0x8e,0x80);
break;
case 6:
Time_Buffer[0]++;
if(Time_Buffer[0]==60)
Time_Buffer[0]=0;
tempa=(Time_Buffer[0])/10*16+(Time_Buffer[0])%10;
Write_1302(0x8e,0x00);
Write_1302(0x80,0x80|tempa);//改写秒
Write_1302(0x8e,0x80);
break;
case 7:
Time_Buffer[5]++;
if(Time_Buffer[5]==8)
Time_Buffer[5]=1;
tempa=(Time_Buffer[5])/10*16+(Time_Buffer[5])%10;//秒数据写入DS1302
Write_1302(0x8e,0x00);
Write_1302(0x8a,tempa);//改写星期
Write_1302(0x8e,0x80);
break;
}
}
}
if(s3==0)
{
delayms(5);
if(s3==0)
{
while(!s3);
switch(s1num)
{
case 1:
Time_Buffer[6]--;
if(Time_Buffer[6]==0)
Time_Buffer[6]=99;
break;
case 2:
Time_Buffer[4]--;
if(Time_Buffer[4]==0)
Time_Buffer[4]=12;
break;
case 3:
Time_Buffer[3]++;
if(Time_Buffer[3]==0)
Time_Buffer[3]=30;
break;
case 4:
Time_Buffer[2]--;
if(Time_Buffer[2]==0)
Time_Buffer[2]=23;
break;
case 5:
Time_Buffer[1]--;
if(Time_Buffer[1]==0)
Time_Buffer[1]=59;
break;
case 6:
Time_Buffer[0]--;
if(Time_Buffer[0]==0)
Time_Buffer[0]=59;
break;
case 7:
Time_Buffer[5]--;
if(Time_Buffer[5]==0)
Time_Buffer[5]=7;
break;
}
}
}
}
}
/*--主程序--*/
void main()
{
LCD_initialize(); //LCD初始化
Display(); //固定显示的汉字
Time0_initialize(); //中断初始化,在中断中显示刷新的时间
while(1)
{
Get_Time(); //读取并刷新时间
GetTemp();
keyscan();
time_adj();
delayms(300);
}
} |