多功能时钟mian.c
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include "main.h"
uint temp; //温度值
void WriteStr(uchar *s)
{
while(*s)
{
write_12864_dat(*s);
s++;
delay_50us(1);
}
}
void display()
{ uchar i;
write_12864_com(0x80);
table1[0] = mun_to_char[time_data_buff[6]/0x10];
table1[1] = mun_to_char[time_data_buff[6]%0x10]; /*年*/
table1[4] = mun_to_char[time_data_buff[4]/0x10];
table1[5] = mun_to_char[time_data_buff[4]%0x10]; /*月*/
table1[8] = mun_to_char[time_data_buff[3]/0x10];
table1[9] = mun_to_char[time_data_buff[3]%0x10]; /*日*/
for(i=0;i<3;i++)
table1[i+13]=Weeks[time_data_buff[5]&0x07][i]; /*星期*/
for(i=0;i<16;i++)
{
write_12864_dat(table1[i]);
delay_50us(1);
}
table3[4] = mun_to_char[time_data_buff[2]/0x10];
table3[5] = mun_to_char[time_data_buff[2]%0x10]; /*时*/
table3[7] = mun_to_char[time_data_buff[1]/0x10];
table3[8] = mun_to_char[time_data_buff[1]%0x10]; /*分*/
table3[10] = mun_to_char[time_data_buff[0]/0x10];
table3[11] = mun_to_char[time_data_buff[0]%0x10]; /*秒*/
write_12864_com(0x88);
for(i=0;i<16;i++)
{
write_12864_dat(table3[i]);
delay_50us(1);
}
temp=ReadTemperature();
//------
table4[10] = mun_to_char[temp/100];
table4[11] = mun_to_char[temp%100/10];
table4[13] = mun_to_char[temp%10]; /*温度*/
write_12864_com(0x98);
for(i=0;i<16;i++)
{
write_12864_dat(table4[i]);
delay_50us(1);
}
}
void main()
{
uchar i,time_set,ck_set,dis=1;
duan=1;
P0=0x00;
duan=0;
lcd12864_init();
lcd_data_port = 0xff; /*释放P0端口*/
// led_latch_port = 0;`
//sled_latch_port = 0;
Set1302(time_data_buff); /*设置时间*/
while(1)
{
if(time_data_buff[1]>=0x60)
time_data_buff[1]=0x00;
if(time_data_buff[2]>=0x24)
time_data_buff[2]=0x00;
if(time_data_buff[3]>=0x32)
time_data_buff[3]=0x01;
if(time_data_buff[4]>=0x13)
time_data_buff[4]=0x01;
if(naoling_data_buff[0]>=0x24)
naoling_data_buff[0]=0x00;
if(naoling_data_buff[1]>=0x60)
naoling_data_buff[1]=0x00;
display();
key_val=Keyscan();
// if(key_val==0)
// Get1302(time_data_buff); /*读取当前时间*/
// temp=ReadTemperature(); /*读取当前温度值*/
if(key_val==1)
{
// key_flag=1; //设定时间
time_set=1;
ck_set=0;
while( Keyscan());
}
// if(key_val==2)
// {
// key_flag=1; //
// p++;
// while( Keyscan());
// }
// if(key_val==1&&key_flag==1)
if(key_val==4)
{
// key_flag=2; //设定闹铃
ck_set=1;
time_set=0;
while( Keyscan());
}
if(key_val==5) //确定键
{
p=0;
dis=1;
ck_set=0;
time_set=0;
Set1302(time_data_buff);
while( Keyscan());
//key_flag=0;
}
//if(key_flag==0)
//改时间
//if(key_flag==1)
if(time_set)
{
if(key_val==2)
p++;
if(p>12)
p=0;
if((naoling_data_buff[p/2+1]>>4)>9)
time_data_buff[p/2+1]&=0x0f;
if((time_data_buff[p/2+1]&0x0f)>9)
time_data_buff[p/2+1]&=0xf0;
if((key_val==3)&&((p%2)==0))
time_data_buff[p/2+1]=time_data_buff[p/2+1]+0x10;
if((key_val==3)&&((p%2)==1))
time_data_buff[p/2+1]=time_data_buff[p/2+1]+0x01;
while( Keyscan());
Set1302(time_data_buff);
}
else
Get1302(time_data_buff);
//改闹铃
// if(key_flag==2)
if(ck_set)
{
if(key_val==2)
p1++;
if(p1>3)
p1=0;
if((naoling_data_buff[p1/2]>>4)>9)
naoling_data_buff[p1/2]&=0x0f;
if((naoling_data_buff[p1/2]&0x0f)>9)
naoling_data_buff[p1/2]&=0xf0;
if((key_val==3)&&((p1%2)==0))
naoling_data_buff[p1/2]=naoling_data_buff[p1/2]+0x10;
if((key_val==3)&&((p1%2)==1))
naoling_data_buff[p1/2]=naoling_data_buff[p1/2]+0x01;
while( Keyscan());
}
//闹铃判决
/* if((key_val==6)&&(nl_flag==0))
{
nl_flag=1;
}
if((key_val==6)&&(nl_flag==1))
{
nl_flag=0;
} */
if(key_val==6)
{
nl_flag++;
nl_flag=nl_flag%2;
while( Keyscan());
}
if((naoling_data_buff[1]==time_data_buff[1])&&(naoling_data_buff[0]==time_data_buff[2]))
{
if(nl_flag)
{
fmq=1;
if(ck)
{
write_12864_com(0x90);
for(i=0;i<16;i++)
{
write_12864_dat(' ');
delay_50us(1);
}
write_12864_com(0x93);
WriteStr("起床了");
ck=0;
}
}
else
{
dis=1;
fmq=0;
ck=1;
}
}
else
{
fmq=0;
ck=1;
}
/*刷新显示*/
// if(key_flag==2)
if(ck_set)
{
table5[6] = mun_to_char[naoling_data_buff[0]/0x10];
table5[7] = mun_to_char[naoling_data_buff[0]%0x10]; /*时*/
table5[10] = mun_to_char[naoling_data_buff[1]/0x10];
table5[11] = mun_to_char[naoling_data_buff[1]%0x10]; /*分*/
write_12864_com(0x90);
for(i=0;i<16;i++)
{
write_12864_dat(table5[i]);
delay_50us(1);
}
}
else
{
if(dis)
{
write_12864_com(0x90);
for(i=0;i<16;i++)
{
write_12864_dat(table2[i]);
delay_50us(1);
}
dis=0;
}
}
}
}