The 51 single-chip thermometer LCD1602 display was successful, so the challenge was to use OLED display
main.c
#include"oled.h"
#include"ds18b20_1.h"
void Timer0Init(void);
//void Gao_Wen(void);
//void GaoDiInit(void);
sbit Deng=P1^0; //LED灯
sbit FengMing=P1^1; //Buzzer
sbit GD=P3^0; //Two functions: lower the upper temperature limit and turn off the LED light
sbit GF=P3^1; //Two functions: increase the low temperature limit and turn off the buzzer
sbit GW=P3^2; //Upper temperature limit increases
sbit DW=P3^3; //lower limit temperature decreases
//unsigned char GaoWen_Y[]={"GW:"}; //high limit temperature display
//unsigned char DiWen_Y[]={"DW:"}; //low limit temperature display
int GaoWen=40; //High limit temperature
int DiWen=-20; //low limit temperature
char flag=0; //One second flag
char b=0; //Internal flag of timer;
/*******************************Main program area************************************/
int main()
{
bit ack;
bit k=1; //After the temperature exceeds the limit, the light and buzzer will be turned off and will not sound anymore. However, after the temperature falls below the limit and exceeds the limit again, the buzzer will still sound.
int Zhen=0,Xiao=0;
unsigned char temp[10];
char len=0;
int wenDu=0; //Receive temperature
// LCD_Init();
Deng=0; //LCD initialization
OLED_Init();
Start18B20(); //Temperature sensor initialization
Timer0Init(); //T0 timer initialization
Delay10ms();
// LCD_WeiZhi(1,0);
// LCD_XianShi(GaoWen_Y);
// LCD_WeiZhi(1,9);
// LCD_XianShi(DiWen_Y);
// GaoDiInit();
OLED_ShowChinese(0,0,10,16);
OLED_ShowChinese(18,0,13,16);
OLED_ShowChar(36,0,':',16);
OLED_ShowChinese(0,2,8,16);
OLED_ShowChinese(18,2,10,16);
OLED_ShowChinese(36,2,11,16);
OLED_ShowChinese(54,2,12,16);
OLED_ShowChar(70,2,':',16);
OLED_ShowChinese(0,4,9,16);
OLED_ShowChinese(18,4,10,16);
OLED_ShowChinese(36,4,11,16);
OLED_ShowChinese(54,4,12,16);
OLED_ShowChar(70,4,':',16);
// OLED_ShowString(0,2,"GW:",16);
// OLED_ShowString(64,2,"DW:",16);
OLED_Num(78,2,GaoWen,3,16);
OLED_Num(78,4,DiWen,3,16);
while(1)
{
if(flag==1) //Refresh temperature in 1 second
{
flag=0;
ack=Read18B20(&wenDu);
if(ack)
{
Zhen=wenDu>>4;
Xiao=wenDu&0x0f;
len=OLED_Xian_Zheng(Zhen,temp);
temp[len++]='.';
Xiao=(Xiao*100)*0.0625;
temp[len++]=Xiao/10+'0';
// temp[len++]=Xiao%10+'0';
while(len<5)
{
temp[len++]=' ';
}
temp[len]='';
// LCD_WeiZhi(0,0);
// LCD_XianShi(temp);
OLED_ShowString(44,0,temp,16);
}
Start18B20();
}
OLED_Num(78,2,GaoWen,3,16);
OLED_Num(78,4,DiWen,3,16);
if((Zhen>=GaoWen||Zhen<=DiWen)&&k)
{
Deng=1;
FengMing=0;
}
if(Zhen>DiWen&&Zhen Deng=0; FengMing=1; k=1; } if(GD==0) { Delay10ms(); if(GD==0) { if(Deng==0) { Gao Wen--; // Delay400ms(); // GaoDiInit(); //OLED_Num(20,2,GaoWen,3,16); } else { // Delay400ms(); Deng=0; k=0; } } } if(GF==0) { Delay10ms(); if(GF==0) { if(FengMing==1) { DiWen++; // Delay400ms(); // GaoDiInit(); // OLED_Num(84,2,DiWen,3,16); } else { // Delay400ms(); FengMing=1; k=0; } } } } } /************************************Timer initialization******************************/ void Timer0Init(void) //50 milliseconds@12.000MHz { EA=1; ET0=1; EX0=1; EX1=1; IT0=1; IT1=1; IP=0; PT0=1; TMOD &= 0xF0; //Set timer mode TMOD |= 0x01; //Set timer mode TL0 = 0x00; //Set the initial timing value TH0 = 0x4C; //Set the initial timing value TF0 = 0; // Clear TF0 flag TR0 = 1; //Timer 0 starts timing } /******************************T0 interrupt**********************************/ void IT0_1(void) interrupt 1 { TL0 = 0x00; //Set the initial timing value TH0 = 0x4C; //Set the initial timing value b++; if(b>=20) { b=0; flag=1; } } /***************************High limit temperature increase****************************************/ void Gao(void) interrupt 0 { GaoWen++; if(GaoWen>128) { GaoWen=128; FengMing=0; Delay100ms(); FengMing=1; } // GaoDiInit(); //OLED_Num(20,2,GaoWen,3,16); } /*******************************Lower limit temperature decreases********************************/ void Di(void) interrupt 2 { DiWen--; if(DiWen<-55) { DiWen=-55; FengMing=0; Delay100ms(); FengMing=1; } // OLED_Num(84,2,DiWen,3,16); // GaoDiInit(); //OLED_Num(84,2,GaoWen,3,16); }
Previous article:Design and production of digital temperature display based on single chip microcomputer
Next article:51 MCU uses DAC0832 to program the output of square wave, sawtooth wave, triangle wave, sine wave
Recommended ReadingLatest update time:2024-11-16 13:47
- Popular Resources
- Popular amplifiers
- 【Follow me Season 2 Episode 2】Arduion UR4 homework submission code
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Fundamentals and Applications of Single Chip Microcomputers (Edited by Zhang Liguang and Chen Zhongxiao)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Request X-CUBE-MEMS1 firmware package
- TI CCS compiler download update
- Simple and efficient zero-point acquisition circuit
- BMS solutions for electric bicycles and electric motorcycles under the new national standard for electric vehicles
- How to choose the type and model of diode in circuit design
- 【DWIN Serial Port Screen】Practical Application
- [National Technology N32G457 Review] RT-Thread drives SSD1306
- IIC communication problem between MSP430 and SHT11
- MSP430.dll initialization error occurs in the MSP430 download program
- A Problem with TTL Inverter Circuit