Preface
This blog post is developed based on STC89C52RC and Keil5 C51 environment;
If there are any deficiencies, please give me more advice;
Things Needed
Timer 0;
Pin P1.0;
code show as below:
#include #define ENABLE 1 #define DISENABLE 0 typedef unsigned char uchar8; sbit P1_0 = P1^0; bit Flag = 0; /* Duty cycle time calculation: Duty cycle = high level time / (high level time + low level time); */ //High level time (initial value: 0x02EE, i.e. decimal 750) uchar8 Timer0_TH0_High_Level_Time = 0x02; //Timer 0 high eight-bit high level time; uchar8 Timer0_TL0_High_Level_Time = 0xEE; //Timer 0 low eight bits high level time; //Low level time (initial value: 0x00FA) uchar8 Timer0_TH0_Low_Level_Time = 0x00; //Timer 0 high eight bits low level time; uchar8 Timer0_TL0_Low_Level_Time = 0cFA; //Timer 0 low eight-bit low level time; void Time0_Init(void); void main() { Time0_Heat(); while(1); } /* Timer configuration: 1. Assume that the crystal frequency of the microcontroller is 12MHz; then the timer accumulation period is 1us; 2. The initial value of the timer is: high level overflow time 0x02EE, that is, decimal 750; low level overflow time 0x00FA, that is, decimal 250; 3. Timer 0 is set to 16-bit auto-reload mode; */ void Time0_Init(void) { TMOD = 0x01; TH0 = Timer0_TH0_High_Level_Time; //The initial value is set to high level; TL0 = Timer0_TL0_High_Level_Time; TR0 = ENABLE; ET0 = ENABLE; EA = ENABLE; Flag = 0; P1_0 = 1; } void Timer0_IT() interrupt 1 { if(Flag) { TH0 = Timer0_TH0_High_Level_Time; TL0 = Timer0_TL0_High_Level_Time; Flag = 0; P1_0 = 1; } else { TH0 = Timer0_TH0_Low_Level_Time; TL0 = Timer0_TL0_Low_Level_Time; Flag = 1; P1_0 = 0; } }
Previous article:Teach you to learn 51 single chip microcomputer step by step: C language basics and the realization of running lights
Next article:51 MCU timer realizes PWM wave
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- 6657Statically configure serial port general interrupt in sys/bios
- Understanding Nginx Architecture in One Article
- Highly recommended! ADI's latest Chinese information is here
- Urgently looking for expert advice AD15 can not open the PCB after cracking
- Difference between LPS22HH and LPS22HB
- How to collect multiple sensor signals through one RS485 interface of industrial computer?
- Altera SoC Architecture Excerpt - What is a SoC FPGA
- How to use common mode chokes in signal lines to eliminate common mode noise
- EEWORLD University ---- Python 3 video tutorial
- [Rivet RVB2601 Creative Application Development Competition] Participation Award Prizes