最佳答案
僅供參考,不懂再問我,哈哈……
--------------------------------------------------------------
#include
#include
#include"clock.h"
#include"daima.h"
uchar t_hour=0x16;
uchar t_min=0x23;
uchar t_mon=0x07;
uchar t_day=0x09;
uchar t_year=0x11;
//flag1=0;
//引腳定義
sbit T_RST=P1^5;
sbit T_CLK=P1^3;
sbit T_IO=P1^4;
sbit ACC0=ACC^0;
sbit ACC7=ACC^7;
bit flag1=0;
uchar x=0x10,y=0x30; //鬧鐘初始化
uchar idata t_sec,sec1,sec2;
uchar idata mon1,mon2;
uchar idata min1,min2;
uchar idata hour1,hour2;
uchar idata day1,day2;
uchar idata year1,year2;
uchar week,week0;
uchar code week1[]="一";
uchar code week2[]="二";
uchar code week3[]={0xc8,0xfd}; //三的內碼失效,該代碼等效為“三”
uchar code week4[]="四";
uchar code week5[]="五";
uchar code week6[]="六";
uchar code week7[]="日";
/*******************************************
向1302寫一個字節
*******************************************/
void input_BYTE(uchar dat)
{
uchar i;
ACC=dat;
for(i=8;i>0;i--)
{
T_IO=ACC0;
T_CLK=1;
T_CLK=0;
ACC=(ACC>>1);
}
}
/*******************************************
1302讀出一個字節
*******************************************/
uchar output_BYTE()
{
uchar i;
for(i=8;i>0;i--)
{
ACC=(ACC>>1);
ACC7=T_IO;
T_CLK=1;
T_CLK=0;
}
return (ACC);
}
/*******************************************
寫數據
*******************************************/
void write_1302(uchar add,uchar dat)
{
T_RST=0;
T_CLK=0;
T_RST=1;
input_BYTE(add);
input_BYTE(dat);
T_CLK=1;
T_RST=0;
}
/*******************************************
讀數據
*******************************************/
uchar read_1302(uchar add)
{
uchar inf;
T_RST=0;
T_CLK=0;
T_RST=1;
input_BYTE(add);
inf=output_BYTE();
T_CLK=1;
T_RST=0;
return (inf);
}
/*******************************
將鬧鐘時間寫入1302寄存器中
*********************************/
/*void write_clock(uchar x,uchar y)
{
write_1302(0xc0,x); //寫鬧鐘的小時部分
write_1302(0xc2,y); //寫鬧鐘的分鐘部分
} */
/*******************************
將鬧鐘時間從1302寄存器中讀出來
*********************************/
/*uchar* read_clock()
{
uchar *temp;
temp[0]=read_1302(0xc1); //讀小時
temp[1]=read_1302(0xc3); //讀分
return temp;
} */
void init_1302()
{
write_1302(0x8e,0x00);//關閉寫保護;
write_1302(0x90,0xaa);//設置充電方式;
// write_1302(0xc0,x); //將鬧鐘的小時寫入1302
// write_1302(0xc2,y); //將鬧鐘的分鐘寫入1302
/* write_1302(0x80,0x00);//秒寄存器初始化;
write_1302(0x82,0x23);//分.......
write_1302(0x84,0x16);//時.......
write_1302(0x86,0x09);//日........
write_1302(0x88,0x07);//月.......
write_1302(0x8a,0x06);//星期...
write_1302(0x8c,0x11);//年......*/
write_1302(0x8e,0x80);//打開寫保護;
}
void show_1302_time(uchar line,uchar col)
{
uchar i=0;
uchar temp1[11];
t_sec=read_1302(0x81);//讀秒 ;
sec1=t_sec&0x0f;
sec2=(t_sec>>4);
t_min=read_1302(0x83);//讀分 ;
min1=t_min&0x0f;
min2=(t_min>>4);
t_hour=read_1302(0x85);//讀小時 ;
hour1=t_hour&0x0f;
hour2=(t_hour>>4);
temp1[0]=hour2+'0';
temp1[1]=hour1+'0';
temp1[2]=':';
temp1[3]=min2+'0';
temp1[4]=min1+'0';
temp1[5]=':';
temp1[6]=sec2+'0';
temp1[7]=sec1+'0';
temp1[8]='\0';
lcd_pos(line,col);
while(temp1[i]!='\0')
{
lcd_wdat(temp1[i]);
i++;
}
}
void show_1302_date(uchar line,uchar col)
{
uchar i=0;
uchar temp[12];
t_year=read_1302(0x8d);//讀年 ;
year1=t_year&0x0f;
year2=(t_year>>4);
t_mon=read_1302(0x89);//讀月 ;
mon1=t_mon&0x0f;
mon2=(t_mon>>4);
t_day=read_1302(0x87);//讀日;
day1=t_day&0x0f;
day2=(t_day>>4);
temp[0]='2';
temp[1]='0';
temp[2]=year2+'0';
temp[3]=year1+'0';
temp[4]='/';
temp[5]=mon2+'0';
temp[6]=mon1+'0';
temp[7]='/';
temp[8]=day2+'0';
temp[9]=day1+'0';
temp[10]='\0';
// temp[11]='\0';
lcd_pos(line,col);
while(temp[i]!='\0')
{
lcd_wdat(temp[i]);
i++;
}
}
void show_1302_week(uchar line,uchar col)
{
uchar i=0;
uchar temp1[]="星期";
lcd_pos(line,col);
/* week=read_1302(0x8b);//讀星期 ;
week0=week&0x0f; */
while(temp1[i]!='\0')
{
lcd_wdat(temp1[i]);
i++;
}
week=read_1302(0x8b);//讀星期 ;
week0=week&0x0f;
lcd_pos(line,col+2);
switch(week0)
{
case 1:
for(i=0;i<2;i++)
{
lcd_wdat(week1[i]);
}
break;
case 2:
for(i=0;i<2;i++)
{
lcd_wdat(week2[i]);
}
break;
case 3:
for(i=0;i<2;i++)
{
lcd_wdat(week3[i]);
}
break;
case 4:
for(i=0;i<2;i++)
{
lcd_wdat(week4[i]);
}
break;
case 5:
for(i=0;i<2;i++)
{
lcd_wdat(week5[i]);
}
break;
case 6:
for(i=0;i<2;i++)
{
lcd_wdat(week6[i]);
}
break;
case 7:
for(i=0;i<2;i++)
{
lcd_wdat(week7[i]);
}
break;
}
}
/*void beep()
{
uchar *naozhong;
// write_clock(hou,min);
naozhong=read_clock();
if(naozhong[0]==t_hour)
{
beeper=0;
}
else
{
beeper=1;
}
} */
void beep()
{
t_hour=read_1302(0x85);//讀小時 ;
t_min=read_1302(0x83);//讀分 ;
/* if((x==t_hour)&&(y==t_min))
{
beeper=0;
flag1=1;
} */
if((read_1302(0xc1)==t_hour)&&(read_1302(0xc3)==t_min))
{
beeper=0;
flag1=1;
}
else
{
beeper=1;
flag1=0;
}
}
/*void show_naozhong(uchar line,uchar col)
{
uchar temp[6],i=0;
uchar *temp1;
temp1=read_clock();
temp[0]=(temp1[0]>>4)+'0';
temp[1]=(temp1[0]&0x0f)+'0';
temp[2]=':';
temp[3]=(temp1[1]>>4)+'0';
temp[4]=(temp1[1]&0x0f)+'0';
temp[5]='\0';
lcd_pos(line,col);
while(temp[i]!='\0')
{
lcd_wdat(temp[i]);
i++;
}
} */
void show_naozhong(uchar line,uchar col)
{
uchar temp[6],i=0;
/* temp[0]=(x>>4)+'0';
temp[1]=(x&0x0f)+'0';
temp[2]=':';
temp[3]=(y>>4)+'0';
temp[4]=(y&0x0f)+'0';
temp[5]='\0';
lcd_pos(line,col);
while(temp[i]!='\0')
{
lcd_wdat(temp[i]);
i++;
} */
temp[0]=(read_1302(0xc1)>>4)+'0';
temp[1]=(read_1302(0xc1)&0x0f)+'0';
temp[2]=':';
temp[3]=(read_1302(0xc3)>>4)+'0';
temp[4]=(read_1302(0xc3)&0x0f)+'0';
temp[5]='\0';
lcd_pos(line,col);
while(temp[i]!='\0')
{
lcd_wdat(temp[i]);
i++;
}
}
回答者:sfdsag2016-04-28 00:00