51单片机多路DS18B20温度测量程序
仿真文件和完整源码的下载地址:http://www.51hei.com/bbs/dpj-20600-1.html
源代码:
#include
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit RS= P2^0 ;//液晶显示引脚定义
sbit RW= P2^1 ;
sbit EN= P2^2 ;
uint t=0,dian=0;
uchar LCD_LINE_ONE[16]={"tp1: "};//定义显示屏幕
uchar LCD_LINE_TWO[16]={"tp2: "};
//uchar LCD_LINE_THR[16]={" "};
int Tm;
int fushu=0 ;
sbit DQ= P3^3;
static unsigned char get_serial[]={ //获取的八个DS18B20内部RAM64位序列号
224, 0,0,0, 184, 197, 50, 40,
215, 0,0,0, 184, 197, 51, 40
// 82, 0,0,0, 184, 197, 52, 40
// 101, 0,0,0, 184, 197, 53,40,
//60, 0,0,0, 184, 197, 54,40,
//11, 0,0,0, 184, 197, 55,40,
//47, 0,0,0, 184, 197, 56,40,
//185, 0,0,0, 184, 197, 49,40,
};
void delay( ms ) //用于液晶显示的延时函数
{
int i ;
while(ms--)
{
for(i=0 ;i<5 ;i++ ) ;
}
}
uchar Read_LCD_State() //读取液晶显示的状态
{
uchar state;
RS=0;RW=1;EN=1;delay(1);
state=P0;
EN = 0;delay(1);
return state;
}
void LCD_Busy_Wait() //如果忙则等待函数
{
while((Read_LCD_State()&0x80)==0x80);
delay(5);
}
void Write_LCD_Zhilin(uchar zl) //液晶显示写指令函数
{
LCD_Busy_Wait();
RS=0;RW=0;
EN=0;
P0=zl;
EN=1;
delay(1);
EN=0;
}
void Write_LCD_shuju(uchar date) //液晶显示写数据函数
{
LCD_Busy_Wait();
RS=1;RW=0;
EN=0;
P0=date;
EN=1;
delay(1);
EN=0;
}
void LCD_INIT()//液晶显示初始化
{
Write_LCD_Zhilin(0x38); // 显示模式设置
delay(1);
Write_LCD_Zhilin(0x01); // 显示清屏
delay(1);
Write_LCD_Zhilin(0x06); // 光标移动设置
delay(1);
Write_LCD_Zhilin(0x0c); // 开及光标设置
delay(1);
}
void Display_LCD_String(uchar p,uchar *s) //液晶显示写入函数
{
uchar i;
Write_LCD_Zhilin(p|0x80); //写地址高位为一
//Write_LCD_Zhilin(0x40|0x80);
for(i=0;i<16;i++)
{
Write_LCD_shuju(s[i]);
delay(1);
}
}
评论