📄 main.c
字号:
#include <reg51.h>
/*************************宏定义******************************/
#define uchar unsigned char
#define uint unsigned int
#define debug
/*************************函数定义******************************/
extern void Initial_DS1302();
extern void LCD_Initial();
extern int ReadTemperature();
extern void DS1302_GetTime(char *time);
extern void GotoXY(uchar x, uchar y);
extern void Print(uchar *str);
void timeTOascII(char i,char *line);
void Delay1ms(uint count);
/*************************数组******************************/
uchar data line[17]; //年,月,日,周,的ASCII码(十位,个位)
//uchar ASCII_TIME[9]; //时,分,秒的的ASCII码(十位,个位)
uchar data time[7]; //秒,分,时,周,日,月,年
/*******************Delay1ms()*******************/
void Delay1ms(unsigned int count)
{
unsigned int i,j;
for(i=0;i<count;i++)
for(j=0;j<120;j++);
}
void delay(unsigned int i)
{
while(i-->0);
}
/*******************timeTOascII()*******************/
void timeTOascII(char i,char *line)
{
if(i==0)
{
int tmp;
tmp=ReadTemperature();
line[0]=time[6]/10+'0';
line[1]=time[6]%10+'0';
line[2]='/';
line[3]=time[5]/10+'0';
line[4]=time[5]%10+'0';
line[5]='/';
line[6]=time[3]/10+'0';
line[7]=time[3]%10+'0';
line[8]='[';
line[9]=time[4]%10+'0';
line[10]=']';
line[11]=tmp/1000+'0';
line[12]=(tmp%1000)/100+'0';
line[13]=(tmp%100)/10+'0';
line[14]=0xdf;
line[15]='C';
line[16]='\0';
if(tmp==9999)
{
line[11]='E';
line[12]='R';
line[13]='R';
}
}
if(i==1)
{
line[0]=time[2]/10+'0';
line[1]=time[2]%10+'0';
line[2]=':';
line[3]=time[1]/10+'0';
line[4]=time[1]%10+'0';
line[5]=':';
line[6]=time[0]/10+'0';
line[7]=time[0]%10+'0';
line[8]=0x20;
line[9]='P';
line[10]='H';
line[11]='I';
line[12]='L';
line[13]='I';
line[14]='P';
line[15]='S';
line[16]='\0';
}
if((i!=1)&&(i!=0))
{
line[0]='E';
line[1]='R';
line[2]='R';
line[3]='O';
line[4]='R';
line[5]='\0';
}
}
/*******************main()*******************/
main()
{
Initial_DS1302();
LCD_Initial();
while(1)
{
DS1302_GetTime(time);
#ifdef debug
timeTOascII(0,line);
GotoXY(0,0);
#endif
Print(line);
timeTOascII(1,line);
GotoXY(0,1);
Print(line);
Delay1ms(100);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -