我想用串口调试助手检测DHT11测到的数据,无奈水平太菜,所以跪求大神们帮助。
#include "msp430G2553.h"
#include"stdio.h"
#define DHT11_OUTPUT P2DIR|=BIT0
#define DHT11_INPUT P2DIR&=~BIT0
#define DHT11_H P2OUT|=BIT0
#define DHT11_L P2OUT&=~BIT0
#define DHT11_IN (P2IN&BIT0)
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define CPU (1000000)
#define delay_us(x) (__delay_cycles((double)x*CPU/1000000.0))
#define delay_ms(x) (__delay_cycles((double)x*CPU/1000.0))
uchar start_DHT11(void);
uchar DHT11_ReadChar(void);
void dht11(void);
uchar DHT11T_Data_H, DHT11T_Data_L, DHT11RH_Data_H, DHT11RH_Data_L,CheckData_temp;
void put(uchar *x)
{
while(*x)
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF=*x;
x++;
}
}
void putc(char *x)
{
while(*x)
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF=*x;
x++;
}
}
void wellcome()
{
put("*************************************\n");
put("******** hello,eeworld! ********\n");
put("******** this is mengzhilv! ********\n");
put("******** Copyright @ 2011 ********\n");
put("*************************************\n\n");
delay_ms(10);
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
UCA0CTL1 |= UCSWRST;
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
P1SEL = BIT1 + BIT2 ;
P1SEL2 = BIT1 + BIT2 ;
UCA0CTL1 |= UCSSEL_2;
UCA0BR0 = 104;
UCA0BR1 = 0;
UCA0MCTL = UCBRS0;
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
delay_us(1000);
wellcome();
put("**********DHT11 TEST**********\n");
delay_ms(1000);
while(1)
{
dht11();
}
}
uchar start_DHT11(void)
{
uchar TData_H_temp,TData_L_temp,RHData_H_temp,RHData_L_temp,checktemp;
uchar presence,flag;
uint count;
DHT11_OUTPUT;
DHT11_L; //拉低18ms以上
delay_ms(20);
DHT11_H;
DHT11_INPUT;
delay_us(40);
presence=DHT11_IN;
if(!presence)
{
count=2;
while((!DHT11_IN)&&count++);//等待低电平
count=2;
while((DHT11_IN)&&count++);//等待高电平
RHData_H_temp = DHT11_ReadChar();
RHData_L_temp = DHT11_ReadChar();
TData_H_temp = DHT11_ReadChar();
TData_L_temp = DHT11_ReadChar();
CheckData_temp = DHT11_ReadChar();
DHT11_OUTPUT;
DHT11_H;
checktemp = (RHData_H_temp + RHData_L_temp + TData_H_temp + TData_L_temp);
if (checktemp == CheckData_temp) {
DHT11RH_Data_H = RHData_H_temp;
DHT11RH_Data_L = RHData_L_temp;
DHT11T_Data_H = TData_H_temp;
DHT11T_Data_L = TData_L_temp;
flag=1;
}
}
P1OUT |=BIT0;
return flag;
}
uchar DHT11_ReadChar(void)
{
unsigned char dat;
unsigned int count; //计数防止死等
unsigned char i;
for(i=0;i<8;i++)
{
count=2;
while((!DHT11_IN)&&count++); //等待50us低电平结束
delay_us(40); //40us
dat <<= 1; //50us低电平+28us高电平表示'0'
if(DHT11_IN) //50us低电平+70us高电平表示'1'
dat |= 1;
count=2;
while((DHT11_IN)&&count++);
if(count==1) //超时则跳出for循环
break;
}
return dat;
}
void dht11()
{
char c[40];
uchar o;
o=start_DHT11();
P1OUT |=BIT1;
delay_ms(300);
P1OUT &=~BIT1;
delay_ms(300);
if (o)
{
put("DHT11 EXIST AND ACQUIRE SUCCESSFUL!\n");
delay_ms(10);
sprintf(c, "%d.%d %d.%d %d\r\n",DHT11RH_Data_H,DHT11RH_Data_L,DHT11T_Data_H,DHT11T_Data_L,CheckData_temp);
putc(c);
}
}
请问这个程序dht是插在哪个引脚上的?我用的是energia开发环境。本人菜鸟,大神求指教,谢谢