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
}[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
}
/****************************************************
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..
}
}
Previous article:How to embed assembly directly in KEIL C51
Next article:MCS-51 single chip microcomputer timing system
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [Mill MYB-YT507 development board trial experience] Python displays memory and CPU real-time status 1
- How do RF circuits and digital circuits coexist harmoniously?
- Xiangshan high-performance RISC-V processor
- Issues with converting remaining TI points into chip points
- Development process of eCAN in DSP28335
- Sugar gliders Part ⑩ Sugar glider health monitoring system based on RSL10 - host computer design
- Can someone help me figure out whether this active filter is a voltage-controlled power supply type or a multiple feedback type?
- 【BearPi-HM Nano】NFC test
- Frost has fallen~
- Summary by an expert: Answers to 23 classic questions in power supply development!