Implementation of intelligent control of touch-type dimming desk lamp based on PIC16F877 microcontroller

Publisher:脑洞飞扬Latest update time:2018-04-01 Source: eefocusKeywords:PIC16F877 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  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

Hardware block diagram of touch-sensitive dimming desk lamp

  The hardware block diagram of the touch-type dimming desk lamp is shown above, and the hardware schematic diagram is shown below.

Touch-type dimming desk lamp hardware schematic diagram

   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.

Software Process

  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.


Keywords:PIC16F877 Reference address:Implementation of intelligent control of touch-type dimming desk lamp based on PIC16F877 microcontroller

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

Application of PIC16F877--AD Converter
The PIC16F877 microcontroller has 8 10-bit A/D converters on the chip. Pins ② to ⑤ are AN0 to AN3, and ⑦ to ⑩ are AN4 to AN7. On the MPLAB-ICD experimental board, the RA0 port of the 16F877 microcontroller is connected to a 10kΩ potentiometer with voltage, and 8 LEDs are connected to the D port (RD0 to RD7), as shown
[Microcontroller]
Application of PIC16F877--AD Converter
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号