This is a complete code of the eye-activating instrument made with 51 series single-chip microcomputer. Friends who need it can take a look. The code has been tested successfully.
/*
Project name: Single-chip eye-activating instrument
Related knowledge points: single-chip microcomputer drives heating devices, digital tube display, key operation, etc.
Program development: http://www.51hei.com single-chip microcomputer tutorial website.
*/
#include
#define uint unsigned int
#define uchar unsigned char
#define duan P0 // Define the segment display of P1 port as duan label
#define keyio P3 // Set P3 port as the port for key detection
uchar time,guannum,guantime1,guantime2; //time is the value in minutes, light displays the time value
uint b; //50MS is 1 time, so 1 minute is 1200 times
bit xsd,onandoff; //decimal point flashing bit variable, switch variable flag bit
sbit xuanled=P2^3;
sbit guanled=P2^5;
sbit rfled=P2^7;//Three indicator light position control
sbit xsdbit=P0^6;//Decimal point actual hardware output pin definition
sbit gewela=P2^0;//Ones digit digital tube position control
sbit shiwela=P2^1;//Tens digit digital tube lock position control
sbit guanout=P1^0;//Spectrum output
sbit rfout=P1^1; //RF heating head output drive
sbit xuanout=P1^2; //Gyromagnetic output
sbit fmqout=P1^3;
uchar code tab[]={0x48,0xee,0x54,0x64,0xe2,0x61,0x41,0xec,0x40,0x60,0xf7};//Digital tube segment display code 0~9, to be written
void chushi(void); //Initialize when entering the main function
void key(void); //Key detection
void display(uchar time);//Digital tube display processing program
void chushi1(void); //Perform large loop function initialization processing
void delay(uchar num)//delay module program
{
uchar c,d;
for(c=num;c>0;c--)
for(d=40;d>0;d--);
}
void main() //Main function program body
{
uchar a;
chushi();
while(1)
{
chushi1();
key(); //Key detectionif
(keyio!=0xff)
fmqout=0;
else fmqout=1;
if(onandoff!=0)
{
for(a=100;a>0;a--)
{
duan=tab[10]; //Open segment display, display the middle segment
gewela=0;
shiwela=0;
delay(10);
gewela=1;
shiwela=1;
}
while(onandoff!=0)
{
display(time);
key();
if(time==0&&b>=1000)
fmqout=xsd;
else if(keyio==0xff)
fmqout=1;
else fmqout=0;
}
for(a=200;a>0;a--)
display(time);
}
}
}
void time0() interrupt 1
{
TH0=0x3c;
TL0=0xb0;
b++;
if(b==1200)
{
b=0;
if(time!=0)
time--;
else onandoff=0; //set zero flag
}
if(b%10==0)
xsd=~xsd; //The decimal point variable changes in a cycle of 1S
if(guannum==2||guannum==3)
{
guantime2--;
if(guantime2==0)
{
guantime2=guantime1;
guanout=~guanout;
}
}
}[page]
void chushi(void) //Initialize directly when entering the main MAIN function body
{
TMOD=0x01; //Timer timing mode
TH0=0x3c;
TL0=0xb0;
ET0=1;
EA=1;
TR0=1;
xuanled=1;
guanled=1;
rfled=1;
}
void chushi1(void) //Initialization of the large loop
{
time=30; //The initial time value is 30 minutes when the machine is turned on
guanout=0; //Spectrum output is low level
rfout=0; //RF heating head output drive is low level
xuanout=0; //Gyromagnetic output low level
guannum=0; //When in standby mode, the spectrum is in 0 state
xuanled=1;
guanled=1;
rfled=1;
duan=tab[10]; //Open segment display, display the middle segment
gewela=0;
shiwela=0;
delay(2);
gewela=1;
shiwela=1;
}
void key(void) //Key detection module
{
uchar a,num1;
keyio=0xff;
if(keyio!=0xff)
{
fmqout=0;
if(onandoff!=0)
{
for(a=100;a>0;a--)
display(time);
}
else
{ for(a=20;a>0;a--)
{
duan=tab[10]; //Open segment display, display the middle segment
gewela=0;
shiwela=0;
delay(2);
gewela=1;
shiwela=1;
}
}
if(keyio!=0xff)
{
num1=keyio;
switch(num1)
{
case 0xfe: onandoff=~onandoff; //Switch on and off
break;
case 0xfd: b=0;
if((onandoff!=0)&&(time!=99)) //time plus
time++;
break;
case 0xfb: b=0;
if((onandoff!=0)&&(time!=0)) //time minus
time--;
break;
case 0xf7: if(onandoff!=0)
{
xuanout=~xuanout; //rotation variable changeif
(xuanout!=0)
xuanled=0;
else xuanled=1;
}
break;
case 0xef: if(onandoff!=0) //spectral output variable changes
{
guannum++;
if(guannum==4)
guannum=0;
if(guannum!=0)
guanled=0;
else guanled=1;
if(guannum==1)
guanout=1;
else if(guannum==2)
guantime1=guantime2=15;
else if(guannum==3)
guantime1 =guantime2=8;
else guanout=0;
}
break;
case 0xdf: if(onandoff!=0) //RF heating variable changes
{
rfout=~rfout;
if(rfout!=0)
rfled=0;
else rfled=1;
}
break;
default:break;
}
}
}
}
void display(uchar min) //digital tube display module
{
uchar ge,shi;
shi=min/10;
ge=min%10;
duan=tab[shi];
shiwela=0;
delay(5);
shiwela=1;
duan=tab[ge];
xsdbit=xsd;
gewela=0;
delay(5);
gewela=1;
}
Previous article:Single chip microcomputer controls thyristor dimming without lightning circuit + program
Next article:About the PxM0 and PxM1 settings of the STC12C5410AD microcontroller
Recommended ReadingLatest update time:2024-11-16 14:51
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
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
- Solving High-Voltage Current Sensing Design Challenges in HEV/EV
- Car Charger IC
- Several points to note when using SIMD to process multiple data in parallel
- The resistance of the transistor
- This week's highlights
- Recommend a network disk that supports automatic synchronization - TeraCLOUD, supports WebDav
- Digital Temperature Servo Control System Based on Microcontroller
- About the power supply problem of LED constant current chip
- LIN communication, no response error, please help
- Very useful, a summary of RF dry goods (worth collecting)