温度传感器c语言编程 - 副本(Temperature sensor C language programming - copy)
温度传感器c语言编程 - 副本(Temperature sensor C language programming - copy)
I wrote 51 SCM 18B20 temperature sensor source (C language), very easy to use, and in the development board on the actual operation is very successful, is to learn 18B20 temperature sensor is a good reference! (unlike some people just paste a program, they don't know right or wrong)
* for 51 MCU development board V3.0 and V4.0.
/*51 microcontroller 18B20 temperature sensor source program (C language).
#include
#include
Sbit RS = P1^0;
Sbit RW = P1^1;
Sbit EN = P1^2;
Sbit TSOR = P3^7;
/*------------------------------------------ global variables -------------------------------------------------------*/
Static unsigned char temp1 temp2; / / the temperature value of the integer, decimal part
Static char line0[] = "00:00"";
"Static char line1[] =". C";
The /*-------------------------------------------LCD driver function ------------------------------------------------*/
Void, DelayL ();
Void, DelayS ();
Void WriteCommand (unsigned, char, C);
Void WriteData (unsigned, char, C);
Void ShowChar (unsigned, char, POS, unsigned, char, C);
Void ShowString (unsigned, char, line, char, *ptr);
Void, InitLcd ();
/*--------------------------------------------- -------------------------------------------*/ drive digital thermometer
Void ChangePos (bit, SEL, unsigned, char, pos1, unsigned, char, pos2);
/*------------------------------------------ temperature sensor driver ----------------------------------------------*/
Void, Delay15 ();
Void, Delay60 ();
Void, Delay100ms ();
Void, Write0TS ();
Void, Write1TS ();
Bit, ReadTS ();
Void, ResetTS ();
Void WriteByteTS (unsigned, char, byte);
Unsigned, char, ReadByteTS ();
Void, InitTS ();
Void, GetTempTS ();
The main program ---------------------------------------------------*/ /*-------------------------------------------------
Void main (void)
{
Char code str1[] = "Hello World"!";
Char code str2[] = "2006-12-12"";
Char code str3[] = "51mcu-v3.0"";
Uns