/*
Note: This program mainly shows how to use the timer to count
. It is a relatively simple program that reflects modular sub-functions
*/
#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:An improved voltage regulating circuit controlled by STC12C2052AD single chip microcomputer
Next article:Simple program for timer counting LED display
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
- TI's active-clamp flyback controller is said to halve the size of power supplies
- EEWORLD University Hall----Power System Analysis (Tsinghua University)
- 【ufun learning】Analysis of the buzzing routine
- Design and simulation of LC balun
- Capacitive touch MSP430FR2676 MCU motherboard
- 【XMC4800 Relax EtherCAT Kit Review 2】-Building the environment and lighting up the LED
- Common problems in OLED development
- ECG monitor solution based on DSP system platform
- A novice asks about AD copper plating, thank you
- Compact W600 development board