#include "usart.h"
#include "stm32f10x.h"
#include "rc522.h"
#include "delay.h"
#include "spi_driver.h"
#include "stm32f10x_spi.h"
#include "QDTFT_demo.h"
#include "Lcd_Driver.h"
#include "GUI.h"
void RC522_IO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); //开启AFIO时钟
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE); //关闭JTAG因为要使用PB3和4
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_4;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStruct);
SPI_Configuration(SPI1);
}
/*
/////////////////////////////////////////////////////////////////////
//功 能:写RC632寄存器
//参数说明:Address[IN]:寄存器地址
// value[IN]:写入的值
/////////////////////////////////////////////////////////////////////
void WriteRawRC(unsigned char Address, unsigned char value)
{
unsigned char i, ucAddr;
RC522_SCK_RESET(); //MF522_SCK = 0;
RC522_NSEL_RESET(); //MF522_NSS = 0;
ucAddr = ((Address<<1)&0x7E);
RC522_Delay(10);
for(i=8;i>0;i--)
{
//MF522_SI = ((ucAddr&0x80)==0x80);
if((ucAddr&0x80)==0x80)
{
RC522_MOSI_SET();
}
else
{
RC522_MOSI_RESET();
}
RC522_SCK_SET(); //MF522_SCK = 1;
ucAddr <<= 1;
RC522_Delay(10);
RC522_SCK_RESET(); //MF522_SCK = 0;
RC522_Delay(10);
}
for(i=8;i>0;i--)
{
//MF522_SI = ((value&0x80)==0x80);
if((value&0x80)==0x80)
{
RC522_MOSI_SET();
}
else
{
RC522_MOSI_RESET();
}
RC522_SCK_SET(); //MF522_SCK = 1;
value <<= 1;
RC522_Delay(10);
RC522_SCK_RESET(); //MF522_SCK = 0;
RC522_Delay(10);
// MF522_SCK = 1;
// value <<= 1;
// MF522_SCK = 0;
}
RC522_NSEL_SET(); //MF522_NSS = 1;
RC522_SCK_SET(); //MF522_SCK = 1;
}
/////////////////////////////////////////////////////////////////////
//功 能:读RC632寄存器
//参数说明:Address[IN]:寄存器地址
//返 回:读出的值
/////////////////////////////////////////////////////////////////////
unsigned char ReadRawRC(unsigned char Address)
{
unsigned char i, ucAddr;
unsigned char ucResult=0;
RC522_SCK_RESET(); //MF522_SCK = 0;
RC522_NSEL_RESET(); //MF522_NSS = 0;
ucAddr = ((Address<<1)&0x7E)|0x80;
RC522_Delay(10);
for(i=8;i>0;i--)
{
// MF522_SI = ((ucAddr&0x80)==0x80);
// MF522_SCK = 1;
// ucAddr <<= 1;
// MF522_SCK = 0;
if((ucAddr&0x80)==0x80)
{
RC522_MOSI_SET();
}
else
{
RC522_MOSI_RESET();
}
RC522_SCK_SET(); //MF522_SCK = 1;
ucAddr <<= 1;
RC522_Delay(10);
RC522_SCK_RESET(); //MF522_SCK = 0;
RC522_Delay(10);
}
for(i=8;i>0;i--)
{
RC522_SCK_SET(); //MF522_SCK = 1;
ucResult <<= 1;
RC522_Delay(10);
//ucResult|=(bit)MF522_SO;
// if(RC522_MISO_STATUS==1)
// {
// ucResult|=0x01;
// }
// else
// {
// ucResult&=~0x01;
// }
ucResult |=RC522_MISO_STATUS;
RC522_SCK_RESET(); //MF522_SCK = 0;
RC522_Delay(10);
}
RC522_NSEL_SET(); //MF522_NSS = 1;
RC522_SCK_SET(); //MF522_SCK = 1;
return ucResult;
}
*/
//#define MAXRLEN 18
/////////////////////////////////////////////////////////////////////
//功 能:寻卡
//参数说明: req_code[IN]:寻卡方式
// 0x52 = 寻感应区内所有符合14443A标准的卡
// 0x26 = 寻未进入休眠状态的卡
// pTagType[OUT]:卡片类型代码
// 0x4400 = Mifare_UltraLight
// 0x0400 = Mifare_One(S50)
// 0x0200 = Mifare_One(S70)
// 0x0800 = Mifare_Pro(X)
// 0x4403 = Mifare_DESFire
//返 回: 成功返回MI_OK
/////////////////////////////////////////////////////////////////////
char PcdRequest(unsigned char req_code,unsigned char *pTagType)
{
char status;
unsigned int unLen;
unsigned char ucComMF522Buf[MAXRLEN];
ClearBitMask(Status2Reg,0x08); //清RC522寄存位
WriteRawRC(BitFramingReg,0x07); //写RC623寄存器
SetBitMask(TxControlReg,0x03); //置RC522寄存位
//
ucComMF522Buf[0] = req_code;
/////////////////////////////////////////////////////////////////////
//功 能:通过RC522和ISO14443卡通讯
//参数说明:Command[IN]:RC522命令字
// pIn [IN]:通过RC522发送到卡片的数据
// InLenByte[IN]:发送数据的字节长度
// pOut [OUT]:接收到的卡片返回数据
// *pOutLenBit[OUT]:返回数据的位长度
/////////////////////////////////////////////////////////////////////
status = PcdComMF522(PCD_TRANSCEIVE,ucComMF522Buf,1,ucComMF522Buf,&unLen);
// UART_send_byte(status);
if ((status == MI_OK) && (unLen == 0x10))
{
*pTagType = ucComMF522Buf[0];
*(pTagType+1) = ucComMF522Buf[1];
}
else
{ status = MI_ERR; // printf(".");
// Lcd_Clear(WHITE);Gui_DrawFont_GBK16(8,0,BLUE,WHITE,">>>");
}
return status;
}
/////////////////////////////////////////////////////////////////////
//功 能:防冲撞
//参数说明: pSnr[OUT]:卡片序列号,4字节
//返 回: 成功返回MI_OK
/////////////////////////////////////////////////////////////////////
char PcdAnticoll(unsigned char *pSnr)
{
char status;
unsigned char i,snr_check=0;
unsigned int unLen;
unsigned char ucComMF522Buf[MAXRLEN];
ClearBitMask(Status2Reg,0x08);
WriteRawRC(BitFramingReg,0x00);
ClearBitMask(CollReg,0x80);
ucComMF522Buf[0] = PICC_ANTICOLL1;
ucComMF522Buf[1] = 0x20;
status = PcdComMF522(PCD_TRANSCEIVE,ucComMF522Buf,2,ucComMF522Buf,&unLen);
if (status == MI_OK)
{
for (i=0; i<4; i++)
{
*(pSnr+i) = ucComMF522Buf[i];
snr_check ^= ucComMF522Buf[i];
}
if (snr_check != ucComMF522Buf[i])
{ status = MI_ERR; }
}
SetBitMask(CollReg,0x80);
return status;
}
/////////////////////////////////////////////////////////////////////
//功 能:选定卡片
//参数说明: pSnr[IN]:卡片序列号,4字节
//返 回: 成功返回MI_OK
/////////////////////////////////////////////////////////////////////
char PcdSelect(unsigned char *pSnr)
{
char status;
unsigned char i;
unsigned int unLen;
unsigned char ucComMF522Buf[MAXRLEN];
ucComMF522Buf[0] = PICC_ANTICOLL1;
ucComMF522Buf[1] = 0x70;
ucComMF522Buf[6] = 0;
for (i=0; i<4; i++)
{
ucComMF522Buf[i+2] = *(pSnr+i);
ucComMF522Buf[6] ^= *(pSnr+i);
}
CalulateCRC(ucComMF522Buf,7,&ucComMF522Buf[7]);
ClearBitMask(Status2Reg,0x08);
status = PcdComMF522(PCD_TRANSCEIVE,ucComMF522Buf,9,ucComMF522Buf,&unLen);
if ((status == MI_OK) && (unLen == 0x18))
{ status = MI_OK; }
else
{ status = MI_ERR; }
return status;
}
/////////////////////////////////////////////////////////////////////
//功 能:验证卡片密码
//参数说明: auth_mode[IN]: 密码验证模式
// 0x60 = 验证A密钥
// 0x61 = 验证B密钥
// addr[IN]:块地址
// pKey[IN]:密码
// pSnr[IN]:卡片序列号,4字节
//返 回: 成功返回MI_OK
/////////////////////////////////////////////////////////////////////
char PcdAuthState(unsigned char auth_mode,unsigned char addr,unsigned char *pKey,unsigned char *pSnr)
{
char status;
unsigned int unLen;
unsigned char i,ucComMF522Buf[MAXRLEN];
ucComMF522Buf[0] = auth_mode;
ucComMF522Buf[1] = addr;
for (i=0; i<6; i++)
{ ucComMF522Buf[i+2] =
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于STM32实现的智能门禁系统源码+项目说明.zip 蜂鸣器 LED 按键防抖 步进电机驱动 ds1302 时钟管理芯片驱动 rc-522 RFID驱动 ST7735S 128*64 彩色显示屏驱动(包含GUI) HC-SR04 超声波测距仪驱动 详细工程文件见压缩包 门禁系统test.7z
资源推荐
资源详情
资源评论
收起资源包目录
基于STM32实现的智能门禁系统源码+项目说明.zip (44个子文件)
项目说明.md 363B
门禁系统test.7z 282KB
HARDW
Picture.h 128KB
key.c 703B
Lcd_Driver.c 7KB
lcd.h 1KB
rc522.c 21KB
hcsr.h 520B
ds1302.h 1KB
lcd.c 10KB
spi_driver.c 7KB
ds1302.c 7KB
LCD_Config.h 71B
exti.c 1KB
key.h 200B
QDTFT_demo.c 3KB
beep.h 242B
w25qxx.h 3KB
renti.c 704B
dianji.h 356B
led.h 185B
timer.c 7KB
Picture.h~RF234aed6.TMP 104KB
SysTickDelay.h 365B
hcsr.c 5KB
p.h 128KB
QDTFT_demo.h 232B
dianji.c 3KB
main.h 444B
spi_driver.h 576B
GUI.h 711B
font.h 31KB
timer.h 234B
Lcd_Driver.h 3KB
renti.h 200B
GUI.c 9KB
led.c 824B
SysTickDelay.c 2KB
main.c 16KB
Picture.h~RF22dc7af.TMP 16KB
rc522.h 7KB
beep.c 909B
w25qxx.c 14KB
exti.h 184B
共 44 条
- 1
资源评论
Make程序设计
- 粉丝: 5631
- 资源: 3568
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功