Note: The microcontroller must be 52rc and cannot be 60s2
*/
#include "main.h"
#include "peizhi.h"
#include "smg.h"
#include "eeprom.h"
sfr WDT_CONTR=0XE1;
unsigned char HighRH = 0; //high byte of high level reload value
unsigned char HighRL = 0; //low byte of high level reload value
unsigned char LowRH = 0; //high byte of low level reload value
unsigned char LowRL = 0; //low byte of low level reload value
/**************************Button definition**********************************/
bit d1 = 1;
bit d2 = 1;
bit d3 = 1;
uint8 ci;
uint8 ca = 0;
uint8 ca1 = 0;
uint16 cb = 0;
void key(); //Key function declaration
void ConfigPWM(unsigned int fr, unsigned char dc); //Frequency and duty cycle adjustment function
void main()
{
bit q1 = 1;
bit q2 = 1;
bit q3 = 1;
ca = EEPROMReadByte(0);
cb = EEPROMReadByte(1)*255+EEPROMReadByte(2);
EA = 1; // Enable general interrupt
peizhit1(1); //Configure T0 timing 2ms
while(1)
{
ConfigPWM(cb, ca); //Frequency 100Hz, duty cycle 10%
if(d1 != q1)
{
q1 = d1;
if(d1 == 0)
{
ca1++;
if(ca1 >= 2)
{
ca1 = 0;
}
}
}
if(ca1 == 1)
{
if(d2 != q2)
{
q2 = d2;
if(d2 == 0)
{
ca++;
EEPROMSectorErase(0);
EEPROMWriteByte(0,ca);
EEPROMWriteByte(2,cb);
EEPROMWriteByte(1,cb>>8);
if(ca >= 99)
{
ca = 99;
}
}
}
if(d3 != q3)
{
q3 = d3;
if(d3 == 0)
{
if(ca>0)
{
ca--;
EEPROMSectorErase(0);
EEPROMWriteByte(0,ca);
EEPROMWriteByte(2,cb);
EEPROMWriteByte(1,cb>>8);
}
}
}
}
if(ca1 == 0)
{
if(d2 == 0)
{
cb++;
EEPROMSectorErase(0);
EEPROMWriteByte(0,ca);
EEPROMWriteByte(2,cb);
EEPROMWriteByte(1,cb>>8);
if(cb >= 200)
{
cb = 200;
}
}
if(d3 == 0)
{
if(cb>0)
{
cb--;
EEPROMSectorErase(0);
EEPROMWriteByte(0,ca);
EEPROMWriteByte(2,cb);
EEPROMWriteByte(1,cb>>8);
}
}
}
xianshi1(cb);
xianshi2(ca);
}
}
void key()
{
static uint8 saomiaozhi[] = {1,1,1,1};
saomiaozhi[0] = (saomiaozhi[0]<<1) | in1;
saomiaozhi[1] = (saomiaozhi[1]<<1) | in2;
saomiaozhi[2] = (saomiaozhi[2]<<1) | in3;
if(saomiaozhi[0] == 0x00)
{
d1 = 0;
}
if(saomiaozhi[0] == 0xff)
{
d1 = 1;
}
if(saomiaozhi[1] == 0x00)
{
d2 = 0;
}
if(saomiaozhi[1] == 0xff)
{
d2 = 1;
}
if(saomiaozhi[2] == 0x00)
{
d3 = 0;
}
if(saomiaozhi[2] == 0xff)
{
d3 = 1;
}
}
/* Configure and start PWM, fr-frequency, dc-duty cycle*/
void ConfigPWM(unsigned int fr, unsigned char dc)
{
unsigned int high, low;
unsigned long tmp;
tmp = (11059200/12) / fr; //Calculate the count value required for one cycle
high = (tmp*dc) / 100; //Calculate the count value required for the high level
low = tmp - high; //Calculate the count value required for the low level
high = 65536 - high + 12; //Calculate the high level reload value and compensate for interrupt delay
low = 65536 - low + 12; //Calculate the low level reload value and compensate for interrupt delay
HighRH = (unsigned char)(high>>8); //Split the high-level reload value into high and low bytes
HighRL = (unsigned char)high;
LowRH = (unsigned char)(low>>8); // split the low level reload value into high and low bytes
LowRL = (unsigned char)low;
TMOD &= 0xF0; // Clear the control bit of T0
TMOD |= 0x01; //Configure T0 to mode 1
TH0 = HighRH; //Load T0 reload value
TL0 = HighRL;
ET0 = 1; // Enable T0 interrupt
TR0 = 1; //Start T0
PWMOUT = 1; //output high level
}
/* T0 interrupt service function, generate PWM output */
void InterruptTimer0() interrupt 1
{
if (PWMOUT == 1) //When the current output is high, load the low level value and output low level
{
TH0 = LowRH;
TL0 = LowRL;
PWMOUT = 0;
}
else //When the current output is low level, load the high level value and output high level
{
TH0 = HighRH;
TL0 = HighRL;
PWMOUT = 1;
}
}
/* T0 interrupt service function, complete digital tube, key scanning and stopwatch counting*/
void t1() interrupt 3
{
TH1 = T1RH; //Reload the reload value
TL1 = T1RL;
ci++;
ssmg(); //digital tube scanning
if(ci>=2)
{
ci = 0;
key();
}
}
Previous article:MCU key long and short press source program (no need to wait to determine)
Next article:SUKON touch screen learning microcontroller modbus communication program
Recommended ReadingLatest update time:2024-11-15 18:28
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
- Ranking of installed capacity of smart driving suppliers from January to September 2024: Rise of independent manufacturers and strong growth of LiDAR market
- Industry first! Xiaopeng announces P7 car chip crowdfunding is completed: upgraded to Snapdragon 8295, fluency doubled
- P22-009_Butterfly E3106 Cord Board Solution
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- How to perform on-site PIM testing on RF connectors?
- IAR IDE for MSP430, 8051, ARM and other platforms
- What does damping coefficient mean? What is the damping coefficient KD value?
- There is a chip shortage now. Are there any domestic chips that can replace this buck-boost chip from Lingte? LTC1517ES5-3.3, SOT...
- MSP430 MCU Development Record (7)
- EEWORLD University Hall ---- EMC pre-test environment construction
- Restraining the complexity of embedded system design
- Device Basics - The Impact of Capacitor Self-resonance Frequency on Selection
- [Zhongke Bluexun AB32VG1 RISC-V Evaluation Board] Try to use RTThread multitasking
- CC3200 wireless wifi processor full voice interactive control smart home system