51單片機(jī)多路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[]={ //獲取的八個(gè)DS18B20內(nèi)部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 ) //用于液晶顯示的延時(shí)函數(shù)
{
int i ;
while(ms--)
{
for(i=0 ;i<5 ;i++ ) ;
}
}
uchar Read_LCD_State() //讀取液晶顯示的狀態(tài)
{
uchar state;
RS=0;RW=1;EN=1;delay(1);
state=P0;
EN = 0;delay(1);
return state;
}
void LCD_Busy_Wait() //如果忙則等待函數(shù)
{
while((Read_LCD_State()&0x80)==0x80);
delay(5);
}
void Write_LCD_Zhilin(uchar zl) //液晶顯示寫指令函數(shù)
{
LCD_Busy_Wait();
RS=0;RW=0;
EN=0;
P0=zl;
EN=1;
delay(1);
EN=0;
}
void Write_LCD_shuju(uchar date) //液晶顯示寫數(shù)據(jù)函數(shù)
{
LCD_Busy_Wait();
RS=1;RW=0;
EN=0;
P0=date;
EN=1;
delay(1);
EN=0;
}
void LCD_INIT()//液晶顯示初始化
{
Write_LCD_Zhilin(0x38); // 顯示模式設(shè)置
delay(1);
Write_LCD_Zhilin(0x01); // 顯示清屏
delay(1);
Write_LCD_Zhilin(0x06); // 光標(biāo)移動設(shè)置
delay(1);
Write_LCD_Zhilin(0x0c); // 開及光標(biāo)設(shè)置
delay(1);
}
void Display_LCD_String(uchar p,uchar *s) //液晶顯示寫入函數(shù)
{
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);
}
}
評論