|
單片機源程序如下:
- #include "led.h"
- #include "delay.h"
- #include "sys.h"
- #include "usart.h"
- #include "lcd.h"
- #include <stdio.h>
- #include "timer.h"
- #include "lcd1602.h"
- #include "key.h"
- #include "rc522.h"
- /**************/
- unsigned char idCard[4]={0x51,0xd5,0xc1,0x2e}; //有效卡號
- /**************/
- u8 rekey = 0;//按鍵防止重復(fù)
- u8 i;
- unsigned char UID[5]; //讀取到的卡號
- unsigned char Temp[4] ;
- unsigned int relayLater =0 ;//延時計數(shù)
- unsigned char reportFlag = 0; //上報標(biāo)志
- int main(void)
- {
- delay_init(); //延時函數(shù)初始化
- uart_init(9600); //串口初始化為9600
- TIM3_Int_Init(499,7199);//50ms
- LED_Init(); //初始化與LED連接的硬件接口
- KEY_Init(); //初始化按鍵
-
- relay1 = 1;
- delay_ms(200);
- relay1 =0 ;
-
- Rc522IoInit();
- PcdReset();//復(fù)位RC522
- PcdAntennaOn();//開啟天線發(fā)射
- while(1)
- {
- if(key1==0) //檢測到按鍵按下
- {
- delay_ms(10); //小抖動
- if(rekey==0)
- {
- if(key1==0) //檢測是否按下
- {
- rekey=1;
- relay1 =1;//打開繼電器
- relayLater = 30; //延時3s
- }
- }
- }
- else
- {rekey = 0;}//防止按鍵重復(fù)操作
- if(PcdRequest(0x52,Temp)==MI_OK)//讀取到卡
- {
- if(PcdAnticoll(UID)==MI_OK)//卡號獲取成功
- {
- if((UID[0]==idCard[0])&&(UID[2]==idCard[2])&&(UID[3]==idCard[3]))//匹配卡號
- {
- relay1 =1;//打開繼電器
- relayLater = 30; //延時3s
- }
- delay_ms(10);
- }
- }
- if(reportFlag == 1)//計時操作標(biāo)志
- {
- reportFlag = 0; //清空標(biāo)志
- if(relayLater>0){relayLater--;relay1=1;}//倒計時
- else{relay1 = 0;}
- }
-
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
stm32-20、程序20181023.rar
(315.26 KB, 下載次數(shù): 146)
2018-11-21 18:27 上傳
點擊文件名下載附件
STM32,RFID 下載積分: 黑幣 -5
|
|