基于M453的智能家居系统设计概要:
使用先进新唐M453MCU为主控制器,集成了语音播报,生物识别技术,以及RFID(射频识别技术)设计的一款高端智能家居终端Demo,让用户可以以指纹识别和RFID两种高效安全的技术使生活更加便捷。同时3.2寸彩色触摸液晶及友好的人机交互带给用户更加完美的体验。语音及灯控,电机控制等外设模块设计的锁具终端
基于M453的智能家居设计详细说明:
本设计使用新唐提供的M451-Tiny作为基础,然后在上面进行扩展,连接了各种外设模块,如人机交互的带触摸3.2寸彩色液晶屏,成都方程式的生物识别传感器(光学指纹传感器),DC控制的继电器,电机驱动芯片+电机,RC522 RFID读卡器,SPI_Flash(W25X16)芯片等。产品的特点是操作便捷,安全性高。以指纹为例,将本套系统安装后,门锁外面只有传感器与用户接触,除了对应的注册手指外不能进行功能性操作,这款指纹传感器带有唯一的身份识别ID,可防止不法份子更换指纹传感器来开门;并且安装类类似指纹锁后,用户回家就不用带钥匙了,而且这个可比钥匙方便多了不是吗?为了进一步提高门锁的安全性,我们可以使用IC卡和指纹识别组合开门的方式……
制作出来的实物图如下:
单片机源程序如下:
- #include "main.h"
- #include "mpr121_bsp.h"
- #include "stdio.h"
- #include "stdlib.h"
- #include "esp8266_bsp.h"
- #include "uart_tft_bsp.h"
- #include "w25x16_bsp.h"
- #include "timer_delay.h"
- #include "motor_bsp.h"
- #include "lamp_bsp.h"
- #include "oled_bsp.h"
- #include "dht11_bsp.h" /* 温湿度传感器 */
- #include "rc522_bsp.h"
- #include "fp_uart_bsp.h"
- #include "voice_bsp.h"
- uint8_t IC_Card[4][5]; /* 可存4张IC卡卡号,且第二维数组每个每一个字节为有效标志0x3A时表示该号有效 */
- /****************************************************************************************************************
- *函数名称:main
- *函数功能:主函数
- *函数参数:None
- *函数返回:None
- *使用示例:None
- *CreateBy:Veiko
- *Time:2015-5-1
- ****************************************************************************************************************/
- int main(void)
- {
- uint8_t Key;
- uint8_t LED_Stu;
- unsigned int TmpID;
- unsigned int err;
- unsigned int MidDid;
- uint8_t DHT11_data[4];
- uint8_t i;
-
- SYS_Init();
- CLK_SetSysTickClockSrc(CLK_CLKSEL0_STCLKSEL_HXT); /* Select SysTick clock source as HXT */
-
- LED_GPIO_Initize();
- motor_Pin_initize(); /* 初始化电机控制引脚 */
- LAMP_Pin_Initize(); /* 初始化灯控制引脚 */
- Open_SPI_Flash();
- TIMER0_Init_Period(0);
- TIMER1_Init_Period(1);
- OLED_Init();
- InitRc522();
- BLH3001_Initize();
- Voice_SetVoice(30);
- Voice_BusyPinInitize();
- while(1)
- {
- TFT_Function();
-
- if(USER_MatchIC() == true)
- {
- Voice_playMusic(5); /* 验证成功 */
- Motor_Door_ZhengZhuan();
- TIMER0_DelayNPeriod(150000); /* 开门 */
- Motor_Door_TingZhi();
- Voice_playMusic(3); /* 门已打开请转动把手开门 */
- TIMER0_DelayNPeriod(500000); /* 开门延时 */
- Motor_Door_FanZhuan();
- TIMER0_DelayNPeriod(150000); /* 开门 */
- Motor_Door_TingZhi();
- }
-
- if(UserGetBLH_INT() == true)
- {
- if(Fp_match_D(0,99 ,&TmpID, &err) == FPR_OK)
- {
- Voice_playMusic(5); /* 验证成功 */
- Motor_Door_ZhengZhuan();
- TIMER0_DelayNPeriod(150000); /* 开门 */
- Motor_Door_TingZhi();
- Voice_playMusic(3); /* 门已打开请转动把手开门 */
- TIMER0_DelayNPeriod(500000); /* 开门延时 */
- Motor_Door_FanZhuan();
- TIMER0_DelayNPeriod(150000); /* 开门 */
- Motor_Door_TingZhi();
- }
- else
- {
- Voice_playMusic(4); /* 验证失败 */
- TIMER0_DelayNPeriod(300000); /* 延时 */
- }
- }
- }
- }
- void USER_DelFP(void)
- {
- unsigned int IDTmp,err;
-
- Voice_playMusic(24); /* 请按手指删除指纹 */
-
- if(Fp_match_D(0, 99 ,&IDTmp, &err)==FPR_OK)
- {
- if(Fp_Delete(IDTmp, IDTmp,&err)== FPR_OK)
- {
- Voice_playMusic(27); /* 操作成功 */
- }
- else
- {
- Voice_playMusic(28); /* 操作失败 */
- }
- }
- else
- {
- Voice_playMusic(28); /* 操作失败 */
-
- }
- TIMER0_DelayNPeriod(300000); /* 延时 */
- }
- void USER_AddFP(void)
- {
- unsigned int IDTmp,err;
-
- Voice_playMusic(7); /* 请录入指纹 */
-
- if(FP_Enroll_D(0,99,&IDTmp,&err) == FPR_OK)
- {
- Voice_playMusic(14); /* 指纹录入成功 */
- }
- else
- {
- Voice_playMusic(15); /* 指纹录入失败 */
- }
- }
- void TFT_Function(void)
- {
- if(TFT_Command != 0) /* 表示有命令 */
- {
- switch(TFT_Command)
- {
- case TFT_CommandKaiMen:
- Voice_playMusic(5); /* 验证成功 */
- Motor_Door_ZhengZhuan();
- TIMER0_DelayNPeriod(150000); /* 开门 */
- Motor_Door_TingZhi();
- Voice_playMusic(3); /* 门已打开请转动把手开门 */
- TIMER0_DelayNPeriod(500000); /* 开门延时 */
- Motor_Door_FanZhuan();
- TIMER0_DelayNPeriod(150000); /* 开门 */
- Motor_Door_TingZhi();
-
- break;
- case TFT_CommandAddFP:
- USER_AddFP();
- break;
- case TFT_CommandDelFP:
- USER_DelFP();
- break;
- case TFT_CommandAddIC:
- USER_AddIC_Card();
- break;
- case TFT_CommandDelIC:
- USER_DeleteIC_Card();
- break;
- case TFT_CommandSWDT_LED:
- if(LAMP1_Stu() == 1)
- {
- LAMP1_ON();
- }
- else
- {
- LAMP1_OFF();
- }
- break;
- case TFT_CommandSWZL_LED:
- if(LAMP2_Stu() == 1)
- {
- LAMP2_ON();
- }
- else
- {
- LAMP2_OFF();
- }
- break;
- default:break;
- }
- TFT_Command = 0;
- }
- }
- bool USER_MatchIC(void)
- {
- uint8_t ArrayTmp[4];
- uint8_t i,j;
-
- if(USER_GetRFID_ID(ArrayTmp) == true)
- {
- for(i=0;i<4;i++)
- {
- if(IC_Card[i][0] != 0x3A)
- continue;
- for(j=0;j<4;j++)
- {
- if(ArrayTmp[j] != IC_Card[i][j+1])
- break;
- }
- if(j==4)
- {
- return 1;
- }
- }
- if(i==4)
- {
- Voice_playMusic(4); /* 验证失败 */
- TIMER0_DelayNPeriod(300000); /* 延时 */
- return 0;
- }
- }
- return 0;
- }
- void USER_DeleteIC_Card(void)
- {
- uint8_t ArrayTmp[4];
- uint8_t i,j;
- Voice_playMusic(25); /* 请刷将要删除的IC卡 */
- while(USER_GetRFID_ID(ArrayTmp) == false);
-
- for(i=0;i<4;i++)
- {
- for(j=0;j<4;j++)
- {
- if(ArrayTmp[j] != IC_Card[i][j+1])
- break;
- }
- if(j==4)
- {
- IC_Card[i][0] = 0xff; /* 清除有效标志 */
- Voice_playMusic(27); /* 操作成功 */
- break;
- }
- }
- if(i==4)
- {
- Voice_playMusic(28); /* 操作失败 */
- }
- TIMER0_DelayNPeriod(300000); /* 延时 */
- }
- void USER_AddIC_Card(void)
- {
- unsigned char CT[2];//卡类型
- unsigned char status;
- uint8_t i,j;
- for(i=0;i<4;i++)
- {
- if(IC_Card[i][0] != 0x3A)
- break;
- }
- if(i<4)
- {
- Voice_playMusic(26); /* 请刷IC卡 */
- while(USER_GetRFID_ID(&IC_Card[i][1]) == false);
- IC_Card[i][0] = 0x3A; /* 标志有效 */
- }
- Voice_playMusic(18); /* 添加IC卡成功 */
- TIMER0_DelayNPeriod(300000); /* 延时 */
- }
- /****************************************************************************************************************
- *函数名称:SYS_Init
- *函数功能:配置系统时钟树
- *函数参数:None
- *函数返回:None
- *使用示例:SYS_Init();
- *CreateBy:Veiko
- *Time:2015-5-1
- ****************************************************************************************************************/
- uint8_t USER_GetRFID_ID(uint8_t *ID_Array)
- {
- unsigned char CT[2];//卡类型
- unsigned char SN[4]; //卡号
- unsigned char status;
-
- status = PcdRequest(PICC_REQALL,CT);/*扫描卡*/
- status = PcdAnticoll(SN);/*防冲撞*/
- if (status==MI_OK)
- {
- *(ID_Array) = SN[0];
- *(ID_Array+1) = SN[1];
- *(ID_Array+2) = SN[2];
- *(ID_Array+3) = SN[3];
- return 1;
- }
- return 0;
- }
- /****************************************************************************************************************
- *函数名称:SYS_Init
- *函数功能:配置系统时钟树
- *函数参数:None
- *函数返回:None
- *使用示例:SYS_Init();
- *CreateBy:Veiko
- *Time:2015-5-1
- ****************************************************************************************************************/
- void SYS_Init(void)
- {
- /*---------------------------------------------------------------------------------------------------------*/
- /* Init System Clock */
- /*---------------------------------------------------------------------------------------------------------*/
- /* Unlock protected registers */
- SYS_UnlockReg();
- /* Enable HIRC clock (Internal RC 22.1184MHz) */
- CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);
- /* Wait for HIRC clock ready */
- CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);
- /* Select HCLK clock source as HIRC and and HCLK clock divider as 1 */
- CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));
- /* Enable HXT clock (external XTAL 12MHz) */
- CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);
- /* Wait for HXT clock ready */
- CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);
- /* Set core clock as HCLK_CLOCK */
- CLK_SetCoreClock(HCLK_CLOCK);
-
- /* Select UART module clock source as HXT and UART module clock divider as 1 */
- CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UARTSEL_HXT, CLK_CLKDIV0_UART(1));
- CLK_SetModuleClock(UART1_MODULE, CLK_CLKSEL1_UARTSEL_HXT, CLK_CLKDIV0_UART(1));
- CLK_SetModuleClock(UART2_MODULE, CLK_CLKSEL1_UARTSEL_HXT, CLK_CLKDIV0_UART(1));
-
- /* Update System Core Clock */
- /* User can use SystemCoreClockUpdate() to calculate SystemCoreClock. */
- SystemCoreClockUpdate();
-
- CLK_EnableModuleClock(I2C1_MODULE); /* Enable peripheral clock */
- CLK_EnableModuleClock(UART1_MODULE);
- CLK_EnableModuleClock(UART0_MODULE);
- CLK_EnableModuleClock(UART2_MODULE);
- /*---------------------------------------------------------------------------------------------------------*/
- /* Init I/O Multi-function */
- /*---------------------------------------------------------------------------------------------------------*/
- /* Set PD multi-function pins for UART0 RXD and TXD */
- SYS->GPD_MFPL &= ~(SYS_GPD_MFPL_PD0MFP_Msk | SYS_GPD_MFPL_PD1MFP_Msk);
- SYS->GPD_MFPL |= (SYS_GPD_MFPL_PD0MFP_UART0_RXD | SYS_GPD_MFPL_PD1MFP_UART0_TXD);
-
- /* Set PA multi-function pins for UART1 RXD and TXD */
- SYS->GPA_MFPL &= ~(SYS_GPA_MFPL_PA0MFP_Msk | SYS_GPA_MFPL_PA1MFP_Msk | SYS_GPA_MFPL_PA2MFP_Msk | SYS_GPA_MFPL_PA3MFP_Msk);
- SYS->GPA_MFPL |= (SYS_GPA_MFPL_PA0MFP_UART1_TXD | SYS_GPA_MFPL_PA1MFP_UART1_RXD |SYS_GPA_MFPL_PA2MFP_GPIO
- |SYS_GPA_MFPL_PA3MFP_GPIO);
-
- /* I2C1: GPE0=SDA, GPC4=SCL*/
- SYS->GPE_MFPL &= ~(SYS_GPE_MFPL_PE0MFP_Msk);
- SYS->GPE_MFPL |= SYS_GPE_MFPL_PE0MFP_I2C1_SDA;
- SYS->GPC_MFPL &= ~(SYS_GPC_MFPL_PC4MFP_Msk);
- SYS->GPC_MFPL |= SYS_GPC_MFPL_PC4MFP_I2C1_SCL;
-
- /* UART2:PC2 PC3 */
- SYS->GPC_MFPL &= ~(SYS_GPC_MFPL_PC2MFP_Msk | SYS_GPC_MFPL_PC3MFP_Msk);
- SYS->GPC_MFPL |= (SYS_GPC_MFPL_PC2MFP_UART2_TXD| SYS_GPC_MFPL_PC3MFP_UART2_RXD);
-
- /* PB1-WakePin */
- SYS->GPB_MFPL &= ~(SYS_GPB_MFPL_PB1MFP_Msk);
- SYS->GPB_MFPL |= (SYS_GPB_MFPL_PB1MFP_GPIO);
-
- /* PB8-语音的BUSY检测引脚
- PB9 and PB10为浇花电机控制引脚
- */
- SYS->GPB_MFPH &= ~(SYS_GPB_MFPH_PB8MFP_Msk| SYS_GPB_MFPH_PB9MFP_Msk | SYS_GPB_MFPH_PB10MFP_Msk);
- SYS->GPB_MFPH |= (SYS_GPB_MFPH_PB8MFP_GPIO | SYS_GPB_MFPH_PB9MFP_GPIO | SYS_GPB_MFPH_PB10MFP_GPIO);
-
- /* Lock protected registers */
- SYS_LockReg();
-
- UART_Open(UART0, 9600);
-
- UART_Open(UART1, 9600);
- UART_EnableInt(UART1, UART_INTEN_RDAIEN_Msk); /* 使能UART1的接收中断功能 */
-
- UART_Open(UART2, 115200);
- UART_EnableInt(UART2, UART_INTEN_RDAIEN_Msk); /* 使能UART1的接收中断功能 */
-
- UART_Open(UART3, 115200);
- UART_EnableInt(UART3, UART_INTEN_RDAIEN_Msk); /* 使能UART1的接收中断功能 */
- }
- /******************************************************End*******************************************************/
-
复制代码
Keil代码下载(需要安装相应芯片的库才能打开):
MDK工程文件(程序源文件)--请合用MDK 5.15打开.7z
(3.48 MB, 下载次数: 19)
|