Home > other >  O great god help me take a look at this ds18b20 temperature display code where there is a problem, b
O great god help me take a look at this ds18b20 temperature display code where there is a problem, b

Time:09-22

# include
# define uint unsigned int
# define uchar unsigned char

DS18B20/* */
P1 sbit k=^ 4;

Void Delay1ms (uint y)
{
Uint x;
for(; Y> 0; Y -)
{
For (x=110; X> 0; X -);
}
}

Uchar Ds18b20Init ()
{
Uchar I=0;
k=0;
I=70;
While (I -);//642 us
K=1;
i=0;
While (k)
{
Delay1ms (1);
i++;
If (i> 5)
{
return 0;
}
}
return 1;
}
Void Ds18b20WriteByte uchar (dat)
{
Uchar I, j;
for(j=0; j<8; J++)
{
k=0;
i++;
K=dat& 0 x01;
I=6;
While (I -)//68 um
K=1;
Dat>=1;//shift
}
}

Uchar Bs18b20ReadByte ()
{
Uint I, j;
Uchar bi, byte;
for(j=0; j<8; J -)
{
k=0;
i++;
K=1;
i++;
i++;
Bi=k;
Byte=(byte> 1) | (bi<7);
I=4;
While (I -);
}
Return byte;
}

Void Ds18b20changeTemp ()
{
Ds18b20Init ();
Delay1ms (1);
Ds18b20WriteByte (0 XCC);
X44 Ds18b20WriteByte (0);//temperature conversion
}

Void Ds18b20ReadTempCom ()
{
Ds18b20Init ();
Delay1ms (1);
Ds18b20WriteByte (0 XCC);
The xbe Ds18b20WriteByte (0);
}
Int Ds18b20ReadTemp ()
{
int temp=0;
Uchar th, tl;
Ds18b20changeTemp ();
Ds18b20ReadTempCom ();
Tl=Bs18b20ReadByte ();
Th=Bs18b20ReadByte ();
Temp=th;
Temp<=8;
Temp |=tl;
Return temp.
}
Digital tube/* */
Uchar code SMGduan [10]={xa4 xc0 0, 0 xf9, 0, 0 xb0, 0 x99, 0 x92, 0 x82, 0 xf8, 0 x80, 0 x90};//show 0 ~ 9
Uchar DisplayDate [8].
Void datepros (int temp)
{
Float tp.
If (temp<0)
{
DisplayDate [0]=0 x40;
Temp=temp - 1;
Temp=~ temp;
Tp=temp;
Temp=tp 0.5 * 0.0625 * 10 +;
}
The else
{
DisplayDate [0]=0 x00;
Tp=temp;
Temp=tp 0.5 * 0.0625 * 10 +;
}
DisplayDate [1]=SMGduan temp/100;
DisplayDate [2]=SMGduan [100/10] temp % | 0 x80;
DisplayDate [3]=SMGduan [10] temp % 100%;
}


Sbit fuhao P1=^ 0;
P1 sbit shi=^ 1;
Sbit ge=p ^ 2;
Sbit xiaoshu P1=^ 3;

Void delay (uint I)
{
While (I -);
}

Void DigDisplay ()
{
Uint I;

for(i=0; i<4. I++)
{
If (I==0) {fuhao=0; Shi=1; General electric (ge)=1; Xiaoshu=1; }
If (I==1) {fuhao=1; Shi=0; General electric (ge)=1; Xiaoshu=1; }
If (I==2) {fuhao=1; Shi=1; Ge=0; Xiaoshu=1; }
If (I==3) {fuhao=1; Shi=1; General electric (ge)=1; Xiaoshu=0; }
}
The P2=DisplayDate [I];//send paragraph
delay(100);//for a period of time between scanning
P2=0x00;//blanking
}

Void main ()
{
While (1)
{
Datepros (Ds18b20ReadTemp ());
DigDisplay ();
}
}

CodePudding user response:

The datepros first (Ds18b20ReadTemp ()); Comment out
Add
DisplayDate [1]=1;
DisplayDate [1]=2;
DisplayDate [2]=3;
DisplayDate [3]=4;
Run the test digital tube display program

CodePudding user response:

Digital tube is no problem, with no other program can display Numbers, so could you please help me to see the application? I in CSDN download, but I don't understand what dula and wela, according to the circuit diagram of what trouble I help me see, please
/*
This code implements the DS18B20 temperature measurement, the crystals of 11.0592 M, the difficulty is to delay procedures,
Section in front of the program to write, write, read, read the byte code can be used as a single bus communication standard code, itself is borrowed from the standard code of
*/
# include
# define uchar unsigned char
# define uint unsigned int
Sbit dula=P2 ^ 6;
Sbit wela=P2 ^ 7;
Sbit DQ=P2 ^ 2;
Unsigned char code table []={x5b x3f 0, 0 x06, 0, 0 x4f, 0 x66, 0 x6d, 0 x7d,
X6f x07 0, 0 x7f, 0, 0, x77 x7c 0, 0 x39, 0 x5e, 0 x79, 0 x71};//without a decimal coding
XBF unsigned char code table1 []={0, 0 x86, 0 XDB, XCF 0, 0 xe6, 0 xed, 0 XFD,
0 x87, 0 XFF, 0 xef};//this is taken after the decimal point code
/*
Void Init_Com (void)//serial port initialization, the application does not use a serial port
{
TMOD=0 x20;
PCON=0 x00;
SCON=0 x50;
TH1=0 XFD;
TL1=0 XFD;
TR1=1;
}
*/
Void delay (int) CNT//delay
{
int i;
for(i=0; i}

Unsigned char reset (void)//reset signal
{
Unsigned char presence;
DQ=0;//the DQ signal lines down
Delay (29).//the DQ signal of low level state lasts 480 us
DQ=1;//release the bus, to return to the high level state
delay(3);//wait from equipment down bus
Presence=DQ;//save the current bus state
Delay (25);//wait for the bus initialization end
Return presence;//return if there is a bus from equipment down
}

The void write_bit (char BitValue)//write a
{
DQ=0;//low DQ signals, start writing time slot
If (BitValue=https://bbs.csdn.net/topics/=1)
{
Delay (5);
DQ=1;//if the time slot is 1, the DQ for high level
}
The else
{
Delay (5);
}
Delay (50);//wait for the write end of the time slot
DQ=1;
}

Void write_byte (WriteByteValue)/section/write
{
unsigned char i;
Unsigned char WriteTemp;
for(i=0; i<8; I++)//write eight consecutive data
{
WriteTemp=WriteByteValue & gt;> i;//to write data in bytes moves to the right (I) a
WriteTemp=WriteTemp & amp; 0 x01;//remove the data bytes of the ith a
Write_bit (WriteTemp);//to write a data bus
}
Delay (50);//waiting for the end of the time slot
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related