使用MSP430单片机控制超声波测距并使用5110显示
1使用MSP430单片机控制超声波测距并使用5110显示.zip
(68.26 KB)
#include "MSP430X14X.H"
#include "cry1602.h"
#include "ds18b20.h"
#include "SR04.H"
#define uint unsigned int
#define uchar unsigned char
#define CPU (8000000)
#define delay_us(x) (__delay_cycles((double)x*CPU/1000000.0))
#define delay_ms(x) (__delay_cycles((double)x*CPU/1000.0))
#define dely_s(x) (__delay_cycles((double)x*CPU/1.0))
extern unsigned char Ds_Temp[6];
unsigned char SR_Temp[6];
void Display_DS18b20()
{
Disp1Char(0,0,'T');
Disp1Char(1,0,'E');
Disp1Char(2,0,'M');
Disp1Char(3,0,'P');
Disp1Char(4,0,':');
Disp1Char(10,0,0xDF);
Disp1Char(11,0,'C');
}
void Display_LCD1602()
{
Disp1Char(0,1,'S');
Disp1Char(1,1,'p');
Disp1Char(2,1,'e');
Disp1Char(3,1,'e');
Disp1Char(4,1,'d');
Disp1Char(5,1,':');
}
void main( void )
{
unsigned char i;
/// long SR_Long;
float DS_Temp;
WDTCTL=WDTPW+WDTHOLD;
/*------选择系统主时钟为8MHz-------*/
BCSCTL1 &= ~XT2OFF; //打开XT2高频晶体振荡器
do
{
IFG1 &= ~OFIFG; //清除晶振失败标志
for (i = 0xFF; i > 0; i++); //等待8MHz晶体起振
}
while ((IFG1 & OFIFG)); //晶振失效标志仍然存在?
BCSCTL2 |= SELM_2 + SELS; //MCLK和SMCLK选择高频晶振
// TACTL |= TASSEL_2 + ID_3; //选择SMCLK为时钟,并且8分频
SR_Init();
LcdReset(); //初始化1602;
Init_18B20(); //初始化DS10B20;
Display_DS18b20();
Display_LCD1602();
while(1)
{
SR_Start();
DS_Temp=DoTransform();
DispStr(5,0,Ds_Temp);
/* SR_Long=SR_DoTrans(DS_Temp);
if(SR_Long!=SR_ERROR)
{
SR_Temp[0]=SR_Long/100+0x30;
SR_Temp[1]='.';
SR_Temp[2]=(SR_Long/10)%10+0x30;
SR_Temp[3]=(SR_Long)%10+0x30;
SR_Temp[4]='M';
SR_Temp[5]='\0';
DispStr(6,1,SR_Temp);
}*/
// SR_Start();
// SR_DoTrans();
//DelayNus(40000);
// DelayNus(40000);
}
}
|