sbit key_1=P0^1; //Confirm key
sbit key_2=P0^2; //Key addition
sbit key_3=P0^3; //Key subtraction
Download the header file 12c5a.h used in this program: http://www.51hei.com/f/12c5a.rar
#include "12c5a.H"
#include "intrins.h"
unsigned char code num[]={"0123456789"};//Display character storage
unsigned char code start_char[]={"Loading...."};
unsigned char code t_char[]={"NOW TEMP IS"};
unsigned char *pnum=num;
unsigned int bbb,ccc,temp,temp_high,temp_low;
#define ADC_POWER 0x80 //ADC power control bit
#define ADC_FLAG 0x10 //ADC complete flag
#define ADC_START 0x08 //ADC start control bit
#define ADC_SPEEDLL 0x00 //540 clocks
#define ADC_SPEEDL 0x20 //360 clocks
#define ADC_SPEEDH 0x40 / /180 clocks
#define ADC_SPEEDHH 0x60 //90 clocks
sbit RS=P3^4; //Data command selection terminal
sbit RW=P3^5; //Read and write control terminal
sbit E=P3^6; //Enable signal control terminal
//sbit key_0=P0^0; //Set button
sbit key_1=P0^1; //Confirm button
sbit key_2=P0^2; //Key addition
sbit key_3=P0^3; //Key subtraction
sbit P04=P0^4;
sbit P05=P0^5;
sbit P06=P0^6;
void key_temphigh();
void key_templow();
void key_scan();
void delay_1602(unsigned int a);
void init_1602(void);
void WR_data_1602(unsigned char adata,unsigned char i);
void process(unsigned int shuju);
void Delay(unsigned char n)
{
int x;
while (n--)
{
x = 500;
while (x--);
}
}
void init_ADC(void)
{
P1ASF=0xFF;
ADC_RES = 0;
ADC_RESL = 0;
ADC_CONTR = 0x88;
Delay(2);
}
unsigned int GetResult(void)
{
unsigned char m,n;
unsigned int aaa;
init_ADC();
while (!(ADC_CONTR & ADC_FLAG)); //Wait complete flag
ADC_CONTR =0x80; //Close ADC
m=ADC_RES;
n= ADC_RESL;
aaa=m*4+n;
return aaa;
}
void start_init(void)
{
unsigned char i;
WR_data_1602(0x80,0); //Displayed in the first line
for(i=0;i<11;i++)
WR_data_1602(start_char[i],1);
delay_1602(20);
init_ADC();
temp=GetResult()*5.0;
WR_data_1602(0x80,0); //Displayed in the first line
for(i=0;i<11 ;i++)
WR_data_1602(t_char[i],1);
}
void delay_1602(unsigned int a) //Delay
{
unsigned int i,j,k;
for(i=0;i
for(j=0;j<106;j++)
for(k=0; k<100;k++);
}
[page]
void key_temphigh() // Temperature upper limit judgment
{ if(key_2==0) //Add judgment
{ Delay(3);
if(key_2==0)
{ while(!key_2);
temp_high+=5;
if(temp_high==995)
{temp_high=5;}
}
}
if(key_3==0) //Subtract judgment
{ Delay(3);
if(key_3==0)
{ while(!key_3); //Wait for
releasetemp_high-=5; //The upper limit alarm temperature decreases by 0.5 each time
if(temp_high==0)
{temp_high=990;}
}
}
}
void key_templow() // Temperature lower limit judgment
{ if(key_2==0) //Add judgment
{ Delay(3);
if(key_2==0)
{ while(!key_2);
temp_low+=5;
if(temp_low==995)
{temp_low=5;}
}
}
if(key_3==0) //Subtract judgment
{ Delay(3);
if(key_3==0)
{ while(!key_3); //Wait for release
temp_low-=5; // The upper limit temperature decreases by 0.5 each time
if(temp_low== 0)
{temp_low=990;}
}
}
}
void key_scan()
{ unsigned char nm=0,k;
if(key_1==0) //Detect the setting button and determine whether to set it
{ if(key_1==0)
{ Delay(100);
while(!key_1);
k=1;nm++;
}
}
while(k) //Enter the adjustment interface,
{ if(key_1==0)
{ Delay(3);
if(key_1==0)
{ while(!key_1);
nm++; //Which parameter to adjustif
(nm==4){nm=1;}
}
}
switch(nm) //Select the object to be adjusted
{ case 1:WR_data_1602(0xc0,0);WR_data_1602('H',1);process(temp_high);key_temphigh();break;
case 2:WR_data_1602(0xc0,0);WR_data_1602('L',1);process(temp_low);key_templow();break;
case 3:WR_data_1602(0xc0,0);WR_data_1602(' ',1);process(temp);nm=0;k=0;break;
default :break;
}
/* if(key_1==0) //OK and Exit
{Delay(3);
if(key_1==0)
{while(!key_1);
nm=0;k=0;WR_data_1602(0xc1,0);process(temp);
}
} */
if(k==0)
{continue;}//End loop
}
}
void baojing()
{
if(temp>temp_high-5) {P04=1;P05=0;P06=1;} // Upper limit 25
else if(temp
}
void init_1602(void) //Initialization
{
WR_data_1602(0x38,0);
WR_data_1602(0x01,0);
WR_data_1602(0x06,0);
WR_data_1602(0x0c,0);
}
void WR_data_1602(unsigned char adata,unsigned char i) //write data i=1,write instruction i=0
{
P2=adata;
RS=i;
RW=0;
E=1;
delay_1602(1);
E=0;
RW=1;
RS=0;
}
void process(unsigned int shuju) //Display data processing
{
unsigned int a,b,c,d;
a=shuju/1000;
b=(shuju%1000)/100;
c=(shuju%100)/10;
d =shuju%10;
if(a==0&&b!=0){WR_data_1602(0xc2,0);
WR_data_1602(*(pnum+b),1);
WR_data_1602(*(pnum+c),1);
WR_data_1602(' .',1);
WR_data_1602(*(pnum+d),1);
WR_data_1602('C',1);}
if(a==0&&b==0){WR_data_1602(0xc2,0);
WR_data_1602(*(pnum+c),1);
WR_data_1602('.',1); WR_data_1602
(*(pnum+d),1);
WR_data_1602('C',1);
WR_data_1602(' ',1); }
//WR_data_1602(0xc1,0); //Displayed in the second line
//WR_data_1602(' ',1);
//WR_data_1602(*(pnum+a),1);
// WR_data_1602(*(pnum+b ),1);
//WR_data_1602(*(pnum+c),1);
// WR_data_1602('.',1);
// WR_data_1602(*(pnum+d),1);
// WR_data_1602('C ',1);
delay_1602(1);
}
void main() //Main function
{
unsigned int mm;
init_1602(); //Initialization
start_init();
mm=GetResult();
temp_high=250;
temp_low=90;
while(1)
{
key_scan();
baojing() ;
ccc=GetResult();
temp=ccc*5.0;
process(temp);
delay_1602(10);
}
}
Previous article:STC89C51RC 40C-PDIP name meaning of each part
Next article:51 single chip microcomputer frequency meter Proteus simulation design (with program circuit)
Recommended ReadingLatest update time:2024-11-17 06:46
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!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- 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
- [RT-Thread reading notes] Part 1 Simple principles of the kernel
- I worked hard to drive the CC2640 Hanshuo electronic tag.
- Solution to the error empty character constant
- Newbie wants to use PLC to control air conditioner
- Looking for a microcontroller model
- Measurement of radar power, spectrum and related parameters
- [ESP32-Audio-Kit Audio Development Board Review]——(2): Questions about play_mp3_control
- Is it popular to reduce the size of laptop keyboards now?
- (Bonus 5) GD32L233 Review - CRC (with the clearest article explaining CRC in history)
- Recruiting MCU development engineers (workplace: Beijing, Wuhan)