Design and production of three-way sectional switch based on AT89C2051 microcontroller
Source: InternetPublisher:ghaytweyhtoo Keywords: at89c2051 microcontroller lighting control segmented switch Updated: 2021/05/03
Segment switch is an energy-saving electronic product. When there are only two power cords, it can be used to control lamps with multiple bulbs, fluorescent lamps, and energy-saving lamps in groups, avoiding the pain of rewiring the lighting circuit. Common segmented switches are controlled by one-position switches, which produce different lighting states by switching different times. This control method has two flaws: first, the bulbs are constantly switched on and off during the control process. Since the service life of bulbs, fluorescent lamps, and energy-saving lamps is closely related to the number of switches, this method can easily cause damage; second, the use It is more troublesome. If there are three groups of lights in the lamp, you must switch on and off four times to turn on all the lights. The following introduces a three-way segmented switch designed with a single-chip microcomputer. A switch and three buttons are used on the control panel. After turning on the switch, you only need to press different buttons to control different lamp groups. The three groups of lamps are independently controlled. Intuitive and easy to use features.
1. Circuit working principle
The segment switch consists of a control panel and a receiving controller. The control panel is installed on the switch box, and the receiving controller is installed on the lamp. The control panel and receiving controller are connected with two power cords. 'The control signal adopts the power carrier method and is transmitted through the power line. In order to prevent interference from the 50Hz AC power supply and facilitate separation, a 100kHz high-frequency pulse signal is used as the control signal. In order to simplify the circuit, pulse counting is used to distinguish different control signals.
1. Control panel circuit
The control panel mainly generates different control signals to control different light groups.
See the circuit diagram below. NAND gates A1, A2, resistors R1~R4, capacitors C1~C3, etc. in IC1 form a delay circuit. The following takes pressing S1 as an example to illustrate its working principle: when S1 is not pressed, the input terminal of A1 is low level, so A2 also outputs low level after two inversions; when S1 is pressed, because C1 The voltage on A1 cannot change suddenly. The input terminal of A1 is high level, and A2 also outputs high level. After that, the voltage at both ends of C1 gradually rises after being charged by R4, and the potential of the input terminal of A1 gradually decreases. When the potential drops to VDD/2, which is 4.5V When below, the output of A2 changes from high level to low level. In this way, when buttons S1NS3 are pressed respectively, the A2 output terminal generates three different single positive pulse signals with pulse widths of 15mS, 23mS, and 34mS respectively, which are used as control signals of the multivibrator. NAND gates A1, A2, resistors R5, R6, capacitor C5, etc. form a multivibrator with an oscillation frequency of about 100kHz. When A2 outputs a high level, the multivibrator works, and A4 outputs a 100kHz pulse signal. Since the number of its output pulse signals is controlled by the high-level time of A2's output, A4 can output different pulse numbers by pressing different buttons in S1 to S3. The corresponding pulse numbers are approximately 1500, 2300, 3400. Transistor VTl, high-frequency transformer T1, etc. form an output circuit. The pulse signal output by A4 is amplified by VT1 and then transmitted to the power line through C8. L1 is a high-frequency choke inductor, which can prevent the 100kHz pulse signal from being short-circuited by other electrical equipment and prevent it from generating external interference signals.
C7, VD2, VD3, C6, etc. form a capacitor step-down power supply circuit, in which the 9V power supply stabilized by the voltage stabilizing diode VD1 is used by IC1.
2. Receive controller circuit
The receiving controller circuit is shown in Figure 2. The circuit is composed of receiving circuit, microcontroller circuit and power supply circuit.
R1 and C1 form the reset circuit of the microcontroller. After the power is turned on, pin 1 of the reset terminal of the microcontroller AT89C2051 receives a high-level reset pulse, causing the microcontroller to enter the initial state set by the program. Its pin P1.0 outputs a high level. P1~1 and P1.2 output low level, the transistor VTl is turned on, and VT2 and VT3 are turned off, causing the relay K1 to be closed and K2 and K3 to be in the released state. In this way, when the switch S4 on the control panel is turned on, the first set of lights will light up. , the other two sets of lights are off. When in use, a commonly used set of lights is generally connected to the control contact of K1.
C4, T1, \/T1, etc. form an input signal processing circuit. C4 plays the role of isolating 50Hz AC signals. In order to improve the anti-interference ability, VT1 does not add a DC bias voltage, and its collector outputs a pulse signal with an amplitude of 5V. The input is sent to the microcontroller through the P3.4 pin of the microcontroller for processing. The microcontroller determines to change the working status of pins P1.0~P1.2 based on the number of input pulse signals. Specifically, about 1500 pulse signals correspond to P1.0, and about 2300 pulse signals correspond to P1.1. About 3400 pulse signals correspond to P1.2.
The following uses the second circuit as an example to illustrate the working process of the circuit. After turning on the power, press button S2, and the P1.1 terminal of the microcontroller will be converted from low level to high level. Relay K2 will be closed, and the corresponding normally open contact will be closed. Click k2 to close and turn on the corresponding lamp group. Press S2 again to switch the P1.1 terminal of the microcontroller from high level to low level and turn off the corresponding lamp group. The working process of the other two routes can be deduced in the same way. When controlling the working status of one channel, the working status of the other two channels will not be affected, that is, each channel can be controlled independently.
C5, VD4~VD8, IC2, etc. form a capacitor step-down power supply circuit, providing +12V and +5V power. The function of L1 in the circuit is the same as L1 in the control panel circuit.
2. Program introduction
The program is written in C language, and the timer TO is set as a counter, and pin P3.4 is used as the input terminal of the counting pulse. The timer T0 counts the input pulse signal. By judging the number of pulses, it can know which switch is pressed on the control panel, thereby changing the working state of the corresponding relay.
The program list is as follows:
#include
unsignedchari,DelayTime;
unsignedintn:
sbitP1_O=p1^0;
sbitP1_1=P1^1;
sbitP1_2=P1^2;
sbitP3_4=P3^4;
voiddelay(DdayTime)//Delay subroutine
{
for(;DelayTime>0;DelayTime——)
{
for(i=0;i<250;i++);
}
}
voiDMAin(void)//main program
{
P1_0=1;
P1_1=O;
P1_2=0;
TMOD=0x05;
//Timer TO works in mode 1 counting
TH0=0;
TL0=O:
TRO=1: //Open timer TO
for(;;)
{
while(P3_4=1);//Judge whether there is
input pulse
TR0=1: //Open timer TO
delay(50);
//Delay 50mS and let timer TO count
TRO=O: //Turn off timer TO
n=TL0ㄧ(TH0<<8);//Get the count value
TH0=0;
TLO=O:
if(n>1300&&n<1700)//ruomai
The middle number is about 1500
P10=!P10://P1.O lose
Output level inversion
elseif(n>2000&&n<2600)//if
The number of pulses is about 2300
P1_1=!P1_1;//P1.1 loses
Output level inversion
elseif(n>3000&&n<3800)//if
The number of pulses is about 3400
P1_2=!P1_2;//P1.2 loses
Output level inversion
}
}
In the program, "while(P3_4==1):" detects whether the P3.4 pin is at high level. When the control panel does not send out a pulse signal, the P3.4 pin is always at a high level, and the program is in a waiting state; once a pulse signal is sent out After that, the P3.4. pin will appear low level. After the program is detected, it will be executed downwards. The timer T0 counts the pulse signal input by the P3.4 pin. Since the longest duration of the control signal sent by the control panel is 34mS, 50mS is selected here to allow the timer TO to count to ensure that the pulse signal is not lost. After counting, the program screens the count values. Since the control panel uses an RC oscillator, its frequency stability is poor. In order to improve the reliability of the circuit operation, a certain error is allowed in the number of pulse signals during screening.
3. Installation and debugging
In the control panel, IC1 uses CMOS NAND gate integrated circuit CD4011, and capacitors C1, C2, C3, and C5 use polyester capacitors with good stability to ensure the stability of the circuit. S1~S4 use touch button switches. The inductor L1 core uses an E16 ferrite core and is wound with φ0.41 enameled wire for 100T. The high-frequency transformer T1 uses an E13 ferrite core and is wound with a φ0.19 enameled wire for 200T primary and 200T secondary. Wind around 50T.
In the receiving controller, IC1 uses ATMEL's AT89C2051 microcontroller integrated circuit, and IC2 uses a low-power three-terminal voltage stabilizing integrated circuit 78L05. X1 uses a 12MHz quartz crystal. VD1~VD7 use rectifier diode 1N4004, VT1 uses transistor 2SC945, VT2~VT4 use transistor 2SCl815. Relays K1 to K3 use model HRS1-S, 12VDC relays, and their contact loads are 3A120/220VAC.
The L1 parameters in the inductor L1 control panel are the same. The high-frequency transformer T1 uses an E13 ferrite core, and uses φ0.19 enameled wire to wind 100T on both the primary and secondary ends. .
Before installation, use a programmer to write the compiled target file switch.hex into the AT89C2051 chip.
After the installation is completed, the debugging work is mainly to adjust the delay time of the control panel and the oscillation frequency of the multivibrator. During debugging, turn on the power switch S4 of the control panel, and then press the button switches S1, S2, and S3 in sequence to see the receiving controller. Is there any action of the corresponding relay in the circuit? If there is no response, if there is no problem with the circuit, it may be that the output frequency error of the control panel is large. Appropriate adjustment of the parameters of R6 or C5 in the circuit can solve the problem. If conditions permit, You can use a frequency meter to measure the output frequency of A4, and connect the input terminal of A1 to +9V with a wire to measure. After this, if there is no response when pressing a certain button switch, it means that the delay error of this path is large, and the capacity of its corresponding delay capacitor can be changed. Finally, press the three buttons S1~S3 of the transmitter in sequence. If the working status of the corresponding three-way relays can change, the debugging work is completed.
- LED acceleration and deceleration motion display composed of CD4017
- Delayed gradual lighting with protection function
- Practical sensitive light-controlled switch circuit diagram
- Electronic massage and acupuncture device circuit
- One of the water full alarm circuits
- Lighting lamp voltage stabilizing circuit (2)
- Resistor value selection circuit
- Gas flameout alarm circuit
- Application circuit of CAT3606
- Temperature control alarm circuit
- Simple laser flashlight circuit diagram
- Negative voltage generation circuit diagram
- Data transmission interface circuit design of automobile driving recorder
- Homemade simple and practical emergency light circuit diagram
- Minimum system interface circuit based on AT89C52 microcontroller
- Driving circuit diagram
- Signal input circuit a
- Wiring of the power supply part of the microcontroller
- Typical circuit for connecting MAX1101 and microcontroller
- Microcontroller remote key input circuit