共享一下网上不好找到的资料,但是 缺少文件无法编译 求指导
单片机源程序如下:
- #include <stdio.h>
- #include "..\at89x52.h"
- #include "..\Communication\Comn2.h"
- #include "..\command\comd.h"
- #include "..\thm3060\thm3060.h"
- #include "main.h"
- #define EnableInterrupt() EA =1;
- #define DisableInterrupt() EA =0;
- // FWT (FRAME WATI TIME)为最大静默时间,即读卡器发送完数据后,到开始收到卡片
- // 响应,读卡器的最大等待时间 t = FWT * 302 uS
- unsigned short FWT = 10; //设置最大等待时间为 3ms
- void main()
- {
- initial_serial();
- EnableInterrupt();
- THM_Reset();
- puts("THM3060 Demo Reader (TDR) Version 1.1\r\nCopyright by \
- LEMICRO Technology Co. Ltd 2016.10. All rights reserved.\r\r");
- puts("THM3060 working at SPI mode.\r");
- while(1)
- {
-
- printf ("TDR V1.0 >");
- deal_with_command();
- TypeB_CardRead();
- }
- }
复制代码- #include "../spi/spi.h"
- #include "THM3060.h"
- // 通过 SPI 总线写 address 寄存器的值
- extern void THM_WriteReg(unsigned char address,unsigned char content)
- {
- unsigned char temp_buff[2];
- // 写命令 BIT7 =1
- temp_buff[0] = address | 0x80;
- temp_buff[1] = content;
- // SPI 帧
- SPI_FRAME_START();
- SPI_SendBuff(temp_buff,2);
- SPI_FRAME_END();
- }
- // 通过 SPI 总线读 address 寄存器的值
- extern unsigned char THM_ReadReg(unsigned char address)
- {
- unsigned char temp_buff[1];
- // SS_N =0;
- SPI_FRAME_START();
- // 读命令 BIT7 = 0;
- temp_buff[0] = address & 0x7F;
- SPI_SendBuff(temp_buff,1);
- SPI_RecvBuff(temp_buff,1);
- //SS_N =1;
-
- SPI_FRAME_END();
- return(temp_buff[0]);
- }
- // SPI 模式等待接收结束,并读出接收数据,数据存在缓冲区 buffer 中,长度为 len
- // 返回值为接收状态
- extern unsigned char THM_WaitReadFrame(unsigned short *len, unsigned char *buffer)
- {
- unsigned char temp,temp1;
- // 等待接收结束
- while (1)
- {
- temp = THM_ReadReg(RSTAT);
- if (temp & 0x80)
- break;
- }
- // 处理返回状态状态值
- if (temp & CERR )
- temp = CERR; //碰撞错误
- else if (temp & PERR)
- temp = PERR; //奇偶校验位错误
- else if (temp & FERR)
- temp = FERR;
- else if (temp & DATOVER)
- temp = DATOVER; //数据溢出
- else if (temp & TMROVER)
- temp = TMROVER; //超时错误
- else if (temp & CRCERR)
- temp = CRCERR; //CRC 计算错误
- else
- temp = FEND; //帧正常结束
- //取得接收长度值
- *len =((unsigned short)(THM_ReadReg(RSCH)) <<8 ) + THM_ReadReg(RSCL);
- //读取接收数据
- if (*len != 0x00 )
- {
- SPI_FRAME_START();
-
- temp1 = DATA;
- SPI_SendBuff( &temp1,1);
- SPI_RecvBuff( buffer,*len);
-
- SPI_FRAME_END();
- }
- //清除状态标志
- THM_WriteReg(RSTAT,0x00);
- return (temp);
- }
- /*
- // 读取接收状态和接收长度
- extern unsigned char THM_ReadStat( unsigned short *len)
- {
-
- unsigned char temp;
- temp = THM_ReadReg(RSTAT);
- if (temp & 0x80 == 0)
- {
- *len =0;
- return 0;
- }
- else
- {
- *len =((unsigned short)(THM_ReadReg(RSCH)) <<8 ) + THM_ReadReg(RSCL);
- if (temp & CERR )
- temp = CERR;
- else if (temp & PERR)
- temp = PERR;
- else if (temp & FERR)
- temp = FERR;
- else if (temp & DATOVER)
- temp = DATOVER;
- else if (temp & TMROVER)
- temp = TMROVER;
- else if (temp & CRCERR)
- temp = CRCERR;
- else
- temp = FEND;
- }
- THM_WriteReg(RSTAT,0x00);
- return temp;
- }
- //读取接收缓冲区数据
- extern void THM_ReadBuff( unsigned short *len,unsigned char * buff)
- {
- unsigned char temp;
- if (*len != 0x00 )
- {
- SPI_FRAME_START();
-
- temp = DATA;
- SPI_SendBuff( &temp,1);
- SPI_RecvBuff( buff,*len);
-
- SPI_FRAME_END();
- }
- }
- */
- // 发送数据子程序
- extern void THM_SendFrame(unsigned char *buffer,unsigned short num)
- {
- unsigned char temp;
- THM_WriteReg(SCNTL, 0x5); //RAMPT_CLR =1,CLK_EN =1
- THM_WriteReg(SCNTL, 0x01); // RAMPT_CLK=0;
-
- temp = DATA | 0x80; //写数据寄存器命令
-
- SPI_FRAME_START();
-
- SPI_SendBuff(&temp,1);
- SPI_SendBuff(buffer,num); //写入数据
-
- SPI_FRAME_END();
-
- THM_WriteReg(SCNTL, 0x03); // SEND =1 ,开始发送
- }
- //打开射频
- extern void THM_OpenRF()
- {
- THM_WriteReg(SCNTL,0x01);
- return;
- }
-
- //关闭射频
- extern void THM_CloseRF()
- {
-
- THM_WriteReg(SCNTL,0x00);
- return;
-
- }
- extern void THM_ChangeProtBaud(unsigned char prot, unsigned char sndbaud, unsigned char rcvbaud)
- {
- THM_WriteReg( PSEL, prot | sndbaud | rcvbaud );
- return;
- }
- #if 0
- unsigned char xdata reqb[] = {0x05,0x00,0x00};
- unsigned char xdata revbuff[100] _at_ 0x000;
- void main()
- {
- unsigned short len;
- unsigned char temp;
- GPIO_DIR = 0x01;
-
- InitSPI();
- THM_OpenRF();
- while(1)
- {
-
- THM_SendFrame(reqb,3);
- temp =THM_WaitReadFrame(&len,revbuff);
- //temp = THM_ReadReg(0x05);
- }
- }
- #endif
复制代码
所有资料51hei提供下载:
基于51单片机的THM3060参考程序.7z
(216.39 KB, 下载次数: 51)
|