stc89c52+18b20共同完成溫度采集
涉及硬件架構(gòu):設(shè)計使用的的是stc89c52——18b20共同完成溫度采集和數(shù)據(jù)處理。
本文引用地址:http://cafeforensic.com/article/201611/323568.htmstc89c52和18b20使用標準連接配置,具體可參考兩個原件的標準推薦連接。實時時鐘使用11.592m的。方便計算周期誤差。
電源考慮到實際使用配置,由原來的預(yù)想外接電源供電改為了電池連接加lm7805實現(xiàn)。
keil在win7下安裝比較費時費力。
18b20的hex文件無法打開,注意保存好源代碼,便于更改。
主程序使用的不間斷循環(huán)檢測,以便于防止程序進入死循環(huán),不能反映溫度調(diào)整后的狀態(tài)。
本程序版權(quán)所有:http://www.51hei.com ,可以任意轉(zhuǎn)載.
主程序設(shè)計如下:
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define uint unsigned int
sbit DQ =P3^5; //定義DS18B20通信端口
sbit lcd_rs_port = P1^7; /*定義LCD控制端口*/
sbit lcd_rw_port = P1^6;
sbit lcd_en_port = P2^4;
#define lcd_data_port P0
sbit beep=P2^7;
sbit dula=P3^7;
sbit lcd_rs_port = P1^7; /*定義LCD控制端口*/
sbit lcd_rw_port = P1^6;
sbit lcd_en_port = P2^4;
#define lcd_data_port P0
sbit beep=P2^7;
sbit dula=P3^7;
//////////////以下是LCD1602驅(qū)動程序////////////////
void lcd_delay(uchar ms)/*LCD1602 延時*/
{
uchar j;
while(ms--)
{
for(j=0;j<250;j++)
{;}
}
}
{
uchar j;
while(ms--)
{
for(j=0;j<250;j++)
{;}
}
}
void lcd_busy_wait() /*LCD1602 忙等待*/
{
dula=1;
lcd_rs_port = 0;
lcd_rw_port = 1;
lcd_en_port = 1;
lcd_data_port = 0xff;
while (lcd_data_port&0x80);
lcd_en_port = 0;
}
void lcd_command_write(uchar command) /*LCD1602 命令字寫入*/
{
dula=1;
lcd_busy_wait();
lcd_rs_port = 0;
lcd_rw_port = 0;
lcd_en_port = 0;
lcd_data_port = command;
lcd_en_port = 1;
lcd_en_port = 0;
}
void lcd_system_reset() /*LCD1602 初始化*/
{
lcd_delay(20);
lcd_command_write(0x38);
lcd_delay(100);
lcd_command_write(0x38);
lcd_delay(50);
lcd_command_write(0x38);
lcd_delay(10);
lcd_command_write(0x08);
lcd_command_write(0x01);
lcd_command_write(0x06);
lcd_command_write(0x0c);
}
{
lcd_delay(20);
lcd_command_write(0x38);
lcd_delay(100);
lcd_command_write(0x38);
lcd_delay(50);
lcd_command_write(0x38);
lcd_delay(10);
lcd_command_write(0x08);
lcd_command_write(0x01);
lcd_command_write(0x06);
lcd_command_write(0x0c);
}
void delay()
{
uint i;
for(i=1000;i>0;i--);
}
{
uint i;
for(i=1000;i>0;i--);
}
void lcd_char_write(uchar x_pos,y_pos,lcd_dat) /*LCD1602 字符寫入*/
{
dula=1;
x_pos &= 0x0f; /* X位置范圍 0~15 */
y_pos &= 0x01; /* Y位置范圍 0~ 1 */
if(y_pos==1) x_pos += 0x40;
x_pos += 0x80;
lcd_command_write(x_pos);
lcd_busy_wait();
lcd_rs_port = 1;
lcd_rw_port = 0;
lcd_en_port = 0;
lcd_data_port = lcd_dat;
lcd_en_port = 1;
lcd_en_port = 0;
}
{
dula=1;
x_pos &= 0x0f; /* X位置范圍 0~15 */
y_pos &= 0x01; /* Y位置范圍 0~ 1 */
if(y_pos==1) x_pos += 0x40;
x_pos += 0x80;
lcd_command_write(x_pos);
lcd_busy_wait();
lcd_rs_port = 1;
lcd_rw_port = 0;
lcd_en_port = 0;
lcd_data_port = lcd_dat;
lcd_en_port = 1;
lcd_en_port = 0;
}
void lcd_bad_check() /*LCD1602 壞點檢查*/
{
char i,j;
for(i=0;i<2;i++){
for(j=0;j<16;j++) {
lcd_char_write(j,i,0xff);
}
}
lcd_delay(200);
lcd_delay(200);
lcd_delay(200);
lcd_delay(100);
lcd_delay(200);
lcd_command_write(0x01); /* clear lcd disp */
}
//////////////////以上是LCD1602驅(qū)動程序////////////////
{
char i,j;
for(i=0;i<2;i++){
for(j=0;j<16;j++) {
lcd_char_write(j,i,0xff);
}
}
lcd_delay(200);
lcd_delay(200);
lcd_delay(200);
lcd_delay(100);
lcd_delay(200);
lcd_command_write(0x01); /* clear lcd disp */
}
//////////////////以上是LCD1602驅(qū)動程序////////////////
關(guān)鍵詞:
stc89c5218b20共溫度采
評論