📄 lcd.txt
字号:
extern char DailNum[8];
extern unsigned short SYS_Flag[20];
volatile unsigned int sec_tick;
volatile int TickTime_sec;
volatile int TickTime_min;
volatile int TickTime_hour;
int year_b = 99; //设置初始值是为了避免上电显示不更新的状况出现
int month_b = 99;
int day_b = 99;
int weekday_b = 99;
int hour_b = 99;
int min_b = 99;
int sec_b = 99;
char *date[8] = {"","一","二","三","四","五","六","日"};
//int year_b,month_b,day_b,weekday_b,hour_b,min_b,sec_b;
//**************
//自定义字符
//**************
void Def_Char(void)
{
int i;
wr_InD(1,0x40); //设置CGRAM地址
for(i = 8; i != 0;i--) //第一幅
{
wr_InD(0,0xff);
wr_InD(0,0x0f);
wr_InD(0,0);
wr_InD(0,0);
}
for(i = 8; i != 0;i--) //第二幅
{
wr_InD(0,0);
wr_InD(0,0);
wr_InD(0,0xff);
wr_InD(0,0x0f);
}
for(i = 8; i != 0;i--) //第三幅
{
wr_InD(0,0xff);
wr_InD(0,0);
wr_InD(0,0);
wr_InD(0,0x0f);
}
for(i = 8; i != 0;i--) //第三幅
{
wr_InD(0,0x0f);
wr_InD(0,0);
wr_InD(0,0);
wr_InD(0,0xff);
}
}
//************
//实数(BCD)转字符串
//************
char *itoc4_Covert(int Int_Number)
{
char result[5];
// char *point=result;
// point=result;
result[0] = (Int_Number / 0x1000) + 48;
result[1] = (Int_Number % 0x1000) / 0x100 + 48;
result[2] = (Int_Number % 0x100 ) / 0x10 + 48;
result[3] = (Int_Number % 0x10 ) + 48;
result[4] = '\0';
return result;
}
char *itoc2_Covert(int Int_Number)
{
char result[3];
// char *point=result;
// point=result;
result[0] = (Int_Number / 0x10) + 48;
result[1] = (Int_Number % 0x10) + 48;
result[2] = '\0';
return result;
}
//************
//实数(十进制)转字符串
//************
char *inttoCharS2_Covert(int Int_Number)
{
char result[3];
result[0] = (Int_Number / 10) + 48;
result[1] = (Int_Number % 10) + 48;
result[2] = '\0';
return result;
}
//**************
//实时时钟重显示
//**************
void Rtc_Rdisp(void)
{
int year,month,day,weekday,hour,min,sec;
int k=0;
// int year_b,month_b,day_b,weekday_b,hour_b,min_b,sec_b; //时钟备份,用于比较
char *p;
char q[12];
char *s=q;
rRTCCON = 0x01; // R/W enable, 1/32768, Normal(merge), No reset
while(1)
{
if(rBCDYEAR == 0x99)
{
year = 0x1999;
month=rBCDMON;
day=rBCDDAY;
weekday=rBCDDATE;
hour=rBCDHOUR;
min=rBCDMIN;
sec=rBCDSEC;
if(sec!=0)
break;
if(k==1)
break;
k=1;
}
else
{
year = 0x2000 + rBCDYEAR;
month=rBCDMON;
day=rBCDDAY;
weekday=rBCDDATE;
hour=rBCDHOUR;
min=rBCDMIN;
sec=rBCDSEC;
if(sec!=0)
break;
if(k==1)
break;
k=1;
}
}
rRTCCON = 0x0; // R/W disable(for power consumption), 1/32768, Normal(merge), No reset
*s++=' ';
p = itoc4_Covert(year); //日期
while (*p !='\0')
{
*s++ = *p++;
}
*s++ = '.';
*s = '\0';
Char_Disp(1,0,q);
s=q;
p = itoc2_Covert(month);
while (*p != '\0')
{
*s++ = *p++;
}
*s = '\0';
Char_Disp(4,0,q);
s=q;
*s++='.';
p = itoc2_Covert(day);
while (*p != '\0')
{
*s++ = *p++;
}
*s = '\0';
Char_Disp(5,0,q);
s=q;
p = itoc2_Covert(hour); //时,分,秒
while (*p !='\0')
{
*s++ = *p++;
}
*s = '\0';
Char_Disp(2,2,q);
s=q;
*s++=':';
p = itoc2_Covert(min);
while (*p != '\0')
{
*s++ = *p++;
}
*s++ = ':';
*s = '\0';
Char_Disp(3,2,q);
s=q;
p = itoc2_Covert(sec);
while (*p != '\0')
{
*s++ = *p++;
}
*s='\0';
Char_Disp(5,2,q);
Char_Disp(2,3,"星期");
Char_Disp(4,3,date[weekday]);
}
//************
//实时时钟显示
//************
void Rtc_Disp(void)
{
int year,month,day,weekday,hour,min,sec;
int k=0;
// int year_b,month_b,day_b,weekday_b,hour_b,min_b,sec_b; //时钟备份,用于比较
char *p;
char q[12];
char *s=q;
rRTCCON = 0x01; // R/W enable, 1/32768, Normal(merge), No reset
k=0;
while(1)
{
if(rBCDYEAR == 0x99)
{
year = 0x1999;
month=rBCDMON;
day=rBCDDAY;
weekday=rBCDDATE;
hour=rBCDHOUR;
min=rBCDMIN;
sec=rBCDSEC;
if(sec!=0)
break;
if(k==1)
break;
k=1;
}
else
{
year = 0x2000 + rBCDYEAR;
month=rBCDMON;
day=rBCDDAY;
weekday=rBCDDATE;
hour=rBCDHOUR;
min=rBCDMIN;
sec=rBCDSEC;
if(sec!=0)
break;
if(k==1)
break;
k=1;
}
}
rRTCCON = 0x0; // R/W disable(for power consumption), 1/32768, Normal(merge), No reset
if (year_b != year)
{
*s++=' ';
p = itoc4_Covert(year); //日期
while (*p !='\0')
{
*s++ = *p++;
}
*s++ = '.';
*s = '\0';
Char_Disp(1,0,q);
}
s=q;
if (month_b != month)
{
p = itoc2_Covert(month);
while (*p != '\0')
{
*s++ = *p++;
}
*s = '\0';
Char_Disp(4,0,q);
}
s=q;
if (day_b != day)
{
*s++='.';
p = itoc2_Covert(day);
while (*p != '\0')
{
*s++ = *p++;
}
*s = '\0';
Char_Disp(5,0,q);
}
s=q;
if (hour_b != hour)
{
p = itoc2_Covert(hour); //时,分,秒
while (*p !='\0')
{
*s++ = *p++;
}
*s = '\0';
Char_Disp(2,2,q);
}
s=q;
if (min_b != min)
{
*s++=':';
p = itoc2_Covert(min);
while (*p != '\0')
{
*s++ = *p++;
}
*s++ = ':';
*s = '\0';
Char_Disp(3,2,q);
}
s=q;
p = itoc2_Covert(sec);
while (*p != '\0')
{
*s++ = *p++;
}
*s='\0';
Char_Disp(5,2,q);
Char_Disp(2,3,"星期"); //星期,有标志位后要优化!
if (weekday_b != weekday)
{
Char_Disp(4,3,date[weekday]);
}
year_b = year;
month_b = month;
day_b = day;
weekday_b = weekday;
hour_b = hour;
min_b = min;
sec_b = sec;
}
//************
//时长初始显示
//************
void TickTime_InDisp (int tt_sec, int tt_min, int tt_hour, char *dail_id)
{
char *tt_b;
char tt_data[5];
char *tt_s = tt_data;
static char tt_min_b=99;
static char tt_hour_b=99;
//秒
tt_s = tt_data;
tt_b = inttoCharS2_Covert(tt_sec);
while (*tt_b != '\0')
{
*(tt_s++) = *(tt_b++);
}
*tt_s='\0';
Char_Disp(7,3,tt_data);
//分
tt_s = tt_data;
if (tt_hour)
{
*(tt_s++) = ':';
}
else
{
*(tt_s++) = ' ';
}
tt_b = inttoCharS2_Covert(tt_min);
while (*tt_b != '\0')
{
*(tt_s++) = *(tt_b++);
}
*(tt_s++) = ':';
*tt_s = '\0';
Char_Disp(5,3,tt_data);
//小时
if (tt_hour)
{
tt_s = tt_data;
tt_b = inttoCharS2_Covert(tt_hour);
while (*tt_b != '\0')
{
*(tt_s++) = *(tt_b++);
}
*tt_s='\0';
Char_Disp(4,3,tt_data);
}
Char_Disp(0,0,dail_id);
}
//************
//时长显示
//************
void TickTime_Disp (int tt_sec, int tt_min, int tt_hour)
{
char *tt_b;
char tt_data[5];
char *tt_s = tt_data;
static char tt_min_b=99;
static char tt_hour_b=99;
//秒
tt_s = tt_data;
tt_b = inttoCharS2_Covert(tt_sec);
while (*tt_b != '\0')
{
*(tt_s++) = *(tt_b++);
}
*tt_s='\0';
Char_Disp(7,3,tt_data);
//分
if (tt_min_b !=tt_min)
{
tt_s = tt_data;
if (tt_hour)
{
*(tt_s++) = ':';
}
else
{
*(tt_s++) = ' ';
}
tt_b = inttoCharS2_Covert(tt_min);
while (*tt_b != '\0')
{
*(tt_s++) = *(tt_b++);
}
*(tt_s++) = ':';
*tt_s = '\0';
Char_Disp(5,3,tt_data);
}
//小时
if (tt_hour_b != tt_hour)
{
if (tt_hour)
{
tt_s = tt_data;
tt_b = inttoCharS2_Covert(tt_hour);
while (*tt_b != '\0')
{
*(tt_s++) = *(tt_b++);
}
*tt_s='\0';
Char_Disp(4,3,tt_data);
}
}
tt_min_b = tt_min;
tt_hour_b = tt_hour;
}
//************
//时长显示中断
//************
void __irq TickTime_Int(void)
{
rI_ISPC=BIT_TICK;
TickTime_sec +=1;
if (TickTime_sec == 60)
{
TickTime_sec=0;
TickTime_min +=1;
if (TickTime_min == 60)
{
TickTime_min=0;
TickTime_hour +=1;
}
}
TickTime_Disp(TickTime_sec, TickTime_min, TickTime_hour);
}
//************
//时钟中断
//************
void __irq Rtc_Int(void)
{
rI_ISPC=BIT_TICK;
sec_tick=1;
Rtc_Disp();
}
//************
//时钟滴答使能
//************
void Rtc_Tickinit(void)
{
pISR_TICK=(unsigned)Rtc_Int;
rINTCON=0x1;
rRTCCON=0x1;
sec_tick=0;
rINTMSK &= ~(BIT_GLOBAL|BIT_TICK);
rRTCCON=0x0; //R/W disable(for power consumption), 1/32768, Normal(merge), No reset
rTICINT = 127+(1<<7); //START
rRTCCON=0x0; //END
/*
Flash_SectorErase ((volatile INT32U)RTC_flag);
Flash_WordProg ((volatile INT32U)RTC_flag,1);
*/
}
//**************
//时长显示初始化
//**************
void TickTimeDisp_Init (void)
{
rINTMSK |= BIT_TICK;
wr_InD(1,0x01);
Delay (20);
wr_InD(1,0x06);
TickTime_sec = 0;
TickTime_min = 0;
TickTime_hour= 0;
pISR_TICK=(unsigned)TickTime_Int;
TickTime_InDisp(TickTime_sec, TickTime_min, TickTime_hour, DailNum);
rINTMSK &= ~(BIT_GLOBAL|BIT_TICK);
}
//**************
//时钟回显初始化
//**************
void RTC_RDispInit (void)
{
rINTMSK |= BIT_TICK;
wr_InD(1,0x01);
Delay (20);
wr_InD(1,0x06);
pISR_TICK=(unsigned)Rtc_Int;
Rtc_Rdisp();
rINTMSK &= ~(BIT_GLOBAL|BIT_TICK);
}
//**************
//实时时钟初始化
//**************
void Rtc_Init(void)
{
if (Readflash((volatile INT32U)RTC_flag) == 0xffff) //改
{
rRTCCON = 0x01; // R/W enable, 1/32768, Normal(merge), No reset
rBCDYEAR = TESTYEAR;
rBCDMON = TESTMONTH;
rBCDDAY = TESTDAY; // SUN:1 MON:2 TUE:3 WED:4 THU:5 FRI:6 SAT:7
rBCDDATE = TESTDATE;
rBCDHOUR = TESTHOUR;
rBCDMIN = TESTMIN;
rBCDSEC = TESTSEC;
rRTCCON = 0x0;
//写相关标志
S_Flag_Save(SYS_Flag);
SYS_Flag[0] +=1;
SYS_Flag[1] = 0x0f01; //实时时钟运行标志;
Flash_SectorErase((volatile INT32U)ContSFlag_StartAdress);
S_Flag_ReWrite(SYS_Flag);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -