//Crystal oscillator 11.0592
//The light changes gradually from bright to dark under the control of the single-chip microcomputer, and it feels like breathing.
//This example uses a digital tube and an LED light on the 51hei-5 development board to achieve a breathing effect.
//File download: http://www.51hei.com/f/fxd.rar
#include
#define uint unsigned int
#define uchar unsigned char
sbit D1=P0^7;
uchar sr;
uchar jf;
uchar code table[]={
0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,
19,20,21 ,22,23,24,25,26,27,
28,29,30,31,32,33,34,35,36,
37,38,39,40,41,42,43,44,45,
46 ,47,48,49};
void light(uchar num);
void delay(uint z);
void main()
{
//Set the counter
//Select counting mode 1
TMOD = 0x11;
//Write the initial value to the counter
TH0 = 0;
TL0 = 0;
////////////////////
//Operate the microcontroller
//Turn on CPU interrupt
EA = 1;
/////////////////////
//Turn on timer T0 bit interrupt
ET0 = 1;
//Turn on counter
TR0 = 1;
//Operate diode
P1=0;
while(1)
{
if(sr<50)
light(sr);
else sr=0;
}
}
//Subfunction
void light(uchar num)
{
uchar tme;
D1 = 0;
tme = table[num];
delay(tme);
D1 = 1;
delay(49-tme);
}
//Interrupt function
void time () interrupt 1
{
//Increment the independent variable
if (jf<2)
{
jf++;
TH0 =0;
TL0 = 0;
}
if (jf==2)
{
//Write initial value
jf=0;
TH0 = 254;
TL0 = 254;
sr++;
}
}
void delay(uint z)
{
uint x,y;
for(x=10;x>0;x--)
for(y=z;y>0;y--);
}
Previous article:Dot matrix + music = happy birthday program based on 51 single chip microcomputer
Next article:Microcontroller self-study notes: Flowing light design program
- Popular Resources
- Popular amplifiers
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
- SparkRoad FPGA development board drives LVDS display
- [2022 Digi-Key Innovation Design Competition] - Introduction to the functions of the STM32F750N8H6 development board
- [NUCLEO-L452RE Review] + Example of sending the value received by the serial port to the message queue
- dds.pdf
- Switching Circuit Voltage Calculation
- Let your LED follow the MUSIC HIGH!
- 【Qinheng CH582】5 displays CPU temperature
- CC1310 Two-wire Serial Bootloader Solution
- 70 Years of Sky Heavy Equipment
- What should the circuit output waveform look like?