//Original work of 51hei MCU Network, all rights reserved.
#include "reg_c51.h"
#define reload_value 0x06 //The count value is 250, if the clock frequency is 12MHz, it is equivalent to 250μs
unsigned char hex[16]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,
0x88,0x83,0xC6,0xA1,0x86,0x8E}; //Hexadecimal decoding table of digital tube
unsigned char n,nn; //Define the interrupt count variable
void main(void) //Main function
{
TMOD &= 0xF0; //Timer/Counter 0 works in mode 2, 8-bit reload mode
TMOD |= 0x0A; //GATE0=1; C/T0#=0; M1=1; M0=0;
TL0 = reload_value; //Set initial value
TH0 = reload_value; //Set initial value
ET0=1; //Enable timer/counter 0 interrupt
EA=1; //Enable total interrupt
TR0=1; //Start timer/counter 0
while(1) //Infinite loop
{
P1=hex[n/10]; //Display the high bit of interrupt count variable n
P0=hex[n%10]; //Display the low bit of interrupt count variable n
}}
void it_timer0(void) interrupt 1 //Timer/counter 0 interrupt function
{
nn=nn++; //Add 1 to nn for each interrupt, and 250μs interval between each interrupt
if (nn==40) //nn=40, which means 40 interrupts, equivalent to 40*250μs =10ms
{
nn=0;
n++; //Add 1 to n every 10ms
if(n==100) //n=100, which is equivalent to 10ms*100=1s
{n=0;
P2_0 = ~P2_0; //Every 1s, invert the level of the P2_0 pin to make the connected LED light flash
}}}
Previous article:Use Timer 0 to generate multiple time intervals
Next article:51 MCU timer/counter works in mode 1
Recommended ReadingLatest update time:2024-11-16 14:26
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Fundamentals and Applications of Single Chip Microcomputers (Edited by Zhang Liguang and Chen Zhongxiao)
- Single chip microcomputer control technology (Li Shuping, Wang Yan, Zhu Yu, Zhang Xiaoyun)
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
- Sub-library: Summary of official Chinese technical documents on temperature and humidity sensors
- Rainbow Arch designed with Circuit Playground Express
- An interview with Roger Hall, General Manager of Qorvo High Performance Solutions Division, to help you learn more about 5G
- 【ST NUCLEO-H743ZI Review】——by bigbat
- How long have you not spent the Lantern Festival at home?
- Protection processing circuit in IoT system and equivalent circuit of HF RFID reader
- EVAL-M3-TS6-665PN development board circuit structure and features
- 51 MCU falling edge trigger
- TI C6748 chip PRU part assembly software package sprc940.zip
- The new issue of "Analog Dialogue" is online, free download!