Preface
This blog post is based on STC89C52RC and keil5 C51 development;
If there is anything I haven't done, please give me some advice;
Things you need
This is done using Timer 0 (and Timer 1 as well).
Use P1.0~P1.3 to complete 4-way PWM output (different duty cycles);
code show as below:
#include #define ENABLE 1 #define DISENABLE 0 typedef unsigned int uint16; typedef unsigned char uchar8; sbit P1_0 = P1^0; sbit P1_1 = P1^1; sbit P1_2 = P1^2; sbit P1_3 = P1^3; /* Duty cycle time calculation: Duty Cycle = High_Level_Time_P1_x/Cycle; */ uchar8 Cycle = 10; //Set PWM cycle: 10*timer overflow cycle (100us) = 1000us; uchar8 High_Level_Time_P1_0 = 0; //The four global variables here control the high level time in each cycle; uchar8 High_Level_Time_P1_1 = 0; uchar8 High_Level_Time_P1_2 = 0; uchar8 High_Level_Time_P1_3 = 0; 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: 9C (decimal 156, that is, the overflow period of the timer is 100us); 3. Timer 0 is set to 8-bit auto-reload mode; */ void Time0_Init(void) { TMOD = 0x02; TH0 = 0x9C; TL0 = 0x9C; TR0 = ENABLE; ET0 = ENABLE; EA = ENABLE; } void Timer0_IT() interrupt 1 { static uchar8 count_P1_0,count_P1_1, count_P1_2,count_P1_3; if(count_P1_0==High_Level_Time_P1_0) { P1_0 = 0; } count_P1_0++; if(count_P1_0==Cycle) { P1_0= 1; count_P1_0 = 0; } if(count_P1_1==High_Level_Time_P1_1) { P1_1 = 1; } count_P1_1++; if(count_P1_1==Cycle) { P1_1= 0; count_P1_1 = 1; } if(count_P1_2==High_Level_Time_P1_2) { count_P1_2=0; } count_P1_2++; if(count_P1_2==Cycle) { P1_2 = 0; count_P1_2=1; } if(count_P1_3==High_Level_Time_P1_3) { count_P1_3 = 0; } count_P1_3++; if(count_P1_3==Cycle) { P1_3 = 1; count_P1_3= 1; } }
Previous article:Notes on assembly operators based on the MCS-51 kernel
Next article:Teach you to learn 51 single chip microcomputer step by step: light up your LED
- Popular Resources
- Popular amplifiers
- 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?
- 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
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- CC2538EM Reference Design CC2538EM-RD
- Source Insight Open Issues
- Why do many domestic chip information require signing an NDA before obtaining it?
- STM Arduion cannot download firmware?
- MSP430F5438A serial port
- Airlabi supports 2018 STM32 seminar
- Signal Processing of Linear Frequency Modulated Stepped Synthetic Aperture Radar System
- Common causes of RF interference
- AC-DC adapter reference design with TI's latest UCC28780 chip and Type-C interface
- An article explains the function and principle of Via hole