51 single-chip digital clock thermometer programming case

#include "reg51.h"

Char disp[11]={0 x3f,0 x06,0 x5b,0 x4f,0 x66,0 x6d,0 x7d,0 x07,0 x7f,0 x6f,0 x40};
Char disp_dot[11]={0 xbf,0 x86,0 xdb,0 xcf,0 xe6,0 xed,0 xfd,0 x87,0 xff,0 xef,0 xc0};

Sbit DQ = P1^3; //Define the communication port

//crystal 12MHz
Void delay_18B20(unsigned int i)
{
While(i--);
}

/ / initialization function
Init_DS18B20(void)
{
Unsigned char x=0;
DQ = 1; //DQ reset delay_18B20(8); //Slightly delay DQ = 0; //Microcontroller pulls DQ low delay_18B20(80); //Exact delay is greater than 480us
DQ = 1; // Pull the bus delay_18B20(14);
x=DQ; //After a delay, if x=0, the initialization succeeds x=1, the initialization fails delay_18B20(20);
}


/ / Read a byte
ReadOneCha r(void)
{
Unsigned char i=0;
Unsigned char dat = 0;
For (i=8;i>0;i--)
{
DQ = 0; // give the pulse signal dat>>=1;
DQ = 1; // give pulse signal if(DQ)
Dat|=0 x80;
Delay_18B20(4);
}
Return(dat);
}

/ / Write a byte
WriteOneCha r(unsigned char dat)
{
Unsigned char i=0;
For (i=8; i>0; i--)
{
DQ = 0;
DQ = dat&0 x01;
Delay_18B20(5);
DQ = 1;
Dat>>=1;
}
}

/ / Read the temperature
ReadTemperature(void)
{
Unsigned char a=0;
Unsigned char b=0;
Unsigned int t=0;

Init_DS18B20();
WriteOneCha r(0 xCC); // Skip the operation of reading the column number. WriteOneCha r(0 x44); // Start the temperature conversion delay_18B20(100);
Init_DS18B20();
WriteOneCha r (0 xCC); / / skip the operation of reading the serial number column WriteOneCha r (0 xBE); / / read the temperature register, etc. (a total of 9 registers can be read) The first two are the temperature a = ReadOneCha r () ;
b=ReadOneCha r();

/ / The sensor return value divided by 16 to the actual temperature value / / In order to get 2 decimal places, first multiply 100, then divide 16, consider the integer data length,
/ / After the skill is processed, multiply by 25, then divide by 4, except 4 with right shift.

t = (b*256+a)*25;
Return( t >> 2 );
}

Main()
{
Unsigned int tmp;
Unsigned char counter;
While(1)
{
/ / Temperature measurement frequency is not necessary too high, too high, but affect the digital display / / so use the counter to control if (counter-- == 0)
{
Tmp = ReadTemperature();
Counter = 20;
}

P2 = 0 xff;
P0 = disp[tmp%10];
P2 = 0 xfb;
Delay_18B20(1000);
P2 = 0 xff;
P0 = disp[tmp/10%10];
P2 = 0 xf7;
Delay_18B20(1000);
P2 = 0 xff;
P0 = disp_dot[tmp/100%10];
P2 = 0 xef;
Delay_18B20(1000);
P2 = 0 xff;
P0 = disp[tmp/1000%10];
P2 = 0 xdf;
Delay_18B20(1000);
}
}

24V Power Supply

24v power supply, the current range is 2A-9.2A, the max power is 220w. We also can meet your specific requirement of the prodcuts.The material of this product is PC+ABS. All condition of our product is 100% brand new.

Our products built with input/output overvoltage protection, input/output overcurrent protection, over temperature protection, over power protection and short circuit protection. You can send more details of this product, so that we can offer best service to you!


24V Power Supply,24V Pc Power Supply,24V Dc Power Supply ,24V Power Supply For Pc

Shenzhen Waweis Technology Co., Ltd. , https://www.huaweishiadapter.com

This entry was posted in on