今天捣鼓了一下TN9模块,红外温度计模块。
DATA:PA14
CLK:PA15
ACTION:PA10
代码:
#include "sam.h"
#define uchar unsigned char
#define uint unsigned int
#define REG_PORT_PINCFG14 (*(RwReg8 *)0x4100444EUL) /**< \brief (PORT) Pin Configuration 0 */
#define REG_PORT_PINCFG15 (*(RwReg8 *)0x4100444FUL) /**< \brief (PORT) Pin Configuration 0 */
void ACK_0() { REG_PORT_OUT0=0x000;} //
void ACK_1() { REG_PORT_OUT0=0x400;}
#define DATA ((REG_PORT_IN0 & 0x4000)>>14)
#define CLOCK ((REG_PORT_IN0 & 0x8000)>>15)
float Temp;
float Temp1,Temp2;
unsigned char ReadData[5];
//-----------------------------------------------------------------------------------------
//????: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 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)
{
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;
}
void configure_port_pins(void)
{
REG_PORT_DIR0=0x0400;
REG_PORT_OUTSET0=0xC000;
REG_PORT_PINCFG14=0x06;
REG_PORT_PINCFG15=0x06;
}
int main(void)
{
long int i;
/* Initialize the SAM system */
SystemInit();
configure_port_pins();
/* Replace with your application code */
while (1)
{
Temp1=TN_GetTemp(0);
Temp2=TN_GetTemp(1);
REG_PORT_OUT1^=0x400;
for(i=1000000;i>0;i--);
}
}
效果图:
工程:
AVR_TN9.rar
(622.17 KB)
|
@ningling_21 :你应该没接TN9.把TN9的代码去掉
@ningling_21 :这个不是闪灯程序,TN9测温程序
下载你这个程序到板子上,灯怎么不会闪呢?