电路原理图如下:
Altium Designer画的原理图和PCB图如下:(51hei附件中可下载工程文件)
单片机源程序如下:
- #include "my_include.h"
- #define NUM_SECTOR_REC_RFID 0
- #define NUM_SECTOR_CARD 1
- #define ADDR_FLASH_ID_BASE_RFID FLASH_BASE_ADDR+(STM32_FLASH_SIZE - NUM_SECTOR_REC_RFID - 1)*1024//保存刷卡用户记录的Flash地址
- #define ADDR_FLASH_ID_BASE_CARD FLASH_BASE_ADDR+(STM32_FLASH_SIZE - NUM_SECTOR_CARD - 1)*1024//保存用户卡号的Flash地址
- #define MAX_NUM_USER_CARD 3//RFID最大用户数
- #define F_SIZE 12//默认字体大小
- #define MyLCD_Show(m,n,p) LCD_ShowString(LCD_GetPos_X(F_SIZE,m),LCD_GetPos_Y(F_SIZE,n),p,F_SIZE,false)
- #define MAX_MENU 4//菜单条目总数
- #if F_SIZE==12
- #define START_LINE 0
- #define POS_MENU_Y 1//菜单显示起始行数
- #elif F_SIZE==24
- #define START_LINE 1
- #define POS_MENU_Y 4//菜单显示起始行数
- #endif
- u8 UID[4];//读取到的卡号
- u8 userCard[MAX_NUM_USER_CARD][4];//用户的卡号
- char disTemp[17];
- char dis0[64];//液晶显示暂存数组
- char dis1[64];//液晶显示暂存数组
- u32 ticks_rly=0,ticks_beep=0;//继电器和蜂鸣器动作及时
- bool beepAlarm = false;//蜂鸣器报警标志
- _record_obj saveRecord_CARD[MAX_NUM_USER_CARD+1];//最大刷卡用户数+未录入卡号(所有未录入卡号视为同一个)
- char *userName_CARD[MAX_NUM_USER_CARD+1] = {"RFID01","RFID02","RFID03","RFID未录入"};//用户名称
- u8 workState = 0;
- u8 availableCardCount = 0;
- void OnGetUartMessage(const _uart_msg_obj *uartMsgRec)
- {
- char *strPtr;
- if((strPtr = strstr(uartMsgRec->payload,"RTC"))!=NULL)//接收到rtc字符串
- {
- My_RTC_SetStr(strPtr+3);//设置实时时钟时间
- USART_printf(USART1,"*Set RTC OK#\r\n");
- }
- else if(strstr(uartMsgRec->payload,"RELAY_KEY")!=NULL)//接收到字符串
- {
- ticks_rly = My_SysTick_GetTicks();//获取系统时间
- MyLCD_Show(4,POS_MENU_Y+3,"远程操作成功 ");//液晶显示字符串
- relay = RLY_ON;//继电器闭合
- beepAlarm = false;//取消蜂鸣器报警
- //**All notes can be deleted and modified**//
- }
- else if(strstr(uartMsgRec->payload,"BEEP_KEY")!=NULL)//接收到字符串
- {
- #pragma push
- #pragma diag_suppress 188//暂时屏蔽#188-D: enumerated type mixed with another type警告
- beepAlarm = !beepAlarm;//切换报警状态
- #pragma pop
- buzzer = beepAlarm;//蜂鸣器动作
- USART_printf(USART1,"*Set BEEP OK#\r\n");
- }
- else if(strstr(uartMsgRec->payload,"GET_RECORD_RFID")!=NULL)//接收到字符串
- {
- u8 i;
- for(i=0;i<MAX_NUM_USER_CARD+1;i++)
- {
- sprintf(dis0,"*REC_CARD_U%dC%dT%d#\r\n",i,saveRecord_CARD[i].count,saveRecord_CARD[i].timeCount);
- USART_printf(USART1,dis0);
- }
- }
- else
- {
- USART_printf(USART1,"*CMD ERROR#\r\n");
- }
- }
- void keySetTime( void );
- int main(void)
- {
- u8 index_CARD;//当前选择的用户编号
- u8 sec_now = 0;//当前时间的秒钟数
- u8 day_now = 0;//当前日期的天数
- u8 i;
-
- My_LED_Init();//LED初始化
- My_KEY_Init();//按键初始化
- USARTx_Init(USART1,9600);//串口初始化为9600
- // USARTx_Init(USART2,9600);//串口初始化为9600
- relay = RLY_ON;//继电器闭合
- buzzer = BEEP_ON;//蜂鸣器报警
- LCD_Init();//液晶初始化
- relay = RLY_OFF;//继电器断开
- buzzer = BEEP_OFF;//蜂鸣器取消报警
- LCD_Clear(Color16_BLACK);//清除液晶屏幕
- FRONT_COLOR = Color16_WHITE;//设置液晶前景色(画笔颜色)
- BACK_COLOR = Color16_BLACK;//设置液晶背景色(画布颜色)
- My_RTC_Init(false);//RTC初始化(不使能闹钟)
- keySetTime();//进入按键设置时钟 如果是有无线通信的情况下 该按键设置可以取消
- MyLCD_Show(4,0,"智能打卡系统");//液晶显示字符串
- MyLCD_Show(4,2+START_LINE,"正在初始化...");//液晶显示字符串
- My_RC522_Init();
-
- My_STMFlash_SectorSaveInit(NUM_SECTOR_REC_RFID,ADDR_FLASH_ID_BASE_RFID,(u16 *)saveRecord_CARD,sizeof(saveRecord_CARD)/2);//读取保存的RFID历史记录数据
- for(i=0;i<MAX_NUM_USER_CARD+1;i++)
- {
- if(saveRecord_CARD[i].count==0xffff)
- {
- saveRecord_CARD[i].timeCount=0;//记录时间戳默认为0(即1970年1月1日00时00分00秒)
- saveRecord_CARD[i].count=0;//记录签到次数默认为0
- saveRecord_CARD[i].userID = i;//用户ID按照数组顺序赋值
- saveRecord_CARD[i].type = 1;
- }
- }
- My_STMFlash_SectorSaveInit(NUM_SECTOR_CARD,ADDR_FLASH_ID_BASE_CARD,(u16 *)userCard,sizeof(userCard)/2);//读取保存的用户卡号数据
- for(i=0;i<MAX_NUM_USER_CARD;i++)//将无效卡号清零
- {
- if(*((u32 *)userCard[i])==0xffffffff)
- {
- *((u32 *)userCard[i])=0;//卡号为0是为无效卡
- }
- //**All notes can be deleted and modified**//
- }
- availableCardCount = MAX_NUM_USER_CARD-availableCardCount;
-
- MyLCD_Show(4,2+START_LINE,"初始化成功 ");//液晶显示字符串
- sprintf(disTemp,"RFID总数:%d",availableCardCount);
- MyLCD_Show(4,3+START_LINE,disTemp);//液晶显示字符串
-
- delay_ms(1000);
- MyLCD_Show(4,2+START_LINE," ");//液晶显示字符串
- MyLCD_Show(4,3+START_LINE," ");//液晶显示字符串
- MyLCD_Show(4,4+START_LINE," ");//液晶显示字符串
- MyLCD_Show(4,POS_MENU_Y," 欢迎使用 ");//液晶显示字符串
- //FINGERPRINT_Cmd_Delete_All_Model();
- My_Menu_Init();
-
- while(1)
- {
- My_KeyScan();//按键扫描
-
-
- switch(My_Menu_GetSelectID())//获取菜单ID
- {
- case MENU_ID_ADD_RFID:////////////////////////////////////////////////添加卡号
- {
- switch(workState)
- {
- case 0:
- for(index_CARD=0;index_CARD<MAX_NUM_USER_CARD;index_CARD++)//计算有效卡号数量
- {
- if(*((u32 *)userCard[index_CARD])==0)//卡号为0是为无效卡
- {
- break;
- }
- }
- if(index_CARD>=MAX_NUM_USER_CARD)//卡号索引大于等于最大用户数
- {
- MyLCD_Show(4,POS_MENU_Y+2,"RFID库已满!");//液晶显示字符串
- delay_ms(1000);
- MyLCD_Show(4,POS_MENU_Y+2," ");//液晶显示字符串
- My_Menu_Back(true);
- break;
- }
- MyLCD_Show(5,POS_MENU_Y+2,"选择编号 ");//液晶显示字符串
- sprintf(disTemp," %s ",userName_CARD[index_CARD]);//显示ID号
- MyLCD_Show(4,POS_MENU_Y+3,disTemp);
- workState++;//进入下一个状态
- break;
- case 1:
- if(KeyIsPress(key_up))//按下了向上键
- {
- index_CARD++;//ID号加
- index_CARD %= MAX_NUM_USER_CARD;//最大用户数
- sprintf(disTemp," %s ",userName_CARD[index_CARD]);//显示ID号
- MyLCD_Show(4,POS_MENU_Y+3,disTemp);
- }
- if(KeyIsPress(key_down))//按下了向下键
- {
- //**All notes can be deleted and modified**//
- sprintf(disTemp," %s ",userName_CARD[index_CARD]);//显示ID号
- MyLCD_Show(4,POS_MENU_Y+3,disTemp);
- }
- if(KeyIsPress(key_ok))//按下了OK键
- {
- if(*((u32 *)userCard[index_CARD])==0)//卡号为0是为无效卡
- {
- workState++;//进入下一个状态
- }
- else
- {
- sprintf(disTemp,"%s已存在! ",userName_CARD[index_CARD]);//显示ID号
- MyLCD_Show(4,POS_MENU_Y+3," ");
- MyLCD_Show(4,POS_MENU_Y+2,disTemp);
- delay_ms(1000);
- MyLCD_Show(4,POS_MENU_Y+2," ");
- //**All notes can be deleted and modified**//
- }
- }
- break;
- case 2:
- MyLCD_Show(5,POS_MENU_Y+2,"请刷卡... ");//液晶显示字符串
- MyLCD_Show(5,POS_MENU_Y+3," ");//液晶显示字符串
- workState++;//进入下一个状态
- break;
- case 3:
- if(My_RC522_ReadCardID(UID,true))//读取到一次卡号
- {
- buzzer = BEEP_ON;
- delay_ms(100);
- buzzer = BEEP_OFF;
- for(i=0;i<MAX_NUM_USER_CARD;i++)//对比所有的用户卡号
- {
- if(My_memcmp(UID,userCard[i],4))//与用户卡号相同
- {
- break;
- }
- }
- if(i<MAX_NUM_USER_CARD)//与其中一个用户卡号相同
- {
- MyLCD_Show(5,POS_MENU_Y+2,"卡号已存在! ");//液晶显示字符串
- delay_ms(900);
- MyLCD_Show(5,POS_MENU_Y+2," ");//液晶显示字符串
- workState--;//返回上一个状态
- }
- else//与所有的用户卡号都不相同
- {
- MyLCD_Show(5,POS_MENU_Y+2,"刷卡成功... ");//液晶显示字符串
- delay_ms(400);
- //**All notes can be deleted and modified**//
- }
- }
- break;
- case 4:
- MyLCD_Show(5,POS_MENU_Y+2,"请再刷一次... ");//液晶显示字符串
- workState++;//进入下一个状态
- break;
- case 5:
- if(My_RC522_ReadCardID(userCard[index_CARD],true))//读取到一次卡号
- {
- buzzer = BEEP_ON;
- delay_ms(100);
- buzzer = BEEP_OFF;
- if(My_memcmp(userCard[index_CARD],UID,4))//对比两次读取的卡号是否相同
- {
- MyLCD_Show(5,POS_MENU_Y+2,"刷卡成功! ");//液晶显示字符串
- My_STMFlash_SaveUseSector(NUM_SECTOR_CARD);//保存数据到用户RFID卡号位置
- workState++;//进入下一个状态
- delay_ms(900);
- }
- else
- {
- MyLCD_Show(5,POS_MENU_Y+2,"卡号不匹配! ");//液晶显示字符串
- MyLCD_Show(5,POS_MENU_Y+3,"请再次刷卡... ");//液晶显示字符串
- *((u32 *)userCard[index_CARD])=0;//卡号清零
- //**All notes can be deleted and modified**//
- }
- }
- break;
- case 6:
- MyLCD_Show(5,POS_MENU_Y+2," ");//液晶显示字符串
- My_Menu_Exit();//退出菜单
- workState=0;//回到初始状态
- break;
- default:break;
- }
- }
- break;
- case MENU_ID_DEL_RFID:////////////////////////////////////////////////删除卡号
- {
- switch(workState)
- {
- case 0:
- if(index_CARD>=MAX_NUM_USER_CARD)
- {
- index_CARD = MAX_NUM_USER_CARD-1;//指向最大值
- }
- MyLCD_Show(5,POS_MENU_Y+2,"选择编号 ");//液晶显示字符串
- sprintf(disTemp," %s ",userName_CARD[index_CARD]);//显示ID号
- MyLCD_Show(4,POS_MENU_Y+3,disTemp);
- workState++;//进入下一个状态
- break;
- case 1:
- if(KeyIsPress(key_up))//按下了向上键
- {
- index_CARD++;//ID号加
- index_CARD %= MAX_NUM_USER_CARD;//最大用户数
- sprintf(disTemp," %s ",userName_CARD[index_CARD]);//显示ID号
- MyLCD_Show(4,POS_MENU_Y+3,disTemp);
- }
- if(KeyIsPress(key_down))
- {
- if(index_CARD)//索引号大于0
- {
- index_CARD--;//ID号减
- }
- else
- {
- index_CARD = MAX_NUM_USER_CARD-1;//指向最大值
- }
- sprintf(disTemp," %s ",userName_CARD[index_CARD]);//显示ID号
- MyLCD_Show(4,POS_MENU_Y+3,disTemp);
- }
- if(KeyIsPress(key_ok))//按下了OK键
- {
- if(*((u32 *)userCard[index_CARD])==0)//卡号为0是为无效卡
- {
- sprintf(disTemp,"%s不存在!",userName_CARD[index_CARD]);
- MyLCD_Show(5,POS_MENU_Y+2,disTemp);//液晶显示字符串
- MyLCD_Show(4,POS_MENU_Y+3," ");//液晶显示字符串
- //**All notes can be deleted and modified**//
- }
- else
- {
- sprintf(disTemp,"删除%s卡号?",userName_CARD[index_CARD]);
- MyLCD_Show(4,POS_MENU_Y+2,disTemp);//液晶显示字符串
- MyLCD_Show(4,POS_MENU_Y+3," ");//液晶显示字符串
- //**All notes can be deleted and modified**//
- }
- delay_ms(500);
- }
- break;
- case 2:
- if(KeyIsPress(key_ok))//按下了OK键
- {
- MyLCD_Show(4,POS_MENU_Y+2,"卡号已删除! ");//液晶显示字符串
- MyLCD_Show(4,POS_MENU_Y+3," ");//液晶显示字符串
- saveRecord_CARD[index_CARD].timeCount = 0;//默认为0
- saveRecord_CARD[index_CARD].count=0;//计数值清零
- My_STMFlash_SaveUseSector(NUM_SECTOR_REC_RFID);//保存数据到RFID历史记录位置
- *((u32 *)userCard[index_CARD])=0;//卡号清零
- My_STMFlash_SaveUseSector(NUM_SECTOR_CARD);//保存数据到用户RFID卡号位置
- workState++;//进入下一个状态
- delay_ms(500);
- }
- break;
- case 3:
- MyLCD_Show(4,POS_MENU_Y+2," ");//液晶显示字符串
- My_Menu_Exit();//退出菜单
- workState=0;//回到初始状态
- break;
- default:break;
- }
- }
- break;
- case MENU_ID_CLR_RFID:////////////////////////////////////////////////清空卡号
- {
- switch(workState)
- {
- case 0:
- MyLCD_Show(4,POS_MENU_Y+1," ");//液晶显示字符串
- MyLCD_Show(4,POS_MENU_Y+2,"确认清空卡号? ");//液晶显示字符串
- MyLCD_Show(4,POS_MENU_Y+3," ");//液晶显示字符串
- workState++;//进入下一个状态
- break;
- case 1:
- if(KeyIsPress(key_ok))//按下了OK键
- {
- MyLCD_Show(4,POS_MENU_Y+2,"卡号已清空! ");//液晶显示字符串
- //**All notes can be deleted and modified**//
- My_STMFlash_SaveUseSector(NUM_SECTOR_REC_RFID);//保存数据到RFID历史记录位置
- for(i=0;i<MAX_NUM_USER_CARD;i++)//清除每一个RFID卡号
- {
- *((u32 *)userCard[i])=0;//卡号为0是为无效卡
- }
- My_STMFlash_SaveUseSector(NUM_SECTOR_CARD);//保存数据到flash
- workState++;//进入下一个状态
- delay_ms(800);
- }
- break;
- case 2:
- MyLCD_Show(4,POS_MENU_Y+2," ");//液晶显示字符串
- My_Menu_Exit();//退出菜单
- workState=0;//回到初始状态
- break;
- default:break;
- }
- }
- break;
- case MENU_ID_HISTORY_RFID:////////////////////////////////////////////RFID历史记录
- {
- switch(workState)
- {
- case 0:
- for(i=0;i<MAX_NUM_USER_CARD+1;i++)//遍历每一个RFID历史记录
- {
- _calendar_obj cal_save;
- My_RTC_IntegerToCalendar(saveRecord_CARD[i].timeCount,&cal_save);//将RFID历史记录的时间数据转换为日历结构体
- sprintf(dis0,"%s %d次 ",userName_CARD[i],saveRecord_CARD[i].count);//数据格式转换
- sprintf(dis1,"%04d-%02d-%02d %02d:%02d:%02d",cal_save.year,cal_save.month,cal_save.day,cal_save.hour,cal_save.minute,cal_save.second);
- MyLCD_Show(0,POS_MENU_Y+(i<<1)+1,dis0);//液晶显示字符串
- MyLCD_Show(0,POS_MENU_Y+(i<<1)+2,dis1);//液晶显示字符串
- }
- workState++;//进入下一个状态
- break;
- case 1:
- if(KeyIsPress(key_set_back))//按下了返回按键
- {
- for(i=0;i<MAX_NUM_USER_CARD+1;i++)//清除每一条历史纪录的显示
- {
- MyLCD_Show(0,POS_MENU_Y+(i<<1)+1," ");//液晶显示字符串
- MyLCD_Show(0,POS_MENU_Y+(i<<1)+2," ");//液晶显示字符串
- }
- }
- break;
- default:break;
- }
- }
- break;
- default:
- break;
- }
- My_Menu_Contrl();//控制菜单的上下移动及进入和返回
-
- if(My_Menu_GetSelectID() == 0)//未进入菜单
- {
- if(KeyIsPress(key_up))//如果按下了继电器控制按键
- {
- ticks_rly = My_SysTick_GetTicks();//获取系统时间
- relay = RLY_ON;//继电器闭合
- beepAlarm = false;//取消蜂鸣器报警
- buzzer = BEEP_OFF;//取消蜂鸣器报警
- }
- if(KeyIsPress(key_down))//如果按下了报警按键
- {
- #pragma push
- #pragma diag_suppress 188//暂时屏蔽#188-D: enumerated type mixed with another type警告
- beepAlarm = !beepAlarm;//切换报警状态
- #pragma pop
- buzzer = beepAlarm;//蜂鸣器动作
- }
- // 寻卡
- if(My_RC522_ReadCardID(UID,true))
- {
- for(index_CARD=0;index_CARD<MAX_NUM_USER_CARD;index_CARD++)//对比每一个RFID卡号
- {
- if(My_memcmp(UID,userCard[index_CARD],4))//如果卡号相同
- {
- break;
- }
- }
- buzzer = !buzzer;
- delay_ms(100);
- buzzer = !buzzer;
- saveRecord_CARD[index_CARD].timeCount = My_RTC_CalendarToInteger(&calendar);//将当前RTC时间转换为整数
- saveRecord_CARD[index_CARD].count++;//计数值+1
- if(index_CARD<MAX_NUM_USER_CARD)//如果读取到的卡号与其中一个用户卡号相同
- {
- ticks_rly = My_SysTick_GetTicks();//获取系统时间
- beepAlarm = false;//取消蜂鸣器报警
- relay = RLY_ON;//继电器闭合
- buzzer = BEEP_OFF;//取消蜂鸣器报警
- FRONT_COLOR = Color16_GREEN;//将液晶前景色(画笔颜色)设置为绿色
- sprintf(disTemp,"%s %d次",userName_CARD[index_CARD],saveRecord_CARD[index_CARD].count);
- MyLCD_Show(4,POS_MENU_Y+3,"刷卡成功!");//液晶显示字符串
- }
- else//如果读取到的卡号与所有用户卡号都不相同
- {
- ticks_beep = My_SysTick_GetTicks();//获取系统时间
- buzzer = BEEP_ON;//蜂鸣器报警
- relay = RLY_OFF;//继电器断开
- FRONT_COLOR = Color16_RED;//将液晶前景色(画笔颜色)设置为红色
- sprintf(disTemp,"RFID未录入 %d次",saveRecord_CARD[index_CARD].count);
- }
- sprintf(dis0,"*REC_CARD_U%dC%dT%d#\r\n",index_CARD,saveRecord_CARD[index_CARD].count,saveRecord_CARD[index_CARD].timeCount);
- USART_printf(USART1,dis0);
- MyLCD_Show(4,POS_MENU_Y+2,disTemp);//液晶显示字符串
- sprintf(dis0,"%04d-%02d-%02d",calendar.year,calendar.month,calendar.day);
- sprintf(dis1,"%02d:%02d:%02d %d",calendar.hour,calendar.minute,calendar.second,calendar.week);
- MyLCD_Show(4,POS_MENU_Y+4,dis0);//液晶显示字符串
- MyLCD_Show(4,POS_MENU_Y+5,dis1);//液晶显示字符串
- //**All notes can be deleted and modified**//
- delay_ms(1800);//防止手指松开时的误判断
- MyLCD_Show(0,POS_MENU_Y+2," ");//液晶显示字符串
- MyLCD_Show(0,POS_MENU_Y+3," ");//液晶显示字符串
- MyLCD_Show(0,POS_MENU_Y+4," ");//液晶显示字符串
- MyLCD_Show(0,POS_MENU_Y+5," ");//液晶显示字符串
- }
- }
- if(ticks_rly>0 && SysTickSecPassed(ticks_rly,3))//时间过去3秒钟
- {
- ticks_rly = 0;
- relay = RLY_OFF;//继电器断开
- }
- if(ticks_beep>0 && SysTickSecPassed(ticks_beep,3))//时间过去3秒钟
- {
- ticks_beep = 0;
- buzzer = BEEP_OFF;//取消蜂鸣器报警
- }
-
- if(day_now != calendar.day)
- {
- day_now = calendar.day;
- sprintf(dis0,"%04d-%02d-%02d",calendar.year,calendar.month,calendar.day);
- #if START_LINE==1
- MyLCD_Show(5,1,dis0);//液晶显示字符串
- #else
- MyLCD_Show(2,0,dis0+5);//液晶显示字符串
- MyLCD_Show(7,0," ");//液晶显示字符串
- #endif
- }
- if(sec_now != calendar.second)
- {
- sec_now = calendar.second;
- sprintf(dis1,"%02d:%02d:%02d %d",calendar.hour,calendar.minute,calendar.second,calendar.week);
- #if START_LINE==1
- MyLCD_Show(5,2,dis1);//液晶显示字符串
- #else
- MyLCD_Show(9,0,dis1);//液晶显示字符串
- #endif
- }
- if(beepAlarm)
- {
- relay = RLY_OFF;//继电器断开
- buzzer = BEEP_ON;
- }
- My_UartMessage_Process();//处理串口数据
- }
- }
- void My_Menu_Contrl(void)
- {
- if(selectedMenu!=NULL)
- {
- if(KeyIsPress(key_up))//按下了向上键
- {
- My_Menu_SelectUp(true);
- }
- if(KeyIsPress(key_down))//按下了向上键
- {
- My_Menu_SelectDown(true);
- }
- if(KeyIsPress(key_ok))//按下了OK键
- {
- My_Menu_Into(true);
- }
- if(KeyIsPress(key_set_back))
- {
- MyLCD_Show(0,POS_MENU_Y+1," ");//液晶显示字符串
- MyLCD_Show(0,POS_MENU_Y+2," ");//液晶显示字符串
- MyLCD_Show(0,POS_MENU_Y+3," ");//液晶显示字符串
- workState=0;//回到初始状态
- My_Menu_Back(true);
- }
- }
- else if(KeyIsPress(key_set_back))
- {
- My_Menu_Into(true);
- }
- }
- void My_Menu_Display(void)
- {
- u8 i;
- if(selectedMenu==NULL)//如果已经退出菜单
- {
- MyLCD_Show(4,POS_MENU_Y," 欢迎使用 ");//液晶显示字符串
- return;
- }
- if(My_Menu_UnderBottom())
- {
- MyLCD_Show(6,POS_MENU_Y,*(selectedMenu->contentPtrArray+selectedMenu->selectIndex));//液晶显示字符串
- return;
- }
- MyLCD_Show(6,POS_MENU_Y,selectedMenu->title);//液晶显示字符串
- for(i=0;i<selectedMenu->itemCount;i++)
- {
- if(i==selectedMenu->selectIndex)
- {
- FRONT_COLOR = Color16_LIGHTBLUE;//设置前景色(画笔颜色)为浅蓝色
- MyLCD_Show(5,i+POS_MENU_Y+1,">");//液晶显示字符串
- MyLCD_Show(6,POS_MENU_Y+1+i,*(selectedMenu->contentPtrArray+i));//液晶显示字符串
- FRONT_COLOR = Color16_WHITE;//设置前景色(画笔颜色)为白色
- }
- else
- {
- MyLCD_Show(5,i+POS_MENU_Y+1," ");//液晶显示字符串
- MyLCD_Show(6,POS_MENU_Y+1+i,*(selectedMenu->contentPtrArray+i));//液晶显示字符串
- }
- }
- }
- void My_Menu_Clear(void)
- {
- u8 i,len;
- if(selectedMenu==NULL || My_Menu_UnderBottom())//如果推出了菜单或当前在菜单的最底层
- {
- MyLCD_Show(4,POS_MENU_Y," ");//液晶显示字符串
- return;
- }
- len = strlen(selectedMenu->title);//计算字符串长度
- while(len--)
- {
- MyLCD_Show(6+len,POS_MENU_Y," ");//液晶显示字符串
- }
- for(i=0;i<selectedMenu->itemCount;i++)//
- {
- len = strlen(*(selectedMenu->contentPtrArray))+1;//计算字符串长度
- while(len--)
- {
- MyLCD_Show(5+len,POS_MENU_Y+i+1," ");//液晶显示字符串
- }
- }
- }
- #pragma diag_suppress 188
- #ifdef LCD_2_4
- #define MyLCD_ShowSetTime(m,n,p) LCD_ShowString(LCD_GetPos_X(24,m),LCD_GetPos_Y(24,n),p,24,false)
- #else
- #define MyLCD_ShowSetTime(m,n,p) LCD_ShowString(LCD_GetPos_X(12,m),LCD_GetPos_Y(12,n),p,12,false)
- #endif
- void keySetTime( void )
- {
- u8 delay=0;//延时跳出
- u8 setTimeFlag =0;//不进行设置时间
- u8 disPlace =0;
- u16 setYear,setMonth,setDay,setHour,setMin,setSec;
- u8 setFlag = 0;
- u8 i= 0;
-
- MyLCD_ShowSetTime(1,2,"Set Rtc ?");
- MyLCD_ShowSetTime(1,3,"K1:Yes K2:No");
- delay = 100; //延时选择约2s
- while(delay)
- {
- My_KeyScan();//按键扫描
- if(KeyIsPressed(0))
- {
- setTimeFlag = 1;//进入时间设置
- LCD_Clear(Color16_BLACK);//清除液晶屏幕
- FRONT_COLOR = Color16_WHITE;//设置液晶前景色(画笔颜色)
- MyLCD_ShowSetTime(0,0,"set RTC :");
- setYear = calendar.year;setMonth = calendar.month;setDay = calendar.day;
- setHour = calendar.hour;setMin = calendar.minute;setSec = calendar.second;
- break;
- }
- else if(KeyIsPress(1))
- {
- break;
- }
- delay--; //延时--
- delay_ms(10);
- }
-
- while(setTimeFlag)//时间设置 设置到最后一项后再点击设置跳出
- {
- disPlace =1;//显示位置依次增加
- FRONT_COLOR = Color16_WHITE;//设置液晶前景色(画笔颜色)
- sprintf(dis0,"Year:%04d ",setYear);
- MyLCD_ShowSetTime(2,disPlace++,dis0);
-
- sprintf(dis0,"Mon :%02d ",setMonth);
- MyLCD_ShowSetTime(2,disPlace++,dis0);
-
- sprintf(dis0,"Day :%02d ",setDay);
- MyLCD_ShowSetTime(2,disPlace++,dis0);
-
- sprintf(dis0,"Hour:%02d ",setHour);
- MyLCD_ShowSetTime(2,disPlace++,dis0);
-
- sprintf(dis0,"Min :%02d ",setMin);
- MyLCD_ShowSetTime(2,disPlace++,dis0);
-
- sprintf(dis0,"Sec :%02d ",setSec);
- MyLCD_ShowSetTime(2,disPlace++,dis0);
- My_KeyScan();//按键扫描
-
- if(KeyIsPress(0)) //设置值键
- {
- setFlag++;//设置标志
- if(setFlag >= 7)
- {
- setFlag = 0;//设置结束
- setTimeFlag =0;//设置结束
- LCD_Clear(Color16_BLACK);//清除液晶屏幕
- FRONT_COLOR = Color16_WHITE;//设置液晶前景色(画笔颜色)
- BACK_COLOR = Color16_BLACK;//设置液晶背景色(画布颜色)
- break;
- }
- }
- else if(KeyIsPress(1)) //设置值键+
- {
- if(setFlag == 1)if(setYear < 2999){setYear = setYear +1;}//设置年 +1
- if(setFlag == 2)if(setMonth < 12 ){setMonth = setMonth +1;}//设置月
- if(setFlag == 3)if(setDay < 31 ){setDay = setDay +1;}//设置日
- // 不设置 周 周是自动的
- if(setFlag == 4)if(setHour < 23 ){setHour = setHour +1;}//设置时
- if(setFlag == 5)if(setMin < 59 ){setMin = setMin +1;}//设置分
- if(setFlag == 6)if(setSec < 59 ){setSec = setSec +1;}//设置秒
- }
- else if(KeyIsPress(2)) //设置值键-
- {
- if(setFlag == 1)if(setYear > 0 ){setYear = setYear -1;}//设置年 -1
- if(setFlag == 2)if(setMonth > 0 ){setMonth = setMonth -1;}//设置月
- if(setFlag == 3)if(setDay > 0 ){setDay = setDay -1;}//设置日
- if(setFlag == 4)if(setHour > 0 ){setHour = setHour -1;}//设置时
- if(setFlag == 5)if(setMin > 0 ){setMin = setMin -1;}//设置分
- if(setFlag == 6)if(setSec > 0 ){setSec = setSec -1;}//设置秒
- }
- My_RTC_Set(setYear,setMonth,setDay,setHour,setMin,setSec);
- FRONT_COLOR = Color16_RED;//设置液晶前景色(画笔颜色)
- for(i=1;i<7;i++) //显示设置位置
- {
- if(i == setFlag){MyLCD_ShowSetTime(1,i,">");}
- else MyLCD_ShowSetTime(1,i," ");
- }
- }
- LCD_Clear(Color16_BLACK);//清除液晶屏幕
- FRONT_COLOR = Color16_WHITE;//设置液晶前景色(画笔颜色)
- BACK_COLOR = Color16_BLACK;//设置液晶背景色(画布颜色)
- }
复制代码
以上资料51hei下载:
STM32单片机刷卡签到系统设计.7z
(11.67 MB, 下载次数: 71)
|