Use microcontroller to make simple timing controller for electric fan
Source: InternetPublisher:太白金星 Keywords: Microcontroller timing controller Updated: 2023/11/27
1. Design ideas:
Start powering the microcontroller through manual keys. Until the power indicator LED4 lights up. When the microcontroller is running, relay 2 works to supply power to the microcontroller. Set the working time of relay 2 by pressing the button to realize automatic power-off of the system. By setting the working time of relay 1, the intermittent rotation of the fan is realized to achieve energy saving.
1. Display part: Use the button to switch the display between fan rotation time, pause time, and system shutdown remaining time. The digital display shows two digits, which are "minutes" running time, and the remaining time when the system is shut down is "hours" running time. The LEDs are red, yellow, and blue, which respectively light up the corresponding fan rotation, pause, and system shutdown remaining time status.
2. Button part:
K1 is the time adjustment shift key. Press this key, the number will flash, and the corresponding light will flash at the same time. Switch between fan spin time, pause time, and system
K2 is the plus one and status switching display key. When K1 is pressed, the time will be plus one. Otherwise, the display switches between fan rotation time, pause time, and system.
K3 is a minus 1 and backup key. When K1 is pressed, it adds 1 to the time, otherwise it is invalid.
3. Relay part:
Relay 1 controls the power cord of the fan to realize the rotation and temporary operation of the fan.
Relay 2 controls the power supply of the microcontroller system to achieve scheduled shutdown of the system.
System name:Electronic Fan simple timing controller
Creator: w418781840 Date: 2008.7.6
System function:
******************************** ****************/
/********************************** *************
Function name: Declaration area
function description:
******************************* ***************/
#include
Function name: display Function
description: Display minute time, two digits.
****************************************** ********/
void display(void)
{
uchar i,scan=1;
for(i=0;i<2;i++)
{ SEG=0xff;
DIG=~scan;
SEG=TAB[dis[ i]];
delay1ms(5);
scan<<=1;
}
}
/******************************** *************
Function name: Delay 5MS Function
description: Key debounce call.
********************** **********************/
void delay5ms(uchar x)
{
uchar j;
for(j=0;j
Function name: initialization Function
description: Initialization of each variable.
****************************************** ****/
void init()
{ fliflag=0; //Flashing flag.
cflag=1; //Fan status flag.
zflag=0; //Rotating flag.
x=30; //Temporary storage
y=10; //Temporary storage
CLED=1;//System work.
sum=0; //Shift
start=30; //Fan rotation time
stop=10; //Pause time.
close=5; //Remaining system shutdown time
count_T0 =0; //T0, T1 related
count_T1=0;
c_count=0;
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256 ;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
}
/************************ ************************
Function name: Separation function
Function description: Separately display tens and ones digits
**************** *************************************/
void disnner(void)
{ if(cflag==1)/ /1
{ RLED=0;YLED=1;BLED=1;//The red light flashes.
time=start; //Display the rotation time.
}
if(cflag==2)
{ RLED=1;YLED=0;BLED= 1;
time=stop;
}
if(cflag==3)
{ RLED=1;YLED=1;BLED=0;
time=close;
}
dis[0]=time/10;
dis[1]=time%10;
}
/************************************************
Function name: T0 interrupt function
function description: generated for 1 minute.
**************************************** ******/
void timer0(void)interrupt 1
{ TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if(++count_T0==1200)//One minute.
{ count_T0=0;
if(zflag==0) //It is 0
{ ZLED=1; //Rotate.
if(start!=99)//The rotation time is 99, display 99, do not switch the flag. Keep rotating.
{
start--; //No, then countdown.
if(start==0)
{ zflag=1;//The countdown time is up. Switch the flag.
cflag=2;
start=x;//Reassign the value
}
}
}
else
{ ZLED=0; //Otherwise pause.
stop--; //Countdown counting.
if(stop==0)
{ cflag=1; //Time is up.
zflag=0;
stop=y;
}
}
if(close!= 99)//The system time is 99, 99 is displayed, and the system has been working..
{ if(++c_count==60) //Count 60 for one minute, that is, one hour later.
{ c_count=0;
close--; / /Do a one-hour countdown.
if(close==0) //When the time is up, the system is powered off.
CLED=0; //Low level is active.
}
}
}
disnner();//Separate. Send display/
}
/* *********************************************
Function name: T1 interrupt service Function
description: Used to adjust time flashing.
***************************************** *****/
void timer1(void)interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
if(++count_T1==6)//Flash period 30MS
{
count_T1=0;
fliflag=~fliflag; //Switch
if(fliflag==0) //The flag is valid.
{
if(sum==1)cflag=1;//Select status flashing.
if(sum==2)cflag=2;
if(sum==3)cflag=3;
disnner(); //Flashing.
dis[ 0]=10; //Put off the extinguisher.
dis[1]=10;
}
else //Otherwise, display normally.
{
RLED=1;YLED=1;BLED=1;
dis[0]=time/10;
dis [1]=time%10;
}
}
}
/************************************** *******
Function name: Key scan function
Function description: Adjust time
************************************ ****************/
void scanner(void)
{ if(K1==0) //It is 0, indicating that a key has been pressed.
{
delay5ms(100);//Delay 500MS .
if(K1==0) //Still pressed. Just exited.
{
while(K1==0)display();//Waiting for release.
delay5ms(2); //Eliminate jitter.
cflag=1; // Exit display state 1.
count_T0=0;
TR0=1; //Start T0
TR1=0; //Off flash
sum=0; //Return.
x=start; //Temporary storage.
y=stop; //Temporarily Save.
}
else
{ //Otherwise, a shift key is pressed.
TR0=0; //Time movement stops.
TR1=1; //Turn on flashing.
sum++; //Shift.
if(sum==4)
sum =1;
}
}
if(K2==0)
{
delay5ms(2);
if(K2==0)
{
while(K2==0)display();
delay5ms(2);
if(sum) //There is a shift bit
{ if(sum==1)
{
start++;
if(start==61)
start=99;
if(start==100)
start=30;
}
if(sum==2)
{
stop++;
if(stop== 61)
stop=5;
}
if(sum==3)
{
close++;
if(close==9)
close=99;
if(close==100)
close=1;
}
}
else //No shift.
{
cflag++ ; //Then display status shifting.
if(cflag==4)
cflag=1;
}
}
}
if(K3==0)
{
delay5ms(2);
if(K3==0)
{
while(K3== 0)display();
delay5ms(2);
if(sum==1)
{ start--;
if(start==29)
start=99;
if(start==98)
start=60;
}
if(sum= =2)
{ stop--;
if(stop==4)
stop=60;
}
if(sum==3)
{ close--;
if(close==0)
close=99;
if(close==98)
close=8;
}
}
}
}
/******************************************
Function name: Main Function
description:
********************************************** /
main()
{
init();
while(1)
{
display();//Display
scanner(); //Detect button..
}
}
- Sample and hold amplifier AD9101 interface circuit
- Digital signal isolation interface circuit
- Interface circuit between MMA1220D and microcontroller
- How to use ESP8266 to make a mini fully functional clock
- How to make a smart mirror using Raspberry Pi
- How to make a super solar tracker using ESP8266
- p4 478 chip pin distribution diagram
- a watchdog circuit
- Circuit diagram: AT88RF
- usb to 232 circuit
- Analysis of internal reset circuit diagram of microcontroller
- Design of infrared communication circuit based on single chip microcomputer
- Two types of negative voltage generation circuit diagrams of single-chip microcomputer
- SPI interface and microcontroller interface principle circuit diagram
- Special ultrasonic collision avoidance warning design for reversing
- Minimum system interface circuit based on AT89C52 microcontroller
- Rice cooker dual timer controller circuit
- Multi-channel DA and microcontroller optical and electrical interface circuit
- Interface circuit between ICL7109 and microcontroller
- Timing controller circuit