/*
Note: This program mainly shows how to use the timer to count, and reflects the modular sub-functions. It is a relatively simple program
*/
#include
#define uchar unsigned char //macro definition
#define uint unsigned int
uchar count; //define global variables
void display_led() //led display sub-function
{
if(count==20) //changes every 1S (crystal oscillator: 12MHZ)
{
count=0; //count cleared for next count
P2=~P2; //P2 value inverted
P2=P2<<1; //P2 value shifted left
P2=~P2;
if(P2==0xff) //if the last LED is on,
P2=0xfe; //then the first LED is on
}
}
void init() //initialization sub-function
{
EA=1; //turn on total interrupt
ET0=1; //turn on timer interrupt
TR0=1; //start timer
TMOD=0x01; //T0 working mode 1, 16-bit counting
TH0=(65536-50000)/256; //Set the initial value of the timer
TL0=(65536-50000)%256;
P2=0xfe; //Assign initial value to P2 port
while(1)
{
display_led(); //Call LED display sub-function
}
}
void main() //Main function
{
init(); //Call initialization sub-function
}
void delay() interrupt 1 //Timed interrupt sub-function
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++; //Count variable plus 1
}
Previous article:Interrupt method keyboard scanning c program
Next article:Simple 4*4 matrix keyboard scanning program
Recommended ReadingLatest update time:2024-11-16 14:53
- 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
- GD32E231 DIY Competition (9)——"Home Intelligent Monitoring" Project Summary
- About G2553 with 20 pins cannot be programmed
- PT6312 driver Samsung segment screen hardware design driver source code
- Why does the STM series MCU use SMD T card instead of traditional T card?
- The problem that the main function cannot be run after downloading the program with IAR compiler
- Added multiple ST sensor drivers in MakeCode
- Selection of power device heat sink
- LabView Note 4: Temperature Monitoring System Based on LabView Password Login
- The command configurations in the manual are all expressed in hexadecimal. How should they be used in the code?
- Gizwits Timer Switch