求AT89C51单片机与DS18B20的C语言程序,温度设定为10℃—70℃最小区分度为0.

求AT89C51单片机与DS18B20的C语言程序,温度设定为10℃—70℃最小区分度为0.2℃,显示是四位共阳数码管,水温控制系统(仿真图这样的)求大神帮忙... 求AT89C51单片机与DS18B20的C语言程序,温度设定为10℃—70℃最小区分度为0.2℃,显示是四位共阳数码管,水温控制系统(仿真图这样的)求大神帮忙 展开
 我来答
超人sun4u
2016-06-16 · TA获得超过267个赞
知道小有建树答主
回答量:277
采纳率:0%
帮助的人:147万
展开全部
#include<reg51.h>
#include<INTRINS.h>
#define uchar unsigned char
#define uint unsigned int

sbit DI = P1^0;
sbit CS = P1^1;
sbit CK = P1^2;
sbit IO = P1^3;
sbit RS = P1^4;
sbit LL = P1^5;
sbit LZ = P1^6;
sbit LH = P1^7;
sbit TK = P3^0;
sbit IG = P3^1;
sbit TF = P3^2;
sbit DQ = P3^3;
sbit UP = P3^4;
sbit DN = P3^5;
sbit TM = P3^7;
bit ng,np,fg;
bit buftm = 0,buftf = 0;

uchar data Disp[8];
uchar data CurrentT,CurrentB,Count1,Count2 = 3,Dot;
char data SignedT,SignedB = 35,gl;
uchar data glc = 0;

void nNop(uint x)
{
while(--x );
}

void IB_Device_Reset( void )
{
DQ = 1; nNop(8); DQ = 0; nNop(90); DQ = 1; nNop(8);
nNop(100); DQ = 1;
}

uchar ReadOneChar( void )
{
uchar i,d = 0;
DQ = 1; _nop_();
for (i = 0; i < 8; i++)
{
DQ = 0; d >>= 1; DQ = 1; _nop_(); _nop_();
if(DQ) d |= 0x80; nNop(30); DQ = 1;
}
return d;
}

void WriteOneChar( uchar dat )
{
uchar i;
for (i = 0; i < 8; i++)
{
DQ = 0; DQ = dat & 0x01; nNop(5); DQ = 1; dat>>=1;
}
}

void Readtemp( void ) reentrant
{
uchar data Temp_Value[2];
IB_Device_Reset();
WriteOneChar( 0xCC );
WriteOneChar( 0x44 );
nNop( 100 );
IB_Device_Reset();
WriteOneChar( 0xCC );
WriteOneChar( 0xBE );
Temp_Value[0] = ReadOneChar();
Temp_Value[1] = ReadOneChar();
/*********Output_Fubi*********/
ng = 0; //Clr Fubi
if( (Temp_Value[1] & 0xF8) == 0xF8)
{
Temp_Value[1] = ~Temp_Value[1];
Temp_Value[0] = ~Temp_Value[0] + 1;
if( Temp_Value[0] == 0x00 ) Temp_Value[1]++;
ng = 1;
}
/*********Output_Temp*********/
CurrentT = Temp_Value[1] * 16 + Temp_Value[0] / 16;
Disp[0] = CurrentT / 10 % 10; Disp[1] = CurrentT % 10;
SignedT = ng? -CurrentT : CurrentT;
if(ng) Disp[0] = 10;
if( Disp[0] == 0 ) Disp[0] = 15;
}

uchar Read( uchar addr )
{
uchar i,b,t;
RS = 0; CK = 0; RS = 1;
for(i = 0; i < 8; i++)
{
IO = addr & 1; CK = 1; CK = 0; addr >>= 1;
}
for(i = 0; i < 8; i++)
{
b >>= 1; t = IO; b |= t<<7; CK = 1; CK = 0;
}
CK = 1; RS = 0;
return b / 16 * 10 + b % 16;
}

void write_7221( uint idat )
{
uchar i;
CS = 0;
for(i = 0; i < 16; i++)
{
CK = 0; idat <<= 1; DI = CY;
CK = 1; _nop_(); _nop_();
CK = 0;
}
CS = 1;
}

void Show( void )
{
uchar s;
for(s = 0; s < 8; s++) write_7221( ((s + 1) * 256) + Disp[s] );
}

void DispLimit( void )
{
np = 0; if( SignedB < 0 ) {CurrentB = ~SignedB + 1; np = 1;}
else CurrentB = SignedB;
Disp[2] = CurrentB / 10; Disp[3] = CurrentB % 10; if(np) Disp[2] = 10;
if( Disp[2] == 0 ) Disp[2] = 15;
}

void Rectime( void )
{
Disp[4] = Read( 0x85 ) / 10; Disp[5] = Read( 0x85 ) % 10 | Dot;
Disp[6] = Read( 0x83 ) / 10; Disp[7] = Read( 0x83 ) % 10;
}

void Flash( void ) interrupt 1
{
if(++Count1 == 60) {Count1 = 0; if(UP && DN) fg = 0; Dot = 0x00;}
if( Count1 == 30 ) Dot = 0x80;
if(++Count2 == 2)
{
if(fg) {Disp[2] = 15; Disp[3] = 15;}
}
if(Count2 == 4) {Count2 = 0; DispLimit();}
if(gl == 2)
{
if(buftm)
{
TM = 0;
}
else if(buftf)
{
TF = 0;
}
else
{
TM = 1;
TF = 1;
}
}
else
{
glc = glc + 1;
if(glc >= (3-gl))
{
glc = 0;
if(buftm)
{
TM = !TM;
}
else if(buftf)
{
TF = !TF;
}
else
{
TM = 1;
TF = 1;
}
}
}
Readtemp();
Rectime();
Show();
TH0 = -50000 / 256;
TL0 = -50000 % 256;
}

void DisplayLED( void )
{
switch(gl)
{
case 0:
LL = 0;
LZ = LH = 1;
break;
case 1:
LZ = 0;
LL = LH = 1;
break;
case 2:
LH = 0;
LL = LZ = 1;
break;
}
}

void main( )
{
Readtemp();
nNop(50000); nNop(50000);
write_7221( 0x09FF );
write_7221( 0x0A0C );
write_7221( 0x0B07 );
write_7221( 0x0C01 );
IE = 0x83;
IP = 0x01;
TMOD = 0x21;
TH0 = TL0 = 254;
TR0 = IT0 = 1;
DisplayLED();

while(1)
{
if(!UP && SignedB < 99)
{
++SignedB; if(!fg) fg = 1; DispLimit();
while(!UP);
}
if(!DN && SignedB > -9)
{
--SignedB; if(!fg) fg = 1; DispLimit();
while(!DN);
}
if(!IG)
{
gl = (gl + 1) % 3;
DisplayLED();
while(!IG);
}
TK = SignedT == SignedB ? 0 : 1;
buftm = SignedT < SignedB ? 1 : 0;
buftf = SignedT > SignedB ? 1 : 0;
}
}

这个程序是带时间显示的程序,51也管用
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式