51单片机与DS18B20程序11.0592MHz的51单片机,Ds18b20检测温度,传给单片机,求C程序!保证时序的!
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/25 14:11:34
51单片机与DS18B20程序11.0592MHz的51单片机,Ds18b20检测温度,传给单片机,求C程序!保证时序的!
51单片机与DS18B20程序
11.0592MHz的51单片机,Ds18b20检测温度,传给单片机,求C程序!保证时序的!
51单片机与DS18B20程序11.0592MHz的51单片机,Ds18b20检测温度,传给单片机,求C程序!保证时序的!
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit DQ = P2^2; //数据口define interface
sbit dula = P2^6; //数码管段选
sbit wela = P2^7; //数码管位选
uint temp; //温度值 variable of temperature
//不带小数点
unsigned char code table[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//带小数点
unsigned char code table1[] = {0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
//
void Display(uint temp) //显示程序
{
uchar A1,A2,A3;
A1 = temp/100; //百位
A2 = temp%100/10; //十位
A3 = temp%10; //个位
dula = 0;
P0 = table[A1]; //显示百位
dula = 1; //打开段选,对应74573的锁存位,高电平不锁存
dula = 0;
wela = 0;
P0 = 0x7e;
wela = 1; //打开位选
wela = 0;
delay(0);
dula = 0;
P0 = table1[A2]; //显示十位,使用的是有小数点的数组(因为temp值扩大了10倍,虽然是十位,实际为个位)
dula = 1;
dula = 0;
wela = 0;
P0 = 0x7d;
wela = 1;
wela = 0;
delay(0);
P0 = table[A3]; //显示个位
dula = 1;
dula = 0;
P0 = 0x7b;
wela = 1;
wela = 0;
delay(0);
}
void main()
{
while(1)
{
Display(Get_Tmp());
}
}