用18B20做温度补偿的超声波测距程序
#include
#include
#define uint unsigned int
#define uchar unsigned char
sbit rs=P1^0;
sbit rw=P1^1;
sbit en=P1^2;
sbit wave=P1^4;
uint
uchar tflag;//温度正负标志
sbit DQ=P1^3;//ds18b20与单片机连接口
char idata disp_buf1[16];//1602显示缓冲区1(即上排16个字符)
char idata disp_buf2[16];//1602显示缓冲区2(即下排16个字符)
uchar code table[]=" Celiang Ok ! ";
uchar i;
char idata julidata[3]; //存放距离值变量
uchar data disdata[4];//温度
unsigned long int JuLi;//距离
unsigned char Gao,Di;//存储计时器高位,低位
void ChuShiHua();//初始化
void FaShe();//发射声波
void Shou();//接收外部中断程序
void Deng();//空等待
void delay(uint n)
{ uchar x=0;
for(; n>0; n--)
{
for(; x<250; x++)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
void delayus(uint n)
{
while(n--);
}
void check_busy()
{
P2=0xff;
rs=0;
rw=1;
en=1;
while(P2&0x80);
en=0;
}
void lcd_wcom(uchar com)
{ check_busy();
rw=0;
rs=0;
P2=com;
en=1;
en=0;
}
void lcd_wdat(uchar dat)
{ check_busy();
rw=0;
rs=1;
P2=dat;
en=1;
en=0;
}
void lcd_init()
{
lcd_wcom(0x38),delay(1);//8位,双列,5*7
lcd_wcom(0x0c),delay(1); //开显示,关光标,光标所在字符不闪
lcd_wcom(0x06),delay(1);//显示地址递增18B20做温度补偿的超声波测距程序
lcd_wcom(0x01),delay(1); //清屏,光标移到左上角
}
void chushi_display()
{
uchar m=0;
lcd_init();
lcd_wcom(0x80);
for(m=0; m<16; m++)
{
lcd_wdat(table[m]); //将数组中字符显示出来18B20做温度补偿的超声波测距程序
delay(1000);
}
delay(100);
lcd_wcom(0x01);
}
void ds1820rst()
{ unsigned char x=0;
}
uchar ds1820rd()
{
}
void ds1820wr(uchar wdata)
{
}
read_temp()
{
}
void ds1820disp()
{
}
void updata_disp()
{
disp_buf1[0]=W, disp_buf1[1]=e;
disp_buf1[2]=n, disp_buf1[3]=D;
disp_buf1[4]=u,disp_buf1[5]=-;
disp_buf1[6]=-, disp_buf1[7]=D;
disp_buf1[8]=i,disp_buf1[9]=s;;
disp_buf1[10]=t,disp_buf1[11]=a;;
disp_buf1[12]=n,disp_buf1[13]=t;;
disp_buf1[14]=:,disp_buf1[15]=:;
disp_buf2[0]=*, disp_buf2[1]=disdata[1];
disp_buf2[2]=disdata[2],disp_buf2[3]=.;
disp_buf2[4]=disdata[3],disp_buf2[5]=-;
disp_buf2[6]=-, disp_buf2[7]=0;
disp_buf2[8]=0;
disp_buf2[9] =julidata[0]+0x30;
disp_buf2[10]=julidata[1]+0x30;
disp_buf2[11]=julidata[2]+0x30;
disp_buf2[12]=c,disp_buf2[13]=m;
disp_buf2[14]=*,disp_buf2[15]=*;
}
void display()
{
uchar i;
lcd_wcom(0x80);
for(i=0;i<16;i++)
lcd_wdat(disp_buf1[i]);
lcd_wcom(0xc0);
for(i=0;i<16;i++)
lcd_wdat(disp_buf2[i]);
}
void int_t0() interrupt 1 using 1
{
TH0=0x3c;
TL0=0xb0;
i++;
if(i== 10)
{
i=0;
}
}
void ChuShiHua()
{
IE = 0x82;
TMOD = 0x10; //定时器1模式1,定时器0模式0
PX1 = 1;
PT0 = 0;
IT1 = 0;
TR0 = 1;
wave= 0;
}
void Deng()
{
unsigned int i,j;
wave=0;
for (i = 0; i < 200; i++)
for (j = 0; j < 200; j++);
}
void FaShe()
{
IE
wave= 0;
delay(80);
TH1 = 0;
TL1 = 0;
wave=1;
TR1 = 1;
delayus(125);
wave=0;
IE=0X86;
}
void Shou() interrupt 2 //外部中断INT1
{
IE = 0; //关中断
JuLi= 0;
TR1 = 0;
Gao = TH1, Di
JuLi = JuLi | Gao, JuLi = JuLi < 8;
JuLi = JuLi | Di,JuLi = JuLi*17;
JuLi = JuLi/1000,julidata[0] = JuLi / 100;
julidata[1] = (JuLi - (julidata[0]*100))/10;
julidata[2] = JuLi, updata_disp();
IE = 0x82; //关int1中断,开显示中断http://www.jiaoqb.com/
}
main()
{
}
18B20温度补偿超声波测 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)