共享一下網上不好找到的資料,但是 缺少文件無法編譯 求指導
單片機源程序如下:
- #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)
2022-3-10 20:29 上傳
點擊文件名下載附件
|