|
該系統(tǒng)以STM32F103C8T6為核心(可自行修改成103系列其他芯片,修改編譯參數(shù))。通過OLED 0.96顯示相關(guān)信息。通過對(duì)RFID模塊(RC522)的控制,讀取RFID標(biāo)簽的信息,并通過串口上傳(可配套相應(yīng)的上位機(jī),完成簡單的考勤,安保等系統(tǒng))
0.png (37.48 KB, 下載次數(shù): 113)
下載附件
2017-7-22 18:30 上傳
單片機(jī)源程序如下:
- #include "stm32f10x.h"
- #include "oled.h"
- #include "MAIN.h"
- #include "mfrc522.h"
- #include "usart.h"
- #include "string.h"
- unsigned char card1[4] = {0xF0,0x1C,0x70,0x3B}; //卡序列號(hào)
- unsigned char card2[4] = {0xDE,0x8A,0xDF,0x2B}; //卡序列號(hào)
- unsigned char card3[4] = {0xD2,0xB2,0x73,0x5B};
- unsigned char card4[4] = {0xB7,0x29,0xDF,0x2B};
- unsigned char snr, buf[16]="liu-bridge",bufr[16], TagType[2], SelectedSnr[4], DefaultKey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
- unsigned char Read_Data[16],PassWd[6],WriteData[16],RevBuffer[30], MLastSelectedSnr[4],NewKey[16];
- char cardID[4];
- unsigned char kahao;
- void findcard();
- void GPIO_ini()
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- /* Enable the GPIO Clock */
- RCC_APB2PeriphClockCmd(MF522_RST_CLK, ENABLE);
- /* Configure the GPIO pin */
- GPIO_InitStructure.GPIO_Pin = MF522_RST_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_Init(MF522_RST_PORT, &GPIO_InitStructure);
-
- /* Enable the GPIO Clock */
- RCC_APB2PeriphClockCmd(MF522_MISO_CLK, ENABLE);
- /* Configure the GPIO pin */
- GPIO_InitStructure.GPIO_Pin = MF522_MISO_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_Init(MF522_MISO_PORT, &GPIO_InitStructure);
-
- /* Enable the GPIO Clock */
- RCC_APB2PeriphClockCmd(MF522_MOSI_CLK, ENABLE);
- /* Configure the GPIO pin */
- GPIO_InitStructure.GPIO_Pin = MF522_MOSI_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_Init(MF522_MOSI_PORT, &GPIO_InitStructure);
-
- /* Enable the GPIO Clock */
- RCC_APB2PeriphClockCmd(MF522_SCK_CLK, ENABLE);
- /* Configure the GPIO pin */
- GPIO_InitStructure.GPIO_Pin = MF522_SCK_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_Init(MF522_SCK_PORT, &GPIO_InitStructure);
-
- /* Enable the GPIO Clock */
- RCC_APB2PeriphClockCmd(MF522_NSS_CLK, ENABLE);
- /* Configure the GPIO pin */
- GPIO_InitStructure.GPIO_Pin = MF522_NSS_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_Init(MF522_NSS_PORT, &GPIO_InitStructure);
-
- /* Enable the GPIO Clock */
- RCC_APB2PeriphClockCmd(LED_CLK, ENABLE);
- /* Configure the GPIO pin */
- GPIO_InitStructure.GPIO_Pin = LED_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_Init(LED_PORT, &GPIO_InitStructure);
- }
- void InitializeSystem()
- {
- LED_OFF;
- delay_10ms(10);
- PcdReset();
- PcdAntennaOff();
- PcdAntennaOn();
- M500PcdConfigISOType( 'A' );
- LED_ON;
- delay_10ms(10);
- LED_OFF;
- delay_10ms(10);
- LED_ON;
- delay_10ms(10);
- LED_OFF;
- }
- int i,j;
- int main(void)
- {
- char status;
- unsigned char rfidflag;
- unsigned char discnt;
- kahao=0;
- GPIO_ini();
- InitializeSystem( );
- uart_init(9600);
- OLED_Init();
- //Draw_Logo();
- for(i=0;i<2000;i++)
- for(j=0;j<2000;j++);
- OLED_Fill(0x00);
- OLED_ShowString1(0,0," RFID EPC SYS");
- OLED_ShowString1(0,3," Status: OK");
- printf("\r\n This is a RFID System \r\n");
- while(1)
- { status= PcdRequest(REQ_ALL,TagType);
- if(!status)
- {
- status = PcdAnticoll(SelectedSnr);
- if(!status)
- {
- status=PcdSelect(SelectedSnr);
- if(!status)
- {
- snr = 1; //扇區(qū)號(hào)1
- status = PcdAuthState(KEYA, (snr*4+3), DefaultKey, SelectedSnr);// 校驗(yàn)1扇區(qū)密碼,密碼位于每一扇區(qū)第3塊
- {
- if(!status)
- {
- //status = PcdRead((snr*4+0), buf); // 讀卡,讀取1扇區(qū)0塊數(shù)據(jù)到buf[0]-buf[16]
- // buf[0]=2;buf[1]=2;buf[2]=3;buf[3]=4;buf[4]=5;buf[6]=1;;buf[7]=1;buf[8]=1;buf[9]=9;
- // status = PcdWrite((snr*4+0), buf); // 寫卡,將buf[0]-buf[16]寫入1扇區(qū)0塊
- if(!status)
- {
- //讀寫成功,點(diǎn)亮LED
- LED_ON;
- PcdAuthState(KEYA, (snr*4+3), DefaultKey, SelectedSnr);
- status = PcdRead((snr*4+0), bufr);
-
- //printf(" %s \r\n",bufr );
- //printf("%s", SelectedSnr);
- findcard();
- if(kahao==1)
- { OLED_ShowString1(0,5," ID 1 Pass");
- printf("%s","#1001[ DISCUZ_CODE_0 ]quot;);
- discnt=0;
- rfidflag=1;
- }
- else if(kahao==2)
- { OLED_ShowString1(0,5," ID 2 Pass");
- printf("%s","#1002[ DISCUZ_CODE_0 ]quot;);
- discnt=0;
- rfidflag=1;
- }
- else if(kahao==3)
- { OLED_ShowString1(0,5," ID 3 Pass");
- printf("%s","#1003[ DISCUZ_CODE_0 ]quot;);
- discnt=0;
- rfidflag=1;
- }
- else if(kahao==4)
- { OLED_ShowString1(0,5," ID 4 Pass");
- printf("%s","#1004[ DISCUZ_CODE_0 ]quot;);
- discnt=0;
- rfidflag=1;
- }
- //printf(" %s %s",bufr,SelectedSnr);
- WaitCardOff();
- }
- }
- }
- }
- }
- }
- LED_OFF;
- if(rfidflag==1)
- { discnt++;
- if(discnt>200)
- { OLED_ShowString1(0,5," ");
- discnt=0;
- rfidflag=0;
- }
- OLED_DLY_ms(5);
- }
- }
- }
- void findcard()
- { unsigned char ii;
- for (ii=0;ii<4;ii++) //比較卡序列號(hào)
- { if (SelectedSnr[ii] != card1[ii])
- { kahao=0;
- break;
- }
- else
- { if (ii==3)
- { kahao=1;
- goto A;
- break;
- }
- }
- }
- for (ii=0;ii<4;ii++)
- { if (SelectedSnr[ii] != card2[ii])
- { kahao=0;
- break;
- }
- else
- { if (ii==3)
- { kahao=2;
- goto A;
- break;
- }
- }
- }
- for (ii=0;ii<4;ii++)
- { if (SelectedSnr[ii] != card3[ii])
- { kahao=0;
- break;
- }
- else
- { if (ii==3)
- { kahao=3;
- goto A;
- break;
- }
- }
- }
- for (ii=0;ii<4;ii++)
- { if (SelectedSnr[ii] != card4[ii])
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
STM32_RFID&OLED.rar
(300.1 KB, 下載次數(shù): 819)
2017-7-22 18:32 上傳
點(diǎn)擊文件名下載附件
STM32F103的RFID讀取程序 下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|