欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
ds18b20溫度測量c51單片機程序 源代碼
[打印本頁]
作者:
niujia
時間:
2015-7-15 23:35
標題:
ds18b20溫度測量c51單片機程序 源代碼
數碼管顯示部分的原理圖(開發板中只需要截圖顯示部分即可):
http://www.raoushi.com/f/51hei-5.pdf
電路:ds18b20接在p2.2 數碼管用8位共陰極數碼管,2個573鎖存 詳見上面的51hei單片機開發板的pdf圖,本人測試成了.
程序源代碼:
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit wela=P2^7;
sbit dula=P2^6;
sbit DS=P2^2;
uchar A;
uint dian;
uchar smg_change[6]={10,10,10,10,10,10};
unsigned char code duanma[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};
unsigned char code weima[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
void delay(unsigned int a)
{
while(a--);
}
void init_tempr()
{
uchar n;
DS=1;
delay(8);
DS=0;
delay(80); //500us
DS=1;
delay(8);
n=DS;
delay(4);
}
void write_byte(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
DS=0;
DS=dat&0x01;
delay(4);
DS=1;
dat>>=1;
}
delay(4);
}
uchar read_byte(void)
{
uchar i,value;
for(i=0;i<8;i++)
{
DS=0;
value>>=1;
DS=1;
if(DS)
value|=0x80;
delay(4);
}
return value;
}
uchar readtempr(void)
{
uint temp, a,b;
init_tempr();
write_byte(0xcc);
write_byte(0x44);
delay(300);
init_tempr();
write_byte(0xcc);
write_byte(0xbe);
a=read_byte();
b=read_byte();
temp=b;
temp<<=4;
temp+=(a&0xf0)>>4;
dian=(a&0x0f)*10*6/10;
return temp;
}
void display()
{
uchar i;
for(i=0;i<6;i++)
{
P0=0X00;
dula=1;
dula=0;
P0=weima[i];
wela=1;
wela=0;
P0=duanma[smg_change[i]];
dula=1;
dula=0;
delay(200);
}
P0=weima[1];
wela=1;
wela=0;
P0=duanma[smg_change[1]]|0x80;
dula=1;
dula=0;
delay(200);
P0=0X00;
dula=1;
dula=0;
}
void dis_deal()
{
smg_change[0]=A/10;
smg_change[1]= A%10;
smg_change[2]=dian/10 ;
smg_change[3]=dian%10 ;
}
void main()
{
while(1)
{
A=readtempr();
dis_deal();
display();
}
}
復制代碼
作者:
傻傻的遠遠
時間:
2018-12-11 11:09
你好,為什么我這只顯示了兩個8啊。根本沒有變化
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1