谁能帮我把这个18B20的单片机程序改成用1602液晶显示温度,只用这个程序改,谢谢
#include<reg52.h>#include<intrins.h>#defineuintunsignedint#defineucharunsignedcharsbi...
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit ds = P2^2;
sbit dula = P2^6;
sbit wela = P2^7;
bit flag;
uint temp;
uchar ge,shi,bai;
uchar code table_du[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay (uint z)
{
uchar x,y;
for (x = z;x > 0;x--)
for (y = 110;y > 0;y--);
}
void delayus(uchar x)
{
while (x--);
}
void ds_reset ()
{
ds = 1;
delayus (5);
ds = 0;
delayus (80);
ds = 1;
delayus (14);
if (ds == 0)
flag = 1;
else
flag = 0;
delayus (20);
}
bit ds_read_bit ()
{
bit dat;
ds = 0;
_nop_();
_nop_();
ds = 1;
_nop_();
dat = ds;
delayus (10);
return dat;
}
uchar ds_read_byte ()
{
uchar i,j,k;
for (i = 0;i < 8;i++)
{
j = ds_read_bit();
k = (j<<7)|(k>>1);
}
return k;
}
void ds_write_byte (uchar dat)
{
uchar i;
for (i = 0;i < 8;i++)
{
ds = 0;
_nop_();
ds = dat&0x01;
delayus (6);
ds = 1;
dat = dat>>1;
}
delayus (6);
}
uint read_temperature()
{
uchar a,b;
ds_reset();
ds_write_byte(0xcc);
ds_write_byte(0xbe);
a = ds_read_byte();
b = ds_read_byte();
temp = b;
temp = temp<<8;
temp = temp | a;
temp = temp*0.0625*10+0.5;
return temp;
}
void display(uint temp)
{
P0 = table_du[temp/100];
dula = 1;
dula = 0;
P0 = 0xfe;
wela = 1;
wela = 0;
delay(10);
P0 = table_du[temp%100/10]|0x80;
dula = 1;
dula = 0;
P0 = 0xfd;
wela = 1;
wela = 0;
delay(10);
P0 = table_du[temp%100%10];
dula = 1;
dula = 0;
P0 = 0xfb;
wela = 1;
wela = 0;
delay(10);
}
void main()
{
while (1)
{
ds_reset ();
ds_write_byte(0xcc);
ds_write_byte(0x44);
display(read_temperature());
}
}
求大神尽快帮我解答 展开
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit ds = P2^2;
sbit dula = P2^6;
sbit wela = P2^7;
bit flag;
uint temp;
uchar ge,shi,bai;
uchar code table_du[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay (uint z)
{
uchar x,y;
for (x = z;x > 0;x--)
for (y = 110;y > 0;y--);
}
void delayus(uchar x)
{
while (x--);
}
void ds_reset ()
{
ds = 1;
delayus (5);
ds = 0;
delayus (80);
ds = 1;
delayus (14);
if (ds == 0)
flag = 1;
else
flag = 0;
delayus (20);
}
bit ds_read_bit ()
{
bit dat;
ds = 0;
_nop_();
_nop_();
ds = 1;
_nop_();
dat = ds;
delayus (10);
return dat;
}
uchar ds_read_byte ()
{
uchar i,j,k;
for (i = 0;i < 8;i++)
{
j = ds_read_bit();
k = (j<<7)|(k>>1);
}
return k;
}
void ds_write_byte (uchar dat)
{
uchar i;
for (i = 0;i < 8;i++)
{
ds = 0;
_nop_();
ds = dat&0x01;
delayus (6);
ds = 1;
dat = dat>>1;
}
delayus (6);
}
uint read_temperature()
{
uchar a,b;
ds_reset();
ds_write_byte(0xcc);
ds_write_byte(0xbe);
a = ds_read_byte();
b = ds_read_byte();
temp = b;
temp = temp<<8;
temp = temp | a;
temp = temp*0.0625*10+0.5;
return temp;
}
void display(uint temp)
{
P0 = table_du[temp/100];
dula = 1;
dula = 0;
P0 = 0xfe;
wela = 1;
wela = 0;
delay(10);
P0 = table_du[temp%100/10]|0x80;
dula = 1;
dula = 0;
P0 = 0xfd;
wela = 1;
wela = 0;
delay(10);
P0 = table_du[temp%100%10];
dula = 1;
dula = 0;
P0 = 0xfb;
wela = 1;
wela = 0;
delay(10);
}
void main()
{
while (1)
{
ds_reset ();
ds_write_byte(0xcc);
ds_write_byte(0x44);
display(read_temperature());
}
}
求大神尽快帮我解答 展开
展开全部
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit ds = P2^2;
sbit R_S=P3^5;
sbit R_W=P3^6;
sbit _E_=P3^4;
bit flag;
uint temp;
void delay (uint z)
{
uchar x,y;
for (x = z;x > 0;x--)
for (y = 110;y > 0;y--);
}
void delayus(uchar x)
{
while (x--);
}
void ds_reset ()
{
ds = 1;
delayus (5);
ds = 0;
delayus (80);
ds = 1;
delayus (14);
if (ds == 0)
flag = 1;
else
flag = 0;
delayus (20);
}
bit ds_read_bit ()
{
bit dat;
ds = 0;
_nop_();
_nop_();
ds = 1;
_nop_();
dat = ds;
delayus (10);
return dat;
}
uchar ds_read_byte ()
{
uchar i,j,k;
for (i = 0;i < 8;i++)
{
j = ds_read_bit();
k = (j<<7)|(k>>1);
}
return k;
}
void ds_write_byte (uchar dat)
{
uchar i;
for (i = 0;i < 8;i++)
{
ds = 0;
_nop_();
ds = dat&0x01;
delayus (6);
ds = 1;
dat = dat>>1;
}
delayus (6);
}
uint read_temperature()
{
uchar a,b;
ds_reset();
ds_write_byte(0xcc);
ds_write_byte(0xbe);
a = ds_read_byte();
b = ds_read_byte();
temp = b;
temp = temp<<8;
temp = temp | a;
temp = temp*0.0625*10+0.5;
return temp;
}
/**********************LCD1602*********************/
/*
函数名:LCD_BUSY()
函数功能:LCD1602读忙
输入:无
输出:无
*/
void LCD_BUSY()
{
uchar i=0;
do
{
R_S=0; //指令
R_W=1; //读
_E_=1;
i =P0;
_E_=0;
}while(i&0x80);
}
/*
函数名:LCD_Write_Byte(bit x,char value)
函数功能:LCD1602读忙
输入:x,value
输出:无
*/
void LCD_Write_Byte(bit x,char value)
{
uchar i=0;
LCD_BUSY();
if(x)
R_S=1; //数据
else
R_S=0; //指令
R_W=0; //写
P0=value;
_E_=1;
for(i=0;i<251;i++);
_E_=0;
}
/*
函数名:LCD_REST()
函数功能:LCD1602读忙
输入:无
输出:无
*/
void LCD_REST()
{
LCD_Write_Byte(0,0x38); //八位数据接口、两行显示、5*7点阵
LCD_Write_Byte(0,0x01); //清屏
LCD_Write_Byte(0,0x06); //地址自动加1
LCD_Write_Byte(0,0x0c); //开显示
}
/***************************/
void display(uint temp)
{
LCD_Write_Byte(0,0xc5); //起始地址 第二行第五列开始显示
LCD_Write_Byte(1,temp/100+48); //根据ASSIC码表数值转换
LCD_Write_Byte(1,46);//小数点
LCD_Write_Byte(1,temp/10%10+48);
LCD_Write_Byte(1,temp%10+48);
LCD_Write_Byte(1,'C');
}
void main()
{
LCD_REST();//初始化功能设置
while (1)
{
ds_reset ();
ds_write_byte(0xcc);
ds_write_byte(0x44);
display(read_temperature);
}
}
追问
不行,程序下载后1602显示L.48C,一直这样显示,没变化。
还有几个地方不明白:
void LCD_BUSY( ) 这里 i = P0和while(i&0x80);是什么意思?
ASSIC码表数值转换不是+30吗?
意法半导体(中国)投资有限公司
2023-06-12 广告
2023-06-12 广告
STM32F103是一款高性能的嵌入式芯片,由意法半导体(STMicroelectronics)公司生产。它是STM32系列芯片之一,具有紧凑、低功耗、高性能等特点,被广泛应用于嵌入式系统中。STM32F103的主要特点包括:1. 集成了A...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询