要实现书包的每日检查书籍功能,我们需要一个RTC时钟能掉电记录时间,掉电保存记录的时间在后备寄存器中,在快速开发中我们直接拉入正点原子的RTC时钟,RTC_Set()设置时间(会在初始化里检查是否是第一次设置),在rtc.c里面找到_calendar_obj calendar时钟结构体,RTC的初始化排在AT24C02初始化后,尽快进入时间获取,由calendar的结构体成员即可获取到日期时间判断(0-6为星期日到六),可以由闹钟中断完善出一个书包定时提醒功能。
通过switch(calendar.week)设置一个全局变量,由全局变量对之前提到的实时显示周几的变量相匹配,即可得到当日课程的AT24C02首地址,依次+3进行八次读取即可获得当日课程。
void duqukecheng(int zhouji)//读取内容并显示在屏幕上,传入周几变量
{
int count=0;
count = zhouji;
LCD_Clear(WHITE); //清屏,白底
LCD_ShowString(24,100,200,16,16,"Today lesson:");
for(;count<=zhouji+24;count+=24)//控制周几 3 * 8 * 7 = 168 课程循环七页,每页三秒钟,一周七天,一天八节课,一节课占三字节
{
AT24CXX_Read(zhouji+0,ONEdatatemp,ONESIZE);//0 读第一节课
zhuanhuan0(ONEdatatemp);//第一节课的三字节内容匹配
AT24CXX_Read(zhouji+3,TWOdatatemp,TWOSIZE);//3 读第二节课
zhuanhuan1(TWOdatatemp);//第二节课的三字节内容匹配
AT24CXX_Read(zhouji+6,THREEdatatemp,THREESIZE);//6
zhuanhuan2(THREEdatatemp);
AT24CXX_Read(zhouji+9,FOURdatatemp,FOURSIZE);//9
zhuanhuan3(FOURdatatemp);
AT24CXX_Read(zhouji+12,FIVEdatatemp,FIVESIZE);//12
zhuanhuan4(FIVEdatatemp);
AT24CXX_Read(zhouji+15,SIXdatatemp,SIXSIZE);//15
zhuanhuan5(SIXdatatemp);
AT24CXX_Read(zhouji+18,SEVENdatatemp,SEVENSIZE);//18
zhuanhuan6(SEVENdatatemp);
AT24CXX_Read(zhouji+21,EIGHTdatatemp,EIGHTSIZE);//21
zhuanhuan7(EIGHTdatatemp);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
}
printf("结束当日课程显示\r\n");
//LCD_Clear(WHITE); //清屏
}
这是转换函数,用以匹配AT24C02里存储的一节课三字节的内容,做出对应的LCD显示,一共有八组,分别对应一天的1-8节课显示位置:
void zhuanhuan0(u8 RX_BUFFER[])
{
if(RX_BUFFER[1] == 'O' && RX_BUFFER[2] == 'N')
{
LCD_ShowString(4+48+100,48,70,16,16,"NONE");
class0 = 1;
}
else if(RX_BUFFER[1] == 'a' && RX_BUFFER[2] == 't')
{
LCD_ShowString(4+48+100,48,70,16,16,"Math");
class1 = 1;
}
else if(RX_BUFFER[1] == 'h' && RX_BUFFER[2] == 'i')
{
LCD_ShowString(4+48+100,48,70,16,16,"Chinese");
class2 = 1;
}
else if(RX_BUFFER[1] == 'n' && RX_BUFFER[2] == 'g')
{
LCD_ShowString(4+48+100,48,70,16,16,"English");
class3 = 1;
}
else if(RX_BUFFER[1] == 'h' && RX_BUFFER[2] == 'y')
{
LCD_ShowString(4+48+100,48,70,16,16,"Physics");
class4 = 1;
}
else if(RX_BUFFER[1] == 'i' && RX_BUFFER[2] == 'o')
{
LCD_ShowString(4+48+100,48,70,16,16,"Biology");
class5 = 1;
}
else if(RX_BUFFER[1] == 'h' && RX_BUFFER[2] == 'e')
{
LCD_ShowString(4+48+100,48,70,16,16,"Chemistry");
class6 = 1;
}
else if(RX_BUFFER[1] == 'e' && RX_BUFFER[2] == 'o')
{
LCD_ShowString(4+48+100,48,70,16,16,"Geography");
class7 = 1;
}
else if(RX_BUFFER[1] == 'o' && RX_BUFFER[2] == 'l')
{
LCD_ShowString(4+48+100,48,70,16,16,"Politics");
class8 = 1;
}
else if(RX_BUFFER[1] == 'i' && RX_BUFFER[2] == 's')
{
LCD_ShowString(4+48+100,48,70,16,16,"History");
class9 = 1;
}
else
{
printf("RX_BUFFER[0] IS %c RX_BUFFER[1] IS %c RX_BUFFER[2] IS %c\r\n",USART_RX_BUF[0],RX_BUFFER[1],RX_BUFFER[2]);
LCD_ShowString(16+6+64+8,200,70,16,16,"ERROR!!");
}
}
关于课程匹配:我用的方法是全局变量,分别两组全局变量对应九种课和一种没课情况,在RC522多从机的刷卡模块程序里,检测到卡ID后就行匹配,九种卡ID对应九种课本,判定为有的时候即赋值为1无则为0。另一组全局变量给AT24C02读取当日课程用,读取到的判定为1无则0。最后再compareclass中完成全局数组classtotal的赋值,根据此数组进行LCD显示输出提醒。class0表示无课,1-9表示先前对应的AT24C02写入的书籍数组名称。
void compareclass(void)
{
if(class0) //1为有课
{
class_total[0]=1;
}
else
{
class_total[0]=0;
}
if(Mathshu == class1 && Mathshu == 1)//´带上书了
{
class_total[1] = 1;
}
else if(class1 == 0 || (class1 == 0 && Mathshu == 1))//没课有书,没书没课则class有课赋值1
{
class_total[1] = -1;
}
else//有课没书
{
class_total[1] = 0;
}
if(Chineseshu == class2 && Chineseshu == 1)//带上书了
{
class_total[2] = 1;
}
else if(class2 == 0 || (class2 == 0 && Chineseshu== 1))
{
class_total[2] = -1;
}
else
{
class_total[2] = 0;
}
if(Englishshu == class3 && Englishshu == 1)
{
class_total[3] = 1;
}
else if(class3 == 0 || (class3 == 0 && Englishshu== 1))
{
class_total[3] = -1;
}
else
{
class_total[3] = 0;
}
if(Physicsshu == class4 && Physicsshu == 1)
{
class_total[4] = 1;
}
else if(class4 == 0 || (class4 == 0 && Physicsshu== 1))
{
class_total[4] = -1;
}
else
{
class_total[4] = 0;
}
if(Biologyshu == class5 && Biologyshu == 1)
{
class_total[5] = 1;
}
else if(class5 == 0 || (class5 == 0 && Biologyshu== 1))
{
class_total[5] = -1;
}
else
{
class_total[5] = 0;
}
if(Chemistryshu == class6 && Chemistryshu == 1)
{
class_total[6] = 1;
}
else if(class6 == 0 || (class6 == 0 && Chemistryshu== 1))
{
class_total[6] = -1;
}
else
{
class_total[6] = 0;
}
if(Geographyshu == class7 && Geographyshu == 1)
{
class_total[7] = 1;
}
else if(class7 == 0 || (class7 == 0 && Geographyshu== 1))
{
class_total[7] = -1;
}
else
{
class_total[7] = 0;
}
if(Politicsshu == class8 && Politicsshu == 1)
{
class_total[8] = 1;
}
else if(class8 == 0 || (class8 == 0 && Biologyshu== 1))
{
class_total[8] = -1;
}
else
{
class_total[8] = 0;
}
if(Historyshu == class9 && Historyshu == 1)
{
class_total[9] = 1;
}
else if(class9 == 0 || (class9 == 0 && Historyshu== 1))
{
class_total[9] = -1;
}
else/
{
class_total[9] = 0;
}
}
至此完成书籍匹配,也就是主体框架搭建中的第一部分:系统自检。接下来就是主界面的程序设计方便用户操作,我通过设定按键触发的方式跳出上述系统自检部分的while(1)死循环,清屏后进入主界面。