/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ #include \#include \#include \#include \#include \#include \#include \
void Delay(u32 nCount);
extern u8 RxBuffer[RxBufferSize]; extern u8 UART_RX_NUM;
unsigned char CT[2];//卡类型 unsigned char SN[4]; //卡号
unsigned char write[16]
{0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10}; unsigned char read[16]
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char key[6] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
/* Private macro -------------------------------------------------------------*/ #define countof(a) (sizeof(a) / sizeof(*(a))) #define BufferSize (countof(Tx_Buffer)-1)
/* Private variables ---------------------------------------------------------*/ u8 Tx_Buffer[] = %u8 Rx_Buffer[BufferSize]; u32 FLASH_ID ;
/* Private defines -----------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/
#define ReadWriteAddr 11 //读写扇区
void main(void) {
unsigned char status; /* Infinite loop */
/*设置内部时钟16M为主时钟*/
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
= =
/*! GPIO_Init( GPIOA, GPIO_PIN_3, GPIO_MODE_OUT_PP_HIGH_FAST); InitRc522(); UART1_SendString(Tx_Buffer,BufferSize); while(1) { status = PcdRequest(PICC_REQALL,CT); /*扫描卡*/ status = PcdAnticoll(SN); /*防冲撞*/ if (status==MI_OK) { GPIO_LOW(GPIOA, GPIO_PIN_3); //寻卡成功 UART1_SendString(\ status = PcdSelect(SN); //选择要操作的卡 if (status==MI_OK) { if( MI_OK == PcdAuthState(0x60,ReadWriteAddr,key,SN) ) { status = PcdRead(ReadWriteAddr,read); if(MI_OK == status) { read[0] = 0x01; read[1] = 0x02; read[2] = 0x03; read[3] = 0x04; read[4] = 0x05; read[5] = 0x06; status = PcdWrite(ReadWriteAddr,read); UART1_SendString(\ } } } } else { GPIO_HIGH(GPIOA, GPIO_PIN_3); } Reset_RC522(); } //验证A密码 } void Delay(u32 nCount) { /* Decrement nCount value */ while (nCount != 0) { nCount--; } } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval : None */ void assert_failed(u8* file, u32 line) { /* User can add his own implementation to report the file name and line number, ex: printf(\ /* Infinite loop */ while (1) { } } #endif 搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新资格考试认证STM8 RC522 IC卡修改密码程序 全文阅读和word下载服务。
相关推荐: