标题:
数码管温度显示程序,有没有大神帮忙看看哪里出错了
[打印本页]
作者:
AmonMU
时间:
2019-1-24 16:02
标题:
数码管温度显示程序,有没有大神帮忙看看哪里出错了
温度.PNG
(57.55 KB, 下载次数: 27)
下载附件
2019-1-24 16:01 上传
#include"reg51.h"
#define uchar unsigned char
#define uint unsigned int
#include"intrins.h"
sbit DQ=P3^7;
sbit P20=P3^0;
sbit P21=P3^1;
sbit P22=P3^2;
sbit P23=P3^3;
sbit P24=P0^0;
code uchar tab[]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90};
code uchar tab1[]={0X40,0X79,0X24,0X30,0X19,0X12,0X02,0X78,0X00,0X10};
uchar a,b,t,h;
uchar bai,shi,ge,xiao;
void delay(unsigned int i)
{
while(i--);
}
//初始化函数
bit int_DS18B20(void)
{
unsigned char x=0;
DQ=1;
delay(8);
DQ=0;
delay(80);
DQ=1;
delay(14);
x=DQ;
delay(30);
return x;
}
//读一个字节
read(void)
{
unsigned char i=0;
unsigned char dat=0;
for(i=8;i>0;i--)
{
DQ=0;
dat>>=1;
DQ=1;
if(DQ)
dat|=0x80;
delay(4);
}
return(dat);
}
//写一个字节
write(unsigned char dat)
{
unsigned char i=0;
for(i=8;i>0;i--)
{
DQ=0;
DQ=dat&0x01;
delay(5);
DQ=1;
dat>>=1;
}
delay(4);
}
//启动转换
void int_(void)
{
while(int_DS18B20());
write(0xCC);
write(0x44);
}
void main(void)
{
uint count=0;
P3=0X00;
int_();
delay(2200);
for(count=0;count<1000;count++)
{
P20=1;
P1=tab[0];
delay(30);
P20=0;
P21=1;
P1=tab[0];
delay(30);
P21=0;
P22=1;
P1=tab1[0];
delay(30);
P22=0;
P23=1;
P1=0xc6;
delay(30);
P23=0;
}
while(1)
{
delay(120);
while(int_DS18B20());
write(0xcc);
write(0xbe);
a=read();
b=read();
if(b>127)
{
a=~a;
b=~b;
a>>=4;
t=b<<4;
t=t|a;
t+=1;
shi=t/10;
ge=t-shi*10;
for(count=0;count<123;count++)
{
if(t>=10)
{
P20=1;
P1=0xbf;
delay(30);
P20=0;
P21=1;
P1=tab[shi];
delay(50);
P21=0;
P22=1;
P1=tab1[ge];
delay(30);
P22=0;
P23=1;
P1=0xc6;
delay(30);
P23=0;
}
else
{
P20=0;
P21=1;
P1=0xbf;
delay(30);
P21=0;
P22=1;
P1=tab1[ge];
delay(30);
P22=0;
P23=1;
P1=0xc6;
delay(30);
P23=0;
}
}
}
else
{
count=0;
a=a>>4;
t=b<<4;
t=t|a;
if(t>36)
{P24=0;}
else P24=1;
bai=t/100;
shi=(t-bai*100)/10;
ge=t-(bai*100+shi*10);
for(count=0;count<123;count++)
{
if(bai)
{
P20=1;
P1=tab[bai];
delay(30);
P20=0;
}
P20=0;
P21=1;
P1=tab[shi];
delay(30);
P21=0;
P22=1;
P1=tab1[ge];
delay(30);
P22=0;
P23=1;
P1=0xc6;
delay(30);
P23=0;
}
}
int_();
}
复制代码
作者:
教教我单片机把
时间:
2019-3-12 19:51
大哥大哥,我一直在找你这个数码管,请问它在DXP里如何找到?
作者:
还有谁?
时间:
2019-3-13 09:15
本帖最后由 还有谁? 于 2019-3-22 12:33 编辑
很器件在里面,看看别人怎么弄的再说
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1