#include <msp430f5529.h>
#include "Dogs102x6.h"
#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))
#define HIGH P2OUT|= BIT1;
#define LOW P2OUT &=~BIT1;
unsigned char temph,templ,humdh,humdl,check,cal;
char receive(void) //接受函数
{
unsigned char num=0,tem,cnt; //临时变量用于存储接受数据
for(cnt=0;cnt<8;cnt++)
{
tem=0;
while(!(P2IN&BIT1)); //等待14us的低电平结束
delay_us(30);
if((P2IN&BIT1)) /////////长于30us定义为1
{
tem=1;
while((P2IN&BIT1)); //等待一位的采集结束
}
num<<=1;
num|=tem;
}
return num;
}
void receive_init()
{
P2DIR|=BIT1;
LOW;
delay_ms(20);
HIGH;
delay_us(30); //20--40
P2DIR &=~BIT1;
if(!(P2IN&BIT1)); //从机发出响应信号
{
while(!(P2IN&BIT1));//等待响应响应结束
while((P2IN&BIT1));//开始采集
humdh=receive();
humdl=receive();
temph=receive();
templ=receive();
check=receive();
}
}
void main( void )
{
unsigned char str1[7]={};
unsigned char str2[6]={};
WDTCTL=WDTPW+WDTHOLD;
UCSCTL4 |= SELS__DCOCLK ;
// Ini_Lcd();
Dogs102x6_init();
Dogs102x6_clearScreen(); //清屏
// show_
tishi();
while(1)
{
receive_init();
str1[0] =humdh/10;
str1[1] =humdh%10;
str1[2] ='.'; //小数点
//湿度小数部分
str1[3] = humdl/10;
str1[4] = '%'; //"%"
str1[5] = 'R'; //"R"
str1[6] = 'H'; //"H"
//温度整数部分
str2[0] =temph/10;
str2[1] =temph%10;
str2[2] ='.'; //小数点
//温度小数部分
str2[3] = templ/10;
str2[4] = '`';
str2[5] = 'C'; //"C"*/
cal=humdh+humdl+temph+templ;
if(cal==check)
{
Dogs102x6_init();//初始化LCD
Dogs102x6_backlightInit();
Dogs102x6_setContrast(15); //设置对比度
Dogs102x6_setBacklight(11);//设置背光度
Dogs102x6_charDraw(1, 1, str1[0], 0);
Dogs102x6_charDraw(1, 11, str1[1], 0);
Dogs102x6_charDraw(1, 23, str1[2], 0);
Dogs102x6_charDraw(1, 34, str1[3], 0);
Dogs102x6_charDraw(1, 45, str1[4], 0);
Dogs102x6_charDraw(1, 54, str1[5], 0);
Dogs102x6_charDraw(1, 64, str1[6], 0);
Dogs102x6_charDraw(2, 1, str2[0], 0);
Dogs102x6_charDraw(2, 12, str2[1], 0);
Dogs102x6_charDraw(2, 22, str2[2], 0);
Dogs102x6_charDraw(2, 32, str2[3], 0);
Dogs102x6_charDraw(2, 42, str2[4], 0);
Dogs102x6_charDraw(2, 52, str2[5], 0);
}
}
}
为什么温度湿度显示不出来,只显示一个点。如下图
一周热门 更多>