//I didn't use the IAPIDLE function. Is there any expert who can give me some advice on the pros and cons?
#include <STC15F104E_PLUS.h>
#include typedef unsigned char BYTE; typedef unsigned int WORD; //#define uint unsigned int //#define MAIN_Fosc 22118400L //Define the main clock //#define MAIN_Fosc 12000000L //Define the main clock #define MAIN_Fosc 11059200L //Define the main clock //#define MAIN_Fosc 5529600L //Define the main clock //#define MAIN_Fosc 24000000L //Define the main clock //#define MAIN_Fosc 40000000L //Define the main clock //#define ENABLE_IAP 0x80 //if SYSCLK<30MHz //#define ENABLE_IAP 0x81 //if SYSCLK<24MHz //#define ENABLE_IAP 0x82 //if SYSCLK<20MHz #define ENABLE_IAP 0x83 //if SYSCLK<12MHz //#define ENABLE_IAP 0x84 //if SYSCLK<6MHz //#define ENABLE_IAP 0x85 //if SYSCLK<3MHz //#define ENABLE_IAP 0x86 //if SYSCLK<2MHz //#define ENABLE_IAP 0x87 //if SYSCLK<1MHz #define CMD_IDLE 0 //Idle mode #define CMD_READ 1 //IAP byte read command #define CMD_PROGRAM 2 //IAP byte programming command #define CMD_ERASE 3 //IAP sector erase command //Test address #define IAP_ADDRESS1 0X0000 //Internal EEPROM address #define IAP_ADDRESS2 0X0200 /* Initial definition */ bit write = 0; sbit VD=P3^3; //Red LED 0.50v=10v ;1.00=27v ;3.85=73v; sbit CD=P3^4; //Green LED sbit ZS=P3^5; //Indicates LED switching 0 - Red LED adjustment; 1 - Green LED adjustment sbit BA=P3^0; //Connect encoder pin a to P3.0 sbit BB=P3^1; //Connect encoder's pin b to P3.1 sbit QH=P3^2; //Encoder button connected to P3.2 voltage adjustment or current adjustment 299=5.00V BYTE v_temp,c_temp,XZ = 0,flag,a0,b0,c0;// 128 109 48 29 //48=0.96V;29=0.58V; void InitTimer0() interrupt 1 // 0.5 milliseconds @ 11.0592MHz frequency 1000HZ { IE2 = 0x00; //Disable timer 2 interrupt AUXR = 0XE4; // turn off timer 2 counting TL0 = 0xCD; //Set the initial timing value to 0.5 milliseconds @ 11.0592MHz TH0 = 0xD4; //Set the initial timing value to 0.5 milliseconds @ 11.0592MHz CEO = 1; CD = 1; flag = 1; AUXR = 0xF4; //Start timer 2 counting IE2 = 0x04; // Enable timer 2 interrupt } void InitTimer2() interrupt 12 //2 microseconds @ 11.0592MHz to control the light on time { flag++; T2L = 0xD4; //Set the initial timing value to 2 microseconds @ 11.0592MHz T2H = 0xFF; //Set the initial timing value to 2 microseconds @ 11.0592MHz if(v_temp == flag) VD=0; if(c_temp == flag) CD=0; } /*//Disable IAP void IapIdle() { IAP_CONTR = 0; //Disable IAP function IAP_CMD = 0; // Clear command register IAP_TRIG = 0; // Clear the trigger register IAP_ADDRH = 0x80; //Set the address to the non-IAP area IAP_ADDRL = 0; } */ //Read a byte from the ISP/IAP/EEPROM area BYTE IapReadByte(WORD addr) { BYTE dat; //data buffer IAP_CONTR = ENABLE_IAP; //使能IAP IAP_CMD = CMD_READ; //Set IAP command IAP_ADDRL = addr; //Set IAP low address IAP_ADDRH = addr >> 8; //Set IAP high address IAP_TRIG = 0x5a; //Write trigger command (0x5a) IAP_TRIG = 0xa5; //Write trigger command (0xa5) _nop_(); //Wait for ISP/IAP/EEPROM operation to complete dat = IAP_DATA; //Read ISP/IAP/EEPROM data //IapIdle(); //Disable IAP function return dat; //return } //Write one byte of data to the ISP/IAP/EEPROM area void IapProgramByte(WORD addr, BYTE dat) { IAP_CONTR = ENABLE_IAP; //使能IAP IAP_CMD = CMD_PROGRAM; //Set IAP command IAP_ADDRL = addr; //Set IAP low address IAP_ADDRH = addr >> 8; //Set IAP high address IAP_DATA = dat; //Write ISP/IAP/EEPROM data IAP_TRIG = 0x5a; //Write trigger command (0x5a) IAP_TRIG = 0xa5; //Write trigger command (0xa5) _nop_(); //Wait for ISP/IAP/EEPROM operation to complete //IdleIdle(); } // sector erase void IapEraseSector(WORD addr) { IAP_CONTR = ENABLE_IAP; //使能IAP IAP_CMD = CMD_ERASE; //Set IAP command IAP_ADDRL = addr; //Set IAP low address IAP_ADDRH = addr >> 8; //Set IAP high address IAP_TRIG = 0x5a; //Write trigger command (0x5a) IAP_TRIG = 0xa5; //Write trigger command (0xa5) _nop_(); //Wait for ISP/IAP/EEPROM operation to complete //IdleIdle(); } /*void Timer0Init(void) //100 microseconds @ 24.000MHz 10KHZPWM { AUXR |= 0x80; //Timer clock 1T mode TMOD &= 0xF0; //Set timer mode TL0 = 0xA0; //Set the initial timing value--100 microseconds @ 24.000MHz TH0 = 0xF6; //Set the initial timing value--100 microseconds @ 24.000MHz TF0 = 0; // Clear TF0 flag TR0 = 1; //Timer 0 starts timing } void Timer2Init(void) //0.4 microseconds @ 24.000MHz { AUXR |= 0x04; //Timer clock 1T mode T2L = 0xF6; //Set the initial timing value--0.4 microseconds @ 24.000MHz T2H = 0xFF; //Set the initial timing value--0.4 microseconds @ 24.000MHz AUXR |= 0x10; //Timer 2 starts timing } */ void bianmaqi(void) //Capture EC11 press and rotation information { unsigned char a, b, c; a = BA; b = BB; c = QH; if (a != a0) // BA changed { a0 = a; if (b != b0) // BB changed { b0 = b;write = 1; if ((a == b) && (XZ == 0) && (v_temp < 153)) {v_temp++;}//225 153 if ((a == b) && (XZ == 1) && (c_temp < 73)) {c_temp++;}//208 65 if ((a != b) && (XZ == 0) && (v_temp > 23)) {v_temp--;}//85 23 if ((a != b) && (XZ == 1) && (c_temp > 5)) {c_temp--;}//29 5 } } if (!c && c0) { if (XZ == 0 ) { XZ = 1; ZS = 1; } else if(XZ == 1)//switch { XZ = 0; ZS = 0; } } c0 = c; } void init() { AUXR = 0XE4; //Set timer 0 and 2 to 1T mode TMOD = 0x00; TL0 = 0xCD; //Set the initial timing value to 0.5 milliseconds @ 11.0592MHz 0xA0; -- 100 microseconds @ 24.000MHz TH0 = 0xD4; //Set the initial timing value to 0.5 milliseconds @ 11.0592MHz 0xFF; -- 0.4 microseconds @ 24.000MHz T2L = 0xD4; //Set the initial timing value to 2 microseconds @ 11.0592MHz 0xF6;--0.4 microseconds @ 24.000MHz T2H = 0xFF; //Set the initial timing value to 2 microseconds @ 11.0592MHz 0xFF;--0.4 microseconds @ 24.000MHz EA = 1; ET0 = 1; TR0 = 1; //Timer 0 starts timing P3M1 &= 0xF7; P3M0 |= 0x08; //P3.3 (push-pull) P3M1 &= 0xEF; P3M0 |= 0x10; //P3.4 (push-pull) P3M1 &= 0xDF; P3M0 |= 0x20; //P3.5 (push-pull) CEO = 0; CD = 0; ZS = 0; // 0 - voltage regulation state; 1 - current regulation state a0 = NO; b0 = BB; c0 = QH; v_temp = IapReadByte(1); if (v_temp == 0 ){v_temp = 65;} //128 65 if (v_temp > 153){v_temp = 65;} //245 128 c_temp = IapReadByte(10); if (c_temp == 0 ){c_temp = 29;} //109 if (c_temp > 29 ){c_temp = 29;} //208 109 } void main() { heat(); while(1) { bianmaqi(); if (write == 1) { write = 0;TR0 = 0; IapEraseSector(IAP_ADDRESS1); //Erase sector if (XZ == 0 ) { IapProgramByte(1,v_temp); //Write data } else if (XZ == 1 ) { IapProgramByte(10,c_temp); //Write data } } _nop_(); TR0 = 1; } }
Previous article:DS18B20 single chip digital thermometer
Next article:Body temperature monitoring sound and light alarm device based on DS18B20
- Popular Resources
- Popular amplifiers
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
- Want to make an embedded machine learning wearable system
- Web front-end/back-end matters, non-technical issues!
- A large bounce occurs on the DC power supply
- For four-layer boards, high-power routing issues
- Multi-input six-level energy efficiency standard
- LIS3DH evaluation board STEVAL-MKI105V1 data
- TMS320C6748 DSP Development Kit (LCDK)
- [RVB2601 Creative Application Development] 6. Online Weather Clock Draft Version
- [Silicon Labs BG22-EK4108A Bluetooth Development Review] Part 3: Bluetooth-Soc Blinky Example Development Experience
- Analysis of the effect of resistance between the be electrodes of PNP transistors