Pic single chip DS18B20 sampling LCD1602 display

Single chip microcomputer STM32L151CCU6
1206RGB (single)
0201 package SLP0603 ESD electrostatic diode 5V one-way ESD
Mobile phone crystal 3.2*2.5mm 3225 26M (26.000MHZ) 7.5PF 10PPM 20PPM 30PPM

#include "1602.h"
#include "18b20.h"
#include "main.h"
__CONFIG(0X0B31);
Main()
{
Char msg[2][16] = {"Temperature:", ".C"};
Delay_us2(40, 40);
Delay_us2(100, 200);
Initial();
While(1){
Start_convert();
Change_to_ascii(get_temp(), &msg[1][3]);
Display2(&msg[0][0], &msg[1][0]);
}

}


//------------------------us level delay -------------------- --------//
Void delay_us2(char x, char y)
{
Char z;
Do{
z = y;
Do{;} while(--z);
} while(--x);
}

//------------------------ 1 second delay -------------------- ------------//
Void delay_1s(unsigned int x)
{
Unsigned a, b;
For(a = x; a > 0; a--)
For(b = 110; b > 0; b--);
}

//------------------------------------------------ -----------------------//
Void delay_us1(char d)
{
While(--d);
}

#include "18b20.h"
#include "main.h"
//-------------- Generate a reset pulse --------------------//
Void tx_reset()
{
ADCON1 = 0X06;
TRISA5 = 0;
DQ = 1;
Delay_us2(10, 5); //65us
While(!DQ); //Check if the bus is busy
DQ = 0;
Delay_us2(10, 23); //730us
}

//---------------- Waiting for the reply pulse -----------------//
Void tx_wait()
{
TRISA5 = 1; // set to the input mode, DQ is automatically pulled high by the external pull-up resistor
Asm("nop");
While(DQ);
While(!DQ);
Delay_us2(10, 13); //430us
}

//-------------------Read a byte ---------------------//
Char read_byte()
{
Char byte, count;
For(count = 8; count > 0; count--)
{
Byte = byte >> 1;
TRISA5 = 0;
DQ = 0;
Asm("nop");
Asm("nop");
TRISA5 = 1; asm("nop");
If(DQ)
Byte = byte | 0x80;
Else
Byte = byte | 0x00;
Delay_us2(3, 5); //65us
}
Return byte;
}

//------------------- Write a byte ---------------------//
Void write_byte(char btmp)
{
Char i;
TRISA5 = 0;
For(i = 8; i > 0; i--)
{
DQ = 0;
Asm("nop");
Asm("nop");
If(btmp & 0x01){
DQ = 1;
Delay_us2(3, 6); //65us
}
Else{
DQ = 0;
Delay_us2(3, 6); //65us
}
DQ = 1;
btmp = btmp >> 1; delay_us2(3, 2);
}
}

//---------------------Start temperature conversion ---------------------//
Void start_convert()
{
Tx_reset();
Tx_wait();
Write_byte(0xCC);
Write_byte(0x44);
Delay_1s(1000);
}

//----------Read the temperature value in the scratchpad register-----------//
Int get_temp()
{
Char high, low;
Volatile int temp;
Tx_reset();
Tx_wait();
Write_byte(0xcc);
Write_byte(0xbe);
Low = read_byte();
High = read_byte();
Temp = high;
Temp = temp << 8;
Temp = temp | low;
Return temp;
}

//-----------------The temperature value is converted to ASCII code---------------//
Void change_to_ascii(int data, char *ascii)
{
Char left, right;
Int middle;
Left = data >> 4;
Right = data & 0x000f;
Middle = 10000 * 0.0625 * right;

Ascii[0] = left & 0x80 ? '-' : '+'; //Determine the highest temperature symbol
Left = left & 0x80 ? ~left & 0x7f : left;
Ascii[1] = left / 100 + 48;
Ascii[2] = left % 100 / 10 + 48;
Ascii[3] = left % 10 + 48;
Ascii[4] = '.';
Ascii[5] = middle / 1000 + 48;
Ascii[6] = middle % 1000 / 100 + 48;
Ascii[7] = middle % 100 / 10 + 48;
Ascii[8] = middle % 10 + 48;
}




Extern void delay_us2(char x, char y);
Extern void delay_1s(unsigned int x);
Extern void delay_us1 (char d);

#include
#define DQ RA5 //Define 18B20 Data Pins
Extern void tx_reset(); //generate a reset pulse
Extern void tx_wait (); // waiting for the response pulse
Extern char read_byte(); //Read one byte
Extern void write_byte (char btmp); //write a byte
Extern void start_convert(); //Start temperature conversion
Extern int get_temp () ; // read the temperature value in the scratch register
Extern void change_to_ascii (int data, char *ascii); //temperature value converted to ASCII code

Automation Light Curtain

This Automation curtain is specially designed for automation industry. SDKELI LSC2 light curtain is designed for automation field, with small size, compact structure and strong anti-interference ability, and the product meets IEC 61496-2 standards. The automatic light curtain is with reliable quality and very competitive price. It has been used in many factories and has replaced curtains from Omron, Banner, Keyence, etc.

Automatic Light Curtain,Laser Light Curtain,Automation Light Beam Sensor,Automatic Infrared Beam Sensor,Infrared Beam Curttain Sensor,Infrared Beam Sensor

Jining Keli Photoelectronic Industrial Co.,Ltd , https://www.sdkelien.com

Posted on