0.jpg (58.35 KB, Downloads: 24)
Download attachments and save them to the photo album
Uploaded on 2018-3-14 05:20
The microcontroller source program is as follows:
#include #include #include "STC12C5A60S2.h" #include "zcy.h" #include "s_12864.h" //////////////////////////////////////////////////////// //Global variables volatile long time0_temp1 = 0; volatile long time0_temp2 = 0; volatile long global_sec = 0; int key_counter = 0 ; int led_flash_mode_index = 2 ; //LED flash mode 1--8, starting from 1, up to 8 modes ssssssssss volatile int time0_10ms_flag = 0; int time0_10ms_counter = 0; int led_active_flag = 0; typedef void (*led_fun_str)(void); //Define the data type of a function pointer //Then define an array with this data type led_fun_str led_fun_bufffer[29+29]; void (*led_flash_fun_str)(void); int led_index = 1; int k_off = 0; int k_on = 0; uchar temp_random = 0; uchar now_temp_random = 0; uchar last_temp_random = 0; fly temp_diff = 0; uchar temp_buffer_random[29]; int k_extern = 0; int loop_temp = 0; uchar temp_buffer_16_16_comm[32]; //Must be designed as a global variable to avoid display errors uchar temp_buffer_8_16_comm[16]; //Must be designed as a global variable to avoid display errors int refer_fun_flag = 0; int key_perss_counter = 0; int key_once_active_flag = 0; //key action once int key_value = 0 ; float now_temp = 0.0; long dis_now_temp = 0; float wenkong_now_temp = 0.0; //Current temperature for temperature control volatile int global_sec_flag = 0; int temp_zero_below_flag = 1 ; //1 means 0 and positive temperature 0 means negative temperature char temp_dis_num_buffer[10]; //Must be defined as a global variable, otherwise the cause of the error is unknown char *temp_str; uint them = 0; int ds_18b20_reset_ok_flag = 0; //pid float SV_value = 50.0; //Set temperature value float PV_value = 0.0; //Current temperature value used for calculation volatile float P_value = 0.0; //Proportional band, for example, 56.3 represents 56.3% 0.0--200.0 int I_value = 0; //Integral time seconds 0-3600 int D_value = 0; // differential time seconds 0-900 int comm_dis_once_flag = 1; //Initial value is 1 volatile int special_dis_once_flag = 1; //Initial value is 1 int pid_tune_flag = 0; //Initial value is 0, i.e. the default value is used in the pid stage 1 is the self-tuning process int three_dot_dis_flag = 0; float Proportion = 0.0; // Proportional constant Proportional Const float Integral = 0.0; // Integral Const float Derivative = 0.0; // Derivative constant Derivative Const float LastError = 0.0; // Error[-1] float PrevError = 0.0; // Error[-2] float SumError = 0.0; // Sums of Errors float dError = 0.0; float Error = 0.0; int pid_result = 0; float T_Hight = 0.0; float T_LOW = 100.0; //temperature long TIME_Hight = 0; long TIME_LOW = 0; //Specific seconds int pid_con_10ms_flag = 0; int pid_con_counter = 0; float KC = 1.0; // critical scale factor initial default value int TC = 40; //Oscillation period initial default value int temp_pid = 0; //Set as a global variable volatile int get_now_temp_flag = 0; volatile int enable_pid_sec_flag = 0; volatile int pid_self_sec_flag = 0; //uint pid_self_calc_buffer[200] _at_ 0xF000; //0xffff corresponds to the top of the flash int zero_across_counter = 0; int pid_self_first_status_flag = 0; long pid_self_time_sec = 0; float max_temp = 0.0 ; //The initial temperature is 0 float min_temp = 100.0 ; //initial temperature equals 100 float sum_temp = 0.0 ; //The initial temperature is 0 float aver_temp = 0.0 ; int cool_ack_counter = 0; int hot_ack_counter = 0; int once_add_1_flag = 0; float pid_self_calc_buffer[4]; int k_pid_self_counter = 0; int enable_calc_min_max_flag = 0; int k_max_min = 0; int dis_tune_once_flag = 1; int k_cut_off_flag = 0; //K cut-off flag long k_reou_value = 0; int soft_dis_flag = 1; int soft_counter = 0; int soft_end_counter = 0; int pwm_con_time_flag = 0; //qqqqqqqqqqqqqq //////////////////////////////////////////////////////// //Function definition void SendByte(uchar Dbyte); //Send byte data void write_cmd(uchar Cbyte); //write instruction void write_data(uchar Dbyte); //write data void PUTchar8x8(int row,int col,int count,uchar *put); void PUTchar8x16(int row,int col,int count,uchar *put); void PUTchar16x16(int row,int col,int count,uchar *put); //32 bytes represent 1 Chinese character void PUTchar24x24(int row,int col,int count,uchar *put); void PUTBMP(void);//Picture void PUTREVERSEBMP(void); //Reverse display of image void LcmClear(void);//清屏 void LcmSet(void); //Display all, that is, the whole screen is black void LcmInit(void);//initialization void ohengxian(void); //O horizontal line program void jihengxian(void); //Odd horizontal line program void oshuxian(void); //O vertical line program void jishuxian(void); //Odd vertical line program void dianxian(void); //The point display program fills the screen with points void zifu8x16xian(void); //Can display numbers and English void zifu16x16xian(void); // can display specific Chinese characters void lcd_dis_position_16_16(int line,int column,uchar zifu_16_16[2]); // 1 row 1 column specific character void lcd_dis_position_8_16(int line,int column,uchar zifu_8_16);// 1 row and 1 column specific character void lcd_s_12864_dis_8_16_str(int dis_line,int start_position,char *dis_str);//Display a line of 8*16 characters void ds_18b20_DelayXus(int n); void ds_18b20_init(void); //DS18B20 initialization uchar ds_18b20_read_date(void); //read one byte void ds_18b20_write_date(uchar date); //write a byte float read_18b20_temp(void); //Read the temperature value of 18b20. The actual temperature value is returned and the value of temp_zero_below_flag is changed. If it is 0, it means it is below 0 degrees. void key_pro(void); void display_pro(void); void pid_pro(void); void dis_4_line_as_null(void); void dis_pid_self_value(void); float read_max6675_temper(void); // Use max6675 to read the temperature of the k probe and return 1 times the final temperature void PWM_clock(uchar clock); void PWM_start(uchar module,uchar mode); void set_pwm_value(uchar value); //between 0--255 The larger the value, the higher the duty cycle and the larger the output voltage 40-->0.8v 237-->4.6v //hhhhhhhhhhhhhhhhhhhhhhhh //////////////////////////////////////////////////////// //中断函数ttttttttttttttttttttttttttttt void tm0_isr(void) interrupt 1 using 1 //1ms { TL0 = 0x20; //Set the initial timing value TH0 = 0xD1; //Set the initial timing value time0_temp1++; if(time0_temp1 % 2 == 0 )//2ms { pid_con_10ms_flag = 1; } if(time0_temp1 >= 10 )//10ms { time0_temp1 = 0; time0_10ms_flag = 1; } time0_temp2++; if(time0_temp2 % 200 == 0)//200ms { get_now_temp_flag = 1; } if(time0_temp2 % 200 == 0)//200ms { //get_now_temp_flag = 1; pid_self_sec_flag = 1; pwm_con_time_flag = 1; enable_pid_sec_flag = 1; special_dis_once_flag = 1; } if(time0_temp2 >= 1000 )//1s If you want 1000 to correspond to 1s, then no interruption can occur in the middle { time0_temp2 = 0; global_sec++; global_sec_flag = 1; three_dot_dis_flag ^= 1; soft_dis_flag = 1; //soft start //ssr_con_1;delay_ms(10);ssr_con_0;//test } } void PCA_Intrrpt(void) interrupt 7 //pwm interrupt { if(CCF0) CCF0=0; if(CCF1) CCF1=0; //software clear if(CF) CF=0; //software clear } //////////////////////////////////////////////////////// //function void Timer0Init(void) //1 millisecond@12.000MHz Timer 0 { AUXR |= 0x80; //Timer clock 1T mode TMOD &= 0xF0; //Set timer mode TMOD |= 0x01; //Set timer mode TL0 = 0x20; //Set the initial timing value TH0 = 0xD1; //Set the initial timing value TF0 = 0; // Clear TF0 flag TR0 = 1; //Timer 0 starts timing ET0 = 1; //enable timer0 interrupt } void io_init(void) { P3M0 = 0x00 ; // 0000 0000 P2M0 = 0xf0 ; // 1111 0000 The lower four bits are the buttons P1M0 = 0xff ; // 1111 1111 strong push-pull output lcd and ssr driver P0M0 = 0x00 ; // 0000 0000 strong push-pull output key_1_in; key_2_in; key_3_in; key_4_in; ssr_con_out; lcd_s_12864_cs_out; lcd_s_12864_reset_out; lcd_s_12864_rs_out; lcd_s_12864_sda_out; lcd_s_12864_sck_out; lcd_s_12864_light_out; lcd_s_12864_cs_0; lcd_s_12864_reset_0; lcd_s_12864_rs_0; lcd_s_12864_sda_0; lcd_s_12864_sck_0; lcd_s_12864_light_0; max6675_so_in; max6675_sck_out; max6675_cs1_out; cs1_1; pwm_con_out; pwm_con_0; } void power_on_event(void)//eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee { int k; for( k = 0; k < 2; k++ ) // flash twice { lcd_s_12864_light_0; delay_ms(200); lcd_s_12864_light_1; delay_ms(200); } //Cite the basic functions, otherwise warning errors will always appear if( refer_fun_flag == 1 ) // Set refer_fun_flag to 0 forever, which means never referencing these functions { // PUTchar8x8(1,1,5,zifu8x8); // PUTchar24x24(1,1,2,zifu24x24); //PUTBMP();//Picture // PUTREVERSEBMP(); //Image is reversed // LcmClear(); //Clear screen // LcmSet(); //Display all, that is, the whole screen is black // LcmInit(); // Initialization // ohengxian(); //O horizontal line program // jihengxian(); // Odd horizontal line program // oshuxian(); //O vertical line program // jishuxian(); //Odd vertical line program // dianxian(); //The point display program is full of points // zifu8x16xian(); //Can display numbers and English // zifu16x16xian(); // can display specific Chinese characters // lcd_dis_position_16_16(1,1,"郑"); // lcd_dis_position_8_16(1,1,'8'); } } //s_12864 lllllllllllllllllllllllllllllll void SendByte(uchar Dbyte) //Send byte data { float i,TEMP; TEMP = Dbyte; for(i=0;i<8;i++) { lcd_s_12864_sck_0; _nop_(); _nop_();
Previous article:Two-way learning fan remote control switch with natural wind MCU source program + circuit
Next article:Please engineer and customize your MCU code
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Xunwei-i.MX6ULL Development Board-Network Test Method (Part 2)
- esp8266 uses oled to play online videos
- Security monitoring multi-channel long-distance transmission problem
- Why does LDMOS conduct without adding gate voltage?
- EEWORLD University Hall----Live Replay: NXP's facial recognition technology solution based on i.MX RT106F
- Function overloading and reentrancy
- Alternative winners in the 5G era
- What Jack Ma said about starting a business...
- Phytec's IMX8Mplus review
- Transplantation of webplayer audio player based on RVB2601