1. Experimental topic:
Assume that the clock of the microcontroller is 12MHz. Please use timer T2 to program the P4.6 pin to output a rectangular wave with a period of 3s. The duty cycle coefficient is required to be 1:3. Observe the changes of LED10. (In one cycle, the time occupied by the high level is called duty cycle.)
2.KEIL code
#include sbit LED=P1^6; void main() { TMOD &=0X0F; TMOD |= 0x01; //Select the working mode 1 of timer T0 TH0 = (65536 - 50000)/256; //initial value of the upper four bits TL0 = (65536 - 50000)%256; //The initial value of the lower four bits overflows every 50ms EA = 1; // Enable general interrupt ET0 = 1; TR0 = 1; //Start the timer P1=0xff; while(1); } void Time0(void) interrupt 1 //Timer interrupt { static unsigned int i = 0; TH0 = (65536-50000)/256; TL0 = (65536-50000)%256; //The overflow period is set to 50ms i++; if(i==20) // overflow 20 times per second { LED=0; //1 second time is up, the level becomes low } if(i==60) { LED=1; //3 seconds have passed, the level becomes high i=0; //Count clear } }
Previous article:Realization of stepless dimming system based on AT89C51 single chip microcomputer
Next article:51 single chip microcomputer experiment - output square wave with a period of 200ms
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
- Single board design related
- From terminals to architecture, TE Connectivity (TE) helps you connect to the 5G high-speed future. Watch the video and answer questions to win gifts!
- [Project source code] Fixing NIOS II software error and solution when using Winbond's SPI FLASH as EPCS
- 03. Anlu SparkRoad domestic FPGA evaluation [Learning] Push switch control LED
- Power supply obstacles + power supply stability
- ST's latest evaluation activity! Get the first-hand experience of the NUCLEO_G431RB development board here
- Some points to note when designing CC2530 2.4G ZigBee low power PCB
- 1500-5 common Chinese characters strokes and pronunciation
- Isn't it great to use LT's 3090 as a constant current source? Let's discuss how to set the current.
- About the development process of the transmission control unit TCU