This article systematically describes how to use the PIC16F877 microcontroller to realize the intelligent control of a touch-type dimming desk lamp, achieving (1) touch dimming; (2) filament preheating; (3) automatic elimination of glare and flicker; (4) timer alarm; (5) distinctive ringtones; (6) hourly time announcement; (7) event reminder; (8) calendar function; (9) Chinese LCD display and other functions, meeting the quality standards of safety, high efficiency, no glare, no flicker, and complete functions.
hardware design
1.PIC16F877 controller
The PIC16F877 microcontroller is a FLASH CPU from MicroChip. It contains 8K of FLASH program storage area, 368 bytes of RAM, 256 bytes of EEPROM, 35 independent I/0 ports, a 16-bit counter/timer, two 8-bit counter/timers, 14 interrupt sources that can be used independently or nested, 2 capturers, comparators, PWM modules, 8-channel 10-bit A/D, built-in watchdog WDT and power monitoring, and multiple power saving modes such as sleep and wait. The I/0 port can directly drive the LCD.
2. Hardware circuit design
The hardware block diagram of the touch-type dimming desk lamp is shown above, and the hardware schematic diagram is shown below.
In the figure above, C1 and T1 form an EMI filter, which can reduce the interference of the ballast to the power grid on the one hand, and prevent other electrical equipment from interfering with the ballast on the other hand; V1-V4 form a bridge rectifier; C3, C4, V5, V6 and R21 form a passive power factor correction circuit, so that the power factor reaches above 0.9. To ensure the service life of the power lamp, the power peak factor of the circuit should be less than 1.7. This article uses the capture function of the PIC16F877 microcontroller to feedback and read back the frequency, and takes corresponding measures according to the change of frequency to change the input of IR2151, thereby controlling the output frequency of IR2151 and achieving the purpose of controlling the output power. This method can make the light source more stable, eliminate glare and strobe, and achieve the effect of eye protection lamp.
When the touch dimming lamp is working, by touching the metal sheets A (light key) and B (dark key), the human body noise signal is added to the I/O port of the MCU through the coupling capacitor for detection. At the same time, the coupling capacitor can also prevent the numbness caused by damage to individual components. The MCU analyzes and calculates the detected signal through the program, and outputs the PWM signal from pin 17 to IR2151 to control the oscillation frequency. The oscillator is output through the high-end (HO) and low-end (LO) pins to drive the two field effect tubes IRF830 to alternately turn on and off, so as to achieve the purpose of controlling the lamp.
The preheating of the filament is controlled by the thermistor. After power is turned on, the 6th pin of IR2151, the inductor L1, the capacitor C1O, and the Cl3 form a series resonant circuit, and a high voltage is generated on Cl3 and applied to both ends of the lamp tube to light the lamp. Among them, RT is a thermistor with a positive temperature coefficient, which plays a role in preheating the filament; after the power is turned on, almost all the filament current is loaded on C1O and RT. Since the capacitance of C1O is large, the LC series circuit does not resonate. As the temperature rises, the resistance of RT increases rapidly, and the RT branch is equivalent to an open circuit) so that the LC series circuit resonates, that is, the filament is preheated and soft-started, which prolongs the service life of the lamp tube. The MCU monitors and adjusts the entire process at all times to achieve true intelligent control.
software design
The software design consists of six parts: MCU initialization, device self-test, timed sampling, interrupt processing, LCD display, and key processing. The software flow is shown in the figure below.
The timer interrupt subroutine is the core of the software design, which includes humidity, humidity sampling, dimming, glare removal and other controls. This article does not have very strict requirements on the accuracy of temperature and humidity. The sampling period is set to 1 minute, and the average value is calculated by sampling 5 points , and the accuracy meets the sampling requirements.
The timer initialization subroutine is as follows;
/***********Timer initialization*******/
void tmint(void)
{
I NTC ON = 0X00;
/********Disable interrupt***********/
GIE=1;
/***********General interrupt enable INTCON.7**********/
PEIE=1;
/*********Peripheral interface interrupt enable bit, must be set to 1 otherwise TMR1
It doesn't work ************/
TMR1IE=1;
/**********TMR1 overflow interrupt enable bit**********/
T1 CON = 0X24;
/******************Prescaler 1 :4 temporarily do not open TMR1***********/
TMR1 L = 0X77;
TMR1 H = 0XEC;
/**************Timer is initialized to 20ms and interrupted once******************/
TMR1ON=1;
/***********Start TMR1 to start counting. T1CON.0**************/
}
The timer interrupt subroutine is as follows:
/************Timer interrupt***********/
void interrupt clkint(void)
{
int i,j,k:
for(i=1:i<5:i++)
{
adwd_h[i]=adwd_h[i+1];
adwd_I[i]=adwd_I[i+1];
/**Temperature sampling value shift, top out the first bit, new value is stored in 5 bits***/
}
int m, n, t;
for(m=1;m<5;m++)
{
adsd_h[m]=adsd_h(m+1]);
adsd_I[m]=adsd_I[m+1];
/***Temperature sampling value shift, top out the first bit, new value is stored in 5 bits*****/
}
ADCONO=Ox41;
/*****Clock source F/8, AO channel, A/D operation enabled**********/
ADCON 1 = 0x82;
/********The result is right aligned***********/
delayms(1);
/***************Waiting for sampling, the sampling capacitor charging time improves accuracy**************/
ADCONO = 0x04;
/**********Start A/D conversion GO.ADCON0.2***********/
while(ADIF==1)
/*********** Set ADIF when conversion ends, PIR1.6**********/
{
adwd_h[5]=ADRESH;
adwd_I[5]=ADRESL;
/**********Store temperature sampling results**********/
}
ADCON0 = 0x51;
/**********Clock source F/8, A1 channel, allow A/D to work**********/
ADCON1 = 0x82;
/*****Result right-aligned**********/
delayms(1);
/**************Waiting for sampling, sampling capacitor charging time——improve accuracy************/
ADCON0ㄧ=0×04;
/********Start A/D conversion GO, ADCON0.2********/
while(ADIF==1)
/*******Wait for the conversion end bit ADIF to be set to 1, PIR1.6***********/
{
adsd_h[5]=ADRESH;
adsd_1[5]=ADRESL;
/**********Store temperature sampling results**********/
}
TMR1 IF=0;
/*******Clear interrupt flag********/
TMR1 L = 0X77;
TMR1 H = 0XEC;
/********Timer re-initializes 20ms interruption once***********/
}
Function Description
To ensure a smooth transition in the brightness adjustment of the desk lamp, this article sets 8 levels of dimming: lightly touch the light key on metal piece A, the light will go from off to on, and then each time you touch the light key, the brightness of the desk lamp will increase by one level, and at the 8th level the lamp reaches its brightest, and thereafter the brightness will not increase after pressing the light key. The function of the dark key on metal piece B is opposite to that of the light key, and each time you press it the brightness decreases by ~ levels until it goes out, and the corresponding status is displayed on the LCD.
Other functions can be set by pressing different buttons to enter the corresponding function menu, and the menu is displayed in pure Chinese. In addition, you can set the hourly voice time, 3 fixed-day alarms and event reminders. Each alarm cycle can be set separately. The event reminder function includes meetings, appointments, weddings, sports, spare time learning, and other events. The reminder includes three options: 1 day in advance, 1 hour in advance, and 10 minutes in advance.
Due to the limited storage capacity of the MCU, in addition to the fixed alarm tones, the following four more distinctive voice tones are available for selection: (1) Lazy pig, get up, or I'll carry you out; (2) Baby, get up, the sun is shining on your butt; (3) Get up quickly, get up quickly, you'll be late; (4) Your scheduled time is up, go do your work.
Previous article:How to use PIC16F5X to implement asynchronous serial I/O port
Next article:Implementation of intelligent control of aromatherapy beauty steam bath room based on PIC16F877
Recommended ReadingLatest update time:2024-11-15 15:08
- 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
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- EEWORLD University ---- Introduction to Intelligent Control
- Free application: National Technology dual-core, with CAN Bluetooth N32WB452 is here
- Unboxing experience of ST MEMS sensor board (IKS01A3) based on STM32F411RE!
- Smart locks and electric cars are trending on the Internet because the weather in Beijing is too cold!
- 101 Examples of Application Skills of Simulation Technology
- MSP430 common program architecture
- [ESP32-Audio-Kit Audio Development Board Review] 2. Download Audio Firmware
- [Construction Monitoring and Security System] 7. Kaluga Test TCP Client
- Solution to packet loss when connecting to server in WinXP system
- [New Year's atmosphere competition] + Blue sky, white clouds, spring, flowers, Yunnan and Guizhou self-driving tour to celebrate the New Year