//实现门禁卡功能
//刷卡实现LCD灯亮 + 12864LCD屏幕显示相应内容
屏幕效果如下:
-
- //
- //===========================================================================//
- /********************************************************************
- //MSP430F149单片机 + RC522 +M1
- //实现门禁卡功能
- //刷卡实现LCD灯亮 + 12864LCD屏幕显示相应内容
- //调试环境:IAR + MSP430F149 +RC522
- //作者:孙登波 119104010574
- //时间:2019.09.10
- ********************************************************************/
- #include "msp430x14x.h"
- #include "PIN_DEF.H"
- #include "RC522.H"
- #include "UART0_Func.c"
- #include "ctype.h"
- #include "BoardConfig.h"
- #include "lcd.h"
- #include "led8run.h"
-
- unsigned char UID[5],Temp[4] ;
- unsigned char RF_Buffer[18] ;
- unsigned char Password_Buffer[6]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF} ; // Mifare One 缺省密码
- char MBRX[30] ;
- char MBKeyTP[30] ;
- char Event ;
- unsigned char DISP_MODE,i ; // 编辑控件显示模式
- unsigned char des_on = 0 ; // DES加密标志
- void Key_TP_Task(void) ;
-
- //***************************************************************************//
- // //
- // 初始化主时钟: MCLK = XT1×(FLL_FACTOR+1) //
- // //
- //***************************************************************************//
- void Init_CLK(void)
- {
- unsigned int qq;
- WDTCTL = WDTPW + WDTHOLD ; // 关看门狗
- BCSCTL1 &= ~XT2OFF; //打开XT2高速晶体振荡器
- do
- {
- IFG1 &= ~OFIFG; //Clear oscFault flag清除振荡器失效标志
- for(qq=0xff;qq>0;qq--);
- }while((IFG1&OFIFG)); //oscFault flag still set
-
- BCSCTL2 |= SELM_2; //MCLK=XT2
- //BCSCTL2 |= DIVM_0; //控制MCLK不分频,默认
-
- BCSCTL2 |= SELS; //SMCLK=XT2
- //BCSCTL2 |= DIVS_0; //控制SMCLK不分频,默认
- }
-
- void Delay(unsigned int time)
- {
- unsigned int i,k ;
- for(i=0;i<255;i++)
- for(k=0;k<time;k++)
- _NOP() ;
- }
-
- void Init_Port(void)
- {
- P4DIR = RF_LPCTL + RF_SS + RF_SCLK + RF_DATA_OUT ;
- P2DIR |= BIT0+RF_LPCTL + RF_SS + RF_SCLK + RF_DATA_OUT;
- P1DIR = RF_LPCTL + RF_SS + RF_SCLK + RF_DATA_OUT ;
- }
-
- void main( void )
- {
- unsigned char status;
- WDTCTL = WDTPW + WDTHOLD ; // 关看门狗
- BoardConfig(0xf0);
- Init_Port();
- InitUART();
- _EINT() ;
- loop:lcd_welcome();
- PcdReset();//复位RC522
- PcdAntennaOn();//开启天线发射
- while(1)
- {
- status = PcdRequest(PICC_REQIDL, Temp); ////寻卡,输出为卡类型
- if (status == MI_OK)
- status = PcdAnticoll(UID); //防冲撞处理,输出卡片序列号,4字节
- if (status == MI_OK)
- status = PcdSelect(UID); //选择卡片,输入卡片序列号,4字节
- if (status == MI_OK)
- status = PcdAuthState(PICC_AUTHENT1A, 1, Password_Buffer, UID); //在进行读写操作之前需要先进行认
- if (status == MI_OK)
- {
- led_run();
- lcd_success();
- Delay(2500);
- goto loop;
- }
-
- }
- }