今天搞了一下TN9模块,就是红外体温计模块。
代码:
#include "ac78xx_gpio.h"
#include "ac78xx_debugout.h"
#include "ac78xx.h"
#define uchar unsigned char
#define uint unsigned int
/* makesure n < 16 */
#define PAout(n) BIT_ADDR(GPIOA_ODR_ADDR, n)
#define PAin(n) BIT_ADDR(GPIOA_IDR_ADDR, n)
#define PBout(n) BIT_ADDR(GPIOB_ODR_ADDR, n)
#define PBin(n) BIT_ADDR(GPIOB_IDR_ADDR, n)
#define PCout(n) BIT_ADDR(GPIOC_ODR_ADDR, n)
#define PCin(n) BIT_ADDR(GPIOC_IDR_ADDR, n)
#define PDout(n) BIT_ADDR(GPIOD_ODR_ADDR, n)
#define PDin(n) BIT_ADDR(GPIOD_IDR_ADDR, n)
#define PEout(n) BIT_ADDR(GPIOE_ODR_ADDR, n)
#define PEin(n) BIT_ADDR(GPIOE_IDR_ADDR, n)
/* gpio bit-band control */
#define LED PAout(0)
void ACK_0() { PBout(14)=0;} //
void ACK_1() { PBout(14)=1;}
#define DATA PBin(10)
#define CLOCK PBin(12)
float Temp;
float Temp1,Temp2;
unsigned char ReadData[5];
unsigned int a,b;
//-----------------------------------------------------------------------------------------
//????:Delay()
//? ?:?????
//-----------------------------------------------------------------------------------------
void Delay(unsigned char us) //5,7,9
{
while(--us);
}
//-----------------------------------------------------------------------------------------
//????:Delayms()
//-----------------------------------------------------------------------------------------
void Delayms(unsigned int ims)
{
unsigned int i,j;
for(i=0;i<ims;i++)
for(j=0;j<65;j++) { Delay(1); }
}
void TN_IRACK_EN(void)
{
ACK_0();
Delay(1);
}
void TN_IRACK_UN(void)
{
ACK_1();
Delay(1);
}
void InitIO(void)
{
GPIO_SetDir(GPIO_PB10, 0);
GPIO_SetDir(GPIO_PB12, 0);
GPIO_SetDir(GPIO_PB14, 1);
}
void TN_ReadData(unsigned char Flag)
{
unsigned char i,j,k,BitState=0;
for(k=0;k<7;k++)
{
for(j=0;j<5;j++)
{
for(i=0;i<8;i++)
{
while(1)
{
if(CLOCK==0)
break;
Delay(1);
}
Delay(1);
if(DATA==1)
BitState=1;
else
BitState=0;
ReadData[j]= ReadData[j]<<1;
ReadData[j]= ReadData[j]|BitState;
Delay(1);
while(1)
{
if(CLOCK==1)
break;
Delay(1);
}
}
}
if(ReadData[0]==Flag)
k=8;
}
TN_IRACK_UN();
}
float TN_GetData(unsigned char X)
{
//Ack_Clk_Data_init;
InitIO();
TN_ReadData(X);
Temp=(ReadData[1]<<8)|ReadData[2];
Temp=(float)Temp/16.00-273.15;
return Temp;
}
float TN_GetTemp(unsigned char mode)
{
float T;
{
TN_IRACK_UN();
TN_IRACK_EN();
if(mode==0)
{
T=TN_GetData(0x4c);
}
else
{
T=TN_GetData(0x66);
}
}
return T;
}
/**
* main
*
* @param[in] none
* @return none
*
* @brief entry
*
*/
int main(void)
{
InitDebug(); //´òÓ¡³õʼ»¯
InitDelay(); //ÑÓʱº¯Êý³õʼ»¯
GPIO_SetDir(GPIO_PA0, 1);
GPIO_SetDir(GPIO_PA2, 1);
GPIO_SetDir(GPIO_PA4, 1);
InitIO();
while (1)
{
Temp1=TN_GetTemp(0);
Temp2=TN_GetTemp(1);
//a=((unsigned int)(Temp1*10));
//b=((unsigned int)(Temp2*10));
printf("T1: %f\r\n",Temp1);
printf("T2: %f\r\n",Temp2);
LED = !LED;
mdelay(500);
}
}
效果图:
T1是人体温度,哈一口气温度就上升。T2是环境温度。
|