Simple timing controller for electric fan based on single chip microcomputer

Publisher:神光骑士Latest update time:2015-02-02 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The mechanical timer of my bedside fan broke, so I designed one using a 51 single-chip microcomputer. The program has passed the preliminary debugging on the experimental board, and I can make the board after waiting for the components to arrive. It's just a bit of a waste of the microcontroller's resources.

 

1. Design ideas:

Start to power the MCU by manual key. Until the power indicator LED4 lights up, the MCU is running, and relay 2 works to power the MCU. By setting the working time of relay 2 by key, the system can be automatically powered off. By setting the working time of relay 1, the fan can be turned intermittently to achieve energy saving.

1. Display part: By pressing the button, the fan rotation time, pause time, and system shutdown remaining time are switched. The digital display is two digits, which are "minutes" running time, and the system shutdown remaining time is "hours" running time. The LED is red, yellow, and blue, respectively lighting up the corresponding fan rotation, pause, and system shutdown remaining time status.

2. Button part:

lK1 is the time adjustment shift key. Press this key, the digital number flashes, and the corresponding light flashes at the same time. Switch between the fan rotation time, pause time, and system

lK2 is the plus one and status switching display key. When K1 is pressed, the time is plus 1. Otherwise, the display is switched between the fan running time, pause time, and system.

lK3 is a subtraction key and a standby key. When K1 is pressed, the time is increased by 1, otherwise it is invalid.

3. Relay part:

l Relay 1 controls the power line of the fan to realize the rotation and temporary of the fan.

l Relay 2 controls the power supply of the MCU system to achieve timed shutdown of the system.

 

2. Schematic diagram

 


3. Program List

/************************************************
System name: Simple electric fan timing controller
Creator: w418781840Date: 2008.7.6System
function:
**************************************************/
/*************************************************
Function name: Declaration area
Function description:
**********************************************/
#include
#defineucharunsignedchar
#defineuintunsignedint
#defineSEGP0//Digital tube segment selection.
#defineDIGP2//Digital tube position selection
uchardis[2]; //Digital drive group
ucharcodeTAB[]={0xC0,0xF9,0xA4,0xB0,0x99,//0-4 common anode.
0x92,0x82,0xF8,0x80,0x90,0xff}; //5-9, extinguishing symbol
ucharstart,stop,close,sum,time; //Each local variable
ucharfliflag,cflag,zflag,x,y; //Each flag bit
uintcount_T0,count_T1,c_count; //Counting variable
sbitK1=P3^7; //Function shift key
sbitK2=P3^2; //Add one key and switch shift key.
sbitK3=P3^3; //Subtract one.
sbitRLED=P2^2; //Red light, indicating the fan rotation status.
sbitYLED=P2^3;//yellow light, indicating fan pause status
sbitBLED=P2^4;//blue light, indicating system status
sbitCLED=P2^6;//fan control bit
sbitZLED=P2^7;//system work control bit
/************************************************
Function name: Delay 1MS function
Function description: display call.
**********************************************/
voiddelay1ms(ucharx)
{
uchari,j;
for(i=0;i for(j=0;j<120;j++);
}[page]

/************************************************
Function name: display function
Function description: display two digits when divided.
**************************************************/
voiddisplay(void)
{
uchari,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
Function description: key debounce call.
**********************************************/
voiddelay5ms(ucharx)
{
ucharj;
for(j=0;j display();
}

/****************************************************
Function name: Initialization function
Function description: Initialize all variables.
**********************************************/
voidinit()
{fliflag=0;//Flashing flag.
cflag=1;//Fan status flag.
zflag=0;//Rotation flag.
x=30;//Temporary storage
y=10;//Temporary storage
CLED=1;//System operation.
sum=0;//Shift
start=30;//Fan rotation time
stop=10;//Pause time.
close=5;//System shutdown remaining 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: separate and display the tens and ones digits
**********************************************/
voiddisnner(void)
{if(cflag==1)//1
{RLED=0;YLED=1;BLED=1;//Red light flashes.
time=start;//Display 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: Generate 1 minute.
**********************************************/
voidtimer0(void)interrupt1
{TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if(++count_T0==1200)//One minute.
{count_T0=0;
if(zflag==0)//is 0
{ZLED=1;//Then rotate.
if(start!=99)//The rotation time is 99, display 99, do not switch the flag. Keep rotating.
{
start--;//No, countdown.
if(start==0)
{zflag=1;//Countdown time is up. Switch the flag.
cflag=2;
start=x;//Reassign
}
}
}
else
{ZLED=0;//Otherwise pause.
stop--;//Countdown.
if(stop==0)
{cflag=1;//Time is up.
zflag=0;
stop=y;
}
}
if(close!=99)//System time is 99, display 99, system keeps working..
{if(++c_count==60)//Count 60 for one minute, that is, one hour later.
{c_count=0;
close--;//Count down for one hour.
if(close==0)//Time is up, system power off.
CLED=0;//Low level is valid.
}
}
}
disnner();//Separate. Send to display/
}
/*************************************************
Function name: T1 interrupt service function
Function description: Used to adjust the time flashing.
**********************************************/
voidtimer1(void)interrupt3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
if(++count_T1==6)//Flashing period 30MS
{
count_T1=0;
fliflag=~fliflag;//Switch
if(fliflag==0)//Flag is valid.
{
if(sum==1)cflag=1;//Select the flashing state.
if(sum==2)cflag=2;
if(sum==3)cflag=3;
disnner();//Flashing.
dis[0]=10;//Put the extinguishing symbol.
dis[1]=10;
}
else//Otherwise, normal display.
{
RLED=1;YLED=1;BLED=1;
dis[0]=time/10;
dis[1]=time%10;
}
}
}
/*********************************************
Function name: key scanning function
Function description: adjust time
**********************************************/
voidscanner(void)
{if(K1==0)//is 0, indicating that a key is pressed.
{
delay5ms(100);//Delay 500MS.
if(K1==0)//still pressed. Just exited.
{
while(K1==0)display();//wait for release.
delay5ms(2);//debounce.
cflag=1;//exit display state 1.
count_T0=0;
TR0=1;//start T0
TR1=0;//turn off flash
sum=0;//return.
x=start;//temporary storage.
y=stop;//temporary storage.
}
else
{//otherwise, a shift key is pressed.
TR0=0;//time movement stops.
TR1=1;//turn on flash.
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 shift
{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 shift the display status.
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
Function description:
**********************************************/
main()
{
init();
while(1)
{
display();//display
scanner();//detect key presses..
}
}

Reference address:Simple timing controller for electric fan based on single chip microcomputer

Previous article:How to embed assembly directly in KEIL C51
Next article:MCS-51 single chip microcomputer timing system

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号