單片機(jī)51的C程序誰給解釋下?
單片機(jī)51的C程序誰給解釋下?
#include
#include
unsigned char code displaybit[]={0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f};
unsigned char code displaycode[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00,0x40};
unsigned char code dotcode[32]={0,3,6,9,12,16,19,22,
25,28,31,34,38,41,44,48,
50,53,56,59,63,66,69,72,
75,78,81,84,88,91,94,97};
unsigned char displaycount;
unsigned char displaybuf[8]={16,16,16,16,16,16,16,16};
unsigned char timecount;
unsigned char readdata[8];
sbit DQ=P3^7;
bit sflag;
bit resetpulse(void)
{
unsigned char i;
DQ=0;
for(i=255;i>0;i--);
DQ=1;
for(i=60;i>0;i--);
return(DQ);
for(i=200;i>0;i--);
}
void writecommandtods18b20(unsigned char command)
{
unsigned char i;
unsigned char j;
for(i=0;i0;j--);
DQ=1;
}
else
{
DQ=0;
for(j=2;j>0;j--);
DQ=1;
for(j=33;j>0;j--);
}
command=_cror_(command,1);
}
}
unsigned char readdatafromds18b20(void)
{
unsigned char i;
unsigned char j;
unsigned char temp;
temp=0;
for(i=0;i0;j--);
if(DQ==1)
{
temp=temp | 0x80;
}
else
{
temp=temp | 0x00;
}
for(j=200;j>0;j--);
}
return(temp);
}
void main(void)
{
TMOD=0x01;
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
ET0=1;
EA=1;
while(resetpulse());
writecommandtods18b20(0xcc);
writecommandtods18b20(0x44);
TR0=1;
while(1)
{
;
}
}
void t0(void) interrupt 1 using 0
{
unsigned char x;
unsigned int result;
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
if(displaycount==2)
{
P0=displaycode[displaybuf[displaycount]] | 0x80;
}
else
{
P0=displaycode[displaybuf[displaycount]];
}
P2=displaybit[displaycount];
displaycount++;
if(displaycount==8)
{
displaycount=0;
}
timecount++;
if(timecount==150)
{
timecount=0;
while(resetpulse());
writecommandtods18b20(0xcc);
writecommandtods18b20(0xbe);
readdata[0]=readdatafromds18b20();
readdata[1]=readdatafromds18b20();
for(x=0;x255)
{
readdata[1]++;
}
}
readdata[1]=readdata[1]4;
x=x & 0x0f;
readdata[1]=readdata[1] | x;
x=2;
result=readdata[1];
while(result/10)
{
displaybuf[x]=result%10;
result=result/10;
x++;
}
displaybuf[x]=result;
if(sflag==1)
{
displaybuf[x+1]=17;
}
x=readdata[0] & 0x0f;
x=x
就是用DS18B20進(jìn)行溫度檢測(cè)
#include
#include
unsigned char code displaybit[]={0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f};
unsigned char code displaycode[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00,0x40};
unsigned char code dotcode[32]={0,3,6,9,12,16,19,22,
25,28,31,34,38,41,44,48,
50,53,56,59,63,66,69,72,
75,78,81,84,88,91,94,97};
unsigned char displaycount;
unsigned char displaybuf[8]={16,16,16,16,16,16,16,16};
unsigned char timecount;
unsigned char readdata[8];
sbit DQ=P3^7;
bit sflag;
bit resetpulse(void)
{
unsigned char i;
DQ=0;
for(i=255;i>0;i--);
DQ=1;
for(i=60;i>0;i--);
return(DQ);
for(i=200;i>0;i--);
}
void writecommandtods18b20(unsigned char command)
{
unsigned char i;
unsigned char j;
for(i=0;i0;j--);
DQ=1;
}
else
{
DQ=0;
for(j=2;j>0;j--);
DQ=1;
for(j=33;j>0;j--);
}
command=_cror_(command,1);
}
}
unsigned char readdatafromds18b20(void)
{
unsigned char i;
unsigned char j;
unsigned char temp;
temp=0;
for(i=0;i0;j--);
if(DQ==1)
{
temp=temp | 0x80;
}
else
{
temp=temp | 0x00;
}
for(j=200;j>0;j--);
}
return(temp);
}
void main(void)
{
TMOD=0x01;
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
ET0=1;
EA=1;
while(resetpulse());
writecommandtods18b20(0xcc);
writecommandtods18b20(0x44);
TR0=1;
while(1)
{
;
}
}
void t0(void) interrupt 1 using 0
{
unsigned char x;
unsigned int result;
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
if(displaycount==2)
{
P0=displaycode[displaybuf[displaycount]] | 0x80;
}
else
{
P0=displaycode[displaybuf[displaycount]];
}
P2=displaybit[displaycount];
displaycount++;
if(displaycount==8)
{
displaycount=0;
}
timecount++;
if(timecount==150)
{
timecount=0;
while(resetpulse());
writecommandtods18b20(0xcc);
writecommandtods18b20(0xbe);
readdata[0]=readdatafromds18b20();
readdata[1]=readdatafromds18b20();
for(x=0;x255)
{
readdata[1]++;
}
}
readdata[1]=readdata[1]4;
x=x & 0x0f;
readdata[1]=readdata[1] | x;
x=2;
result=readdata[1];
while(result/10)
{
displaybuf[x]=result%10;
result=result/10;
x++;
}
displaybuf[x]=result;
if(sflag==1)
{
displaybuf[x+1]=17;
}
x=readdata[0] & 0x0f;
x=x
就是用DS18B20進(jìn)行溫度檢測(cè)
其他人氣:487 ℃時(shí)間:2020-10-01 23:08:59
優(yōu)質(zhì)解答
unsigned char code displaybit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};定義數(shù)碼管顯示位選數(shù)組unsigned char code displaycode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,...
我來回答
類似推薦
- 七年級(jí)下冊(cè)語文傷仲永全文翻譯
- 今有物不知其數(shù),三三數(shù)之余二,五五數(shù)之余三,七七數(shù)之余二.問物幾何?
- 解釋同一字在不同句子里的含義
- Her mother worked in a town last year 變?yōu)榉穸ň?、疑問句然后作肯定、否?/a>
- I will wash my clothes If I___(have) time tomorrow morning
- Gina常坐9路公交車回家翻譯
- 利用馬克思主義基本原理概論回答,為什么說“資本來到世間,從頭到腳,每個(gè)毛孔都滴著血和骯臟的東西”?
- 梯形的高不變,上底和下底都擴(kuò)大4倍,則面積( )
- 修改病句: 跟敵人斗爭(zhēng)時(shí),態(tài)度多么堅(jiān)決 速度 在線等
- 小丁丁期未考試五門功課的平均分是91分,如果去掉最高的數(shù)學(xué)100分和最低的英語分
- read和words這兩個(gè)英語單詞什么意思?
- 2010合肥一中最后一卷理科數(shù)學(xué)答案
猜你喜歡
- 1山中訪友最主要講什么?
- 2已知AB=AC,AD垂直BC于DM、N為AD上的點(diǎn).CM、CN是角ACB的三等分線,BN交AC于E.說明
- 3變化在漢語中是動(dòng)詞還是名詞
- 4Someone says,“Time is money.”But I think time is _____important than money.
- 51.一列火車長168m 以72km/h的速度行駛,一輛汽車以8m/s的速度行駛.當(dāng)兩輛車同時(shí)行駛時(shí),
- 6寫擬人手法的好處是什么?
- 7寫一個(gè)不帶關(guān)聯(lián)詞語表因果關(guān)系的句子
- 8有一個(gè)高壓鍋,鍋內(nèi)氣壓每增加100℃,水的沸點(diǎn)相應(yīng)增加1℃.國內(nèi)水的初始溫度是20℃.
- 9為什么有的電解方程式中,氫離子參與反應(yīng),但是在總反應(yīng)中要寫成水的形式?
- 10計(jì)算(-2)^2007+(-2)^2008=(-2)^2007+2^2008=2^2007x(2-1) 請(qǐng)解答 如何做啊
- 11掌上珊瑚憐不得 卻叫移作上陽花 .
- 12關(guān)于強(qiáng)調(diào)句的一個(gè)問題~