#include <msp430x14x.h>
#include"1602.h"
#include"18b20.h"
#define CPU_F ((double)8000000)
#define Delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define Delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
//P20为TRIG口 P11为Ecoh口
#define Trig_H P2OUT|=BIT0;
#define Trig_L P2OUT&=~BIT0;
uchar table[]="Distance:" ;
uint lastCCR0;
uint j;
uint JIU_L=0,k,wan=0,qian=0,bai=0,shi=0,ge=0;
/*************************主函数*************************/
void main( void )
{
P1DIR=0XFF;P1OUT = 0XFF;
P2DIR = 0XFF;P2OUT = 0XFF;
P3DIR = 0XFF;P3OUT = 0XFF;
P4DIR = 0XFF;P4OUT = 0XFF;
P5DIR = 0XFF;P5OUT = 0XFF;
P6DIR = 0XFF;P6OUT = 0XFF;
WDTCTL = WDTPW + WDTHOLD; //关狗
BCSCTL1=RSEL2+RSEL1+RSEL0;//XT2 开启 LFXT1 工作在低频模式 ACLK
DCOCTL=DCO2+DCO1+DCO0;//DCO 为最高频率
TACTL|=TASSEL_1+MC_2+TACLR;
CCTL0=CM_3+CCIS_0+SCS+CAP+CCIE;
k=0;
j=0;
lastCCR0=0;
CCR0=0;
LcdReset();
zifuchuan("Temper is:");
write_com(0x80+0x40);
zifuchuan("Distance:");//循环读数显示
_EINT(); //打开全局中断
while(1)
{
display(Do1Convert());
Trig_H;
Delay_us(30);
Trig_L;
JIU_L =(int)((float)k*100*1700/32768);
if(JIU_L>4500)
JIU_L=0;
//qian=JIU_L/1000;
bai=(JIU_L%1000)/100;
shi=(JIU_L%100)/10;
ge=JIU_L%10;
write_com(0x80+0X40+9);
//write_data(0x30+qian);显示温度 不显示 测距!!
write_data(0x30+bai);
write_data(0x2e);
write_data(0x30+shi);
write_data(0x30+ge);
write_data('m');
}
}
#pragma vector=
tiMERA0_VECTOR
__interrupt void timerccro(void)
{
k=CCR0-lastCCR0;
lastCCR0=CCR0;
}
Delay_us(30);
Trig_L;
JIU_L =(int)((float)k*100*1700/32768);
if(JIU_L>4500)
这块有问题,Trig先发送一个不少于18us的高电平,然后再发出低电平,接下来还要判断Echo
一周热门 更多>