Initialization procedure:
Assign values to TMOD to determine how T0 and T1 work.
Calculate the initial value and write it into TH0, TL0 or TH1, TL1.
In interrupt mode, assign values to EA and enable timer interrupt.
Set TR0 or TR1 to start the timer/counter timing or counting.
//Function realization: Digital tube increases by one per second;
#include #define uchar unsigned char #define uint unsigned int unsigned char code smg_du[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00}; void main() { TMOD=0x01; //Set timer 0 to working mode 1 TH0=(65536-50000)/256; //Set the initial value once every 50ms TL0=(65536-50000)%256; EA=1; //Turn on the general interrupt switch ET0=1; //Enable timer interrupt TR0=1; //Start the timer while(1) { if(kk==20) // 20 times is 1 second { k=0; P1=smg_du[num]; num++; if(num==10) //Prevent array overflow num=0; } } } void timer0 () interrupt 1 { TH0=(65536-50000)/256; //Set the initial value TL0=(65536-50000)%256; k++; }
Previous article:"Beginner's C51 Self-study Notes" - Four working modes of timer (Part 2)
Next article:"Beginner's C51 Self-study Notes" Serial Port
Recommended ReadingLatest update time:2024-11-24 20:36
- Popular Resources
- Popular amplifiers
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- 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)
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- CATL releases October battle report
- Battery industry in October 2024: growth momentum remains unabated!
- Mercedes-Benz will launch the eCitaro equipped with NMC4 batteries to provide high energy density and long life
- Many companies have announced progress on solid-state batteries. When will solid-state batteries go into mass production?
- Xsens Sirius Series Inertial Sensors Enable 3D Inertial Navigation in Harsh Environments
- Infineon's Automotive Landscape: From Hardware to Systems
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- Four default configurations for static protocol stack projects
- Share the SINA31S bought by Xinbi
- Registration for the 2020 STM32 National Tour Seminar is now open, and surprise gifts are waiting for you!
- The oscillation frequency of the two quartz crystal oscillator circuits is not the frequency of the crystal. Why?
- Keysight Technologies recently collaborated with Nanyang Technological University, Singapore, to develop hybrid vehicle networking communication technology, and the forecast is promising.
- Principle Analysis of Temperature Acquisition System Designed by Temperature Sensor MAX6613
- Mingdeyang FPGA Series Course Phase 1 Chapter 3 VERILOG (1)
- iTOP-iMX6ULL development board-Using UVC camera under Qt5
- How to achieve high-performance mobile phone design? The mobile phone college evaluation seminar will reveal the answer for you!
- Has anyone used the 28035 chip to do LIN communication?