1. Introduction
This system is mainly composed of AT89C51, DS18B20 temperature module and LCD1602.
The general principle is that the temperature data collected by DS18B20 is transmitted to P3.3/INT1 (external interrupt 1) of AT89C51, and finally the current real-time temperature is displayed through LCD1602.
2. Rendering
Simulation diagram
3. Source code
/*Want more projects private wo!!!*/
/*************** writer:shopping.w ******************/
#include #include #define uint unsigned int #define uchar unsigned char #define delayNOP() {_nop_();_nop_();_nop_();_nop_();} sbit DQ = P3^3; sbit LCD_RS = P2^0; sbit LCD_RW = P2^1; sbit LCD_EN = P2^2; uchar code Temp_Disp_Title[]={"Current Temp : "}; uchar Current_Temp_Display_Buffer[]={" TEMP: "}; volatile code Temperature_Char[8] = { 0x0c,0x12,0x12,0x0c,0x00,0x00,0x00,0x00 }; uchar code df_Table[]= { 0,1,1,2,3,3,4,4,5,6,6,7,8,8,9,9 }; float CurrentT = 0; uchar Temp_Value[]={0x00,0x00}; float Display_Digit[]={0,0,0,0}; bit DS18B20_IS_OK = 1; void DelayXus(uint x) { flying i; while(x--) { for(i=0;i<200;i++); } } bit LCD_Busy_Check() { bit result; LCD_RS = 0; LCD_RW = 1; LCD_EN = 1; delayNOP(); result = (bit)(P0&0x80); LCD_EN=0; return result; } void Write_LCD_Command(uchar cmd) { while(LCD_Busy_Check()); LCD_RS = 0; LCD_RW = 0; LCD_EN = 0; _nop_(); _nop_(); P0 = cmd; delayNOP(); LCD_EN = 1; delayNOP(); LCD_EN = 0; } void Write_LCD_Data(uchar dat) { while(LCD_Busy_Check()); LCD_RS = 1; LCD_RW = 0; LCD_EN = 0; P0 = that; delayNOP(); LCD_EN = 1; delayNOP(); LCD_EN = 0; } void LCD_Initialize() { Write_LCD_Command(0x01); DelayXus(5); Write_LCD_Command(0x38); DelayXus(5); Write_LCD_Command(0x0c); DelayXus(5); Write_LCD_Command(0x06); DelayXus(5); } void Set_LCD_POS(uchar pos) { Write_LCD_Command(pos|0x80); } void Delay(uint x) { while(--x); } fly Init_DS18B20() { flying status; DQ = 1; Delay(8); DQ = 0; Delay(90); DQ = 1; Delay(8); DQ = 1; return status; } fly ReadOneByte() { fly i,dat=0; DQ = 1; _nop_(); for(i=0;i<8;i++) { DQ = 0; that >>= 1; DQ = 1; _nop_(); _nop_(); if(DQ) that |= 0X80; Delay(30); DQ = 1; } return that; } void WriteOneByte(volatile dat) { flying i; for(i=0;i<8;i++) { DQ = 0; DQ = that& 0x01; Delay(5); DQ = 1; that >>= 1; } } void Read_Temperature() { if(Init_DS18B20()==1) DS18B20_IS_OK=0; else { WriteOneByte(0xcc); WriteOneByte(0x44); Init_DS18B20(); WriteOneByte(0xcc); WriteOneByte(0xbe); Temp_Value[0] = ReadOneByte(); Temp_Value[1] = ReadOneByte(); DS18B20_IS_OK=1; } } void Display_Temperature() { flying i; uchar t = 150, of = 0; 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]++; of = 1; } Display_Digit[0] = df_Table[Temp_Value[0]&0x0f]; CurrentT = ((Temp_Value[0]&0xf0)>>4) | ((Temp_Value[1]&0x07)<<4); Display_Digit[3] = CurrentT/100; Display_Digit[2] = CurrentT%100/10; Display_Digit[1] = CurrentT%10; Current_Temp_Display_Buffer[11] = Display_Digit[0] + '0'; Current_Temp_Display_Buffer[10] = '.'; Current_Temp_Display_Buffer[9] = Display_Digit[1] + '0'; Current_Temp_Display_Buffer[8] = Display_Digit[2] + '0'; Current_Temp_Display_Buffer[7] = Display_Digit[3] + '0'; if(Display_Digit[3] == 0) Current_Temp_Display_Buffer[7] = ' '; if(Display_Digit[2] == 0&&Display_Digit[3]==0) Current_Temp_Display_Buffer[8] = ' '; if { if(Current_Temp_Display_Buffer[8] == ' ') Current_Temp_Display_Buffer[8] = '-'; else if(Current_Temp_Display_Buffer[7] == ' ') Current_Temp_Display_Buffer[7] = '-'; else Current_Temp_Display_Buffer[6] = '-'; } Set_LCD_POS(0x00); for(i=0;i<16;i++) { Write_LCD_Data(Temp_Disp_Title[i]); } Set_LCD_POS(0x40); for(i=0;i<16;i++) { Write_LCD_Data(Current_Temp_Display_Buffer[i]); } Set_LCD_POS(0x4d); Write_LCD_Data(0x00); Set_LCD_POS(0x4e); Write_LCD_Data('C'); } void main() { LCD_Initialize(); Read_Temperature(); Delay(50000); Delay(50000); while(1) { Read_Temperature(); if(DS18B20_IS_OK) Display_Temperature(); DelayXus(100); } }
Previous article:Single chip perpetual calendar (LCD12864, DS18B20, DS1302)
Next article:Single chip real-time clock circuit (LCD1602, DS1302)
Recommended ReadingLatest update time:2024-11-25 04:23
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- CATL releases October battle report
- Battery industry in October 2024: growth momentum remains unabated!
- Mercedes-Benz will launch the eCitaro equipped with NMC4 batteries to provide high energy density and long life
- Many companies have announced progress on solid-state batteries. When will solid-state batteries go into mass production?
- Xsens Sirius Series Inertial Sensors Enable 3D Inertial Navigation in Harsh Environments
- Infineon's Automotive Landscape: From Hardware to Systems
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- PCB Design Process
- I plan to equip the slag EBAZ4205 with an extended version
- Vinyl records vs digital music: the battle between high fidelity and high technology
- TMC5130 is used as a driver to drive the motor. Why does the motor hum when it is stationary?
- Live broadcast at 10 am today [TI's optimized solutions in industrial multi-protocol communication applications]
- Made an LED music spectrum analyzer
- Common sense concepts of circuits--TTL, CMOS
- EEWORLD University Hall----TI Smart Speaker and Sound Bar- New Power Design Trend
- What parameters should be paid attention to when selecting optocouplers?
- Is there any difference between bit rate and airspeed?