1.硬件
1.正点原子战舰V3开发板
2 RC522读卡板
3 继电器+5V小灯
4 2.8寸电阻触摸屏
1.2 硬件连接
1,DS0(LED0)(连接在PB5),DS1(LED1)(连接在PE5)
2,按键KEY1(PE3)开锁/KEY2(PE2)关锁
3.继电器(连接在PE1)
4.RC522的接线(SPI1)
*1–SDA <----->PA4
*2–SCK <----->PA5
*3–MOSI <----->PA7
*4–MISO <----->PA6
*5–悬空
*6–GND <----->GND
*7–RST <----->PB0
*8–VCC <----->VCC
串口1(波特率:115200,PA9/PA10)与上位机通讯
ALIENTEK 2.8寸TFTLCD模块(通过FSMC驱动,FSMC_NE4接LCD片选/A6接RS)
2.功能实现
2.1概述
用继电器加一个5V小灯来模拟门锁的开关,用K1和K2按键来模拟钥匙开锁关锁,K1按下继电器吸合小灯亮代表门锁打开,K2按下继电器弹开小灯灭代表门锁关闭。第一种开锁方式是当刷卡匹配到正确的卡号时门锁打开,第二种开锁方式是上位机与开发板进行串口通信,上位机发送数据控制门锁,上位机采用QT编写。
2.2上位机界面
3.主要代码
while(1)
{
//01上位机开启门禁
if(USART_RX_STA&0x8000)
{
if(strcmp((char*)USART_RX_BUF,"ON") == 0)
{
LED1 = 0;
RELAY = 1;
LCD_Fill(120,100, 240,130,WHITE);
LCD_ShowString(120,100,60,24,24,"ON");
}
USART_RX_STA=0;//清空标志位
}
//02RFID刷卡
RC522_Read_ID_Once(cid);
if(strlen(cid) > 0)
{
if(((cid[0]==blue_card[0])&&(cid[1]==blue_card[1])&&(cid[2]==blue_card[2])&&(cid[3]==blue_card[3])) ||
((cid[0]==white_card[0])&&(cid[1]==white_card[1])&&(cid[2]==white_card[2])&&(cid[3]==white_card[3])))
{
memset(cid,0,sizeof(cid));
LED1 = 0; //DS1绿灯亮
RELAY = 1; //开启继电器
LCD_Fill(120,100, 240,130,WHITE);
LCD_ShowString(120,100,60,24,24,"ON");
}
else
{
LCD_ShowString(30,130,210,24,24,"NO_ACCESS");//提示没有权限
}
}
if(KEY1_PRES == KEY_Scan(1))
{
LED1 = 0; //DS1绿灯亮
RELAY = 1; //开启继电器
LCD_Fill(120,100, 240,130,WHITE);
LCD_ShowString(120,100,60,24,24,"ON");
}
else if(KEY2_PRES == KEY_Scan(1))
{
LED1 = 1;
RELAY = 0;
LCD_Fill(120,100, 240,130,WHITE);
LCD_ShowString(120,100,60,24,24,"CLOSE");
}
LED0=!LED0;
delay_ms(500);
}