早教吧作业答案频道 -->其他-->
单片机51的C程序谁给解释下?#include#includeunsignedcharcodedisplaybit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};unsignedcharcodedisplaycode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0x
题目详情
单片机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进行温度检测
#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进行温度检测
▼优质解答
答案和解析
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};定义ds18b20表格数组
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;定义连接ds18b20端口
bit sflag;定义标致位
.
.
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};定义ds18b20表格数组
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;定义连接ds18b20端口
bit sflag;定义标致位
.
.
看了 单片机51的C程序谁给解释下...的网友还看了以下:
谁来解下这两个方程1.解方程:(x/1×2)+(x/2×3)+---+(x/2005×2006)= 2020-05-13 …
阅读下面的例题:分解因式x2+2x-1;解析令x2+2x-1=0,得到一个关于x的一元二次方程.∵ 2020-05-14 …
1\x+1=2\x-1解方程过程 2x\2X+5 +5\5X-2=1解方程过程 a的平方\a-b 2020-05-16 …
(1)解出下列方程的解:(x^2-x)^2-5(x^2-x)+6=0(2)解出下列方程的解:(x+ 2020-05-22 …
1.解关于x的不等式k(x-1)>x+12.如果a<2,那么不等式ax>2x+5的解集是?3.如果 2020-07-30 …
请阅读下面的题目及其"解法"解方程x(x-1)/x-1=x+1/x-1解方程x(x-1)/x-1= 2020-07-31 …
请你试一试,解方程组x+2(x+2y)=4①,x+2y=1②把②代入①得x+2*1=4,所以x=2 2020-08-02 …
阅读下面材料,解方程x/(x-1)-3(x-1)/x=2,设x/(x-1)=y,原方程可化为y-3/ 2020-11-26 …
请观察以下解题过程:分解因式:x4-6x2+1解:x4-6x2+1=x4-2x2-4x2+1=(x4 2020-12-13 …
解不等式X/2x-1>1.解:把不等式进行整理先阅读,再解答问题.例:解不等式>1解:把不等式>1进 2020-12-25 …