// |-| |-| |-|
// | | | | | |
// __| |________| |_______|_|_____------>PWM1
//
// |----| |----| |----|
// | | | | | |
// __| |_____| |____| |_------>PWM2
//This experiment uses the CCP module function of the PIC microcontroller to generate PWM function. The period of PWM is:
//(PR2+1)*4TOSC*(TMR2 pre-division value)
//Understand the function of the CCP1CON register of the CCP module,
//Understand the relationship between TMR2 and the CCP module,
//Master the initialization and setting of the relevant registers of the CCP module
//Software platform: XC8 programmer and MPLAB X IDE integrated development environment
//Author: Sun An-qing
//The PWM signal generated by the CCP1 module is output from the RC2 pin,
//At the same time, the PWM signal generated by the CCP2 module is output from the RC1 pin. Both can be
observed with an oscilloscope //The PWM waveform.
Modified by: Leo
Date: 20101223
The display effect makes the LED light display effect go from bright to dark, then back to bright, then back to dark.
#include
void delay1ms(uint DelayTime)
{
uint temp;
for(;DelayTime>0;DelayTime--)
{
for(temp=0;temp<270;temp++)
{;}
}
}
void main(void)
{
//***********************************************************
CCP1M3=1;//Enable CPP1 Work as PWM mode
CCP1M2=1;
CCP1M1=1;
CCP1M0=1;
TRISC2=0;//Enable RC2 work as output
CCPR1L=0x10;//PWM脉宽值,改变PWM的脉宽,只需改变CCPR1L中的值
CCP1X=0;//以及CCP1CON中的CCP1X和CCP1Y这两个位的值
CCP1Y=0;
//***********************************************************
CCP2M3=1;//Enable CPP2 Work as PWM mode
CCP2M2=1;
CCP2M1=1;
CCP2M0=1;
TRISC1=0;//Enable RC1 work as output
CCPR2L=0x20;//PWM脉宽值,改变PWM的脉宽,只需改变CCPR2L中的值
CCP2X=0;//以及CCP2CON中的CCP2X和CCP2Y这两个位的值
CCP2Y=0;
//***********************************************************
TOUTPS3=0;//Enable TMR2--->1:1
TOUTPS2=0;
TOUTPS1=0;
TOUTPS0=0;
T2CKPS1=1;//Enable TMR2--->1:16
T2CKPS0=1;
TMR2ON=1;//Enable TMR2 Working
TMR2=0;
while(1)
{
for(;num <= 1023; num++)
{
PR2=num;//PWM周期,改变PWM的周期,只需改变PR2中的值即可
delay1ms(10);
}
}
}
Previous article:PIC Read-Modify-Write Operations
Next article:PIC16F877A CCP Usage
- 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?
- 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
- Another technical solution for power-type plug-in hybrid: A brief discussion on Volvo T8 plug-in hybrid technology
- 【IoT Graduation Project】Raspberry Pi Development Board + Gizwits IoT + Monitoring Robot
- TI has new products: ISO224 isolation amplifier and ISO1042 CAN transceiver.
- [Repost] Learn these eight circuit design skills and your professional quality will be greatly improved
- [STM32WB55 Review] +ST's Attack
- In the TTL inverter circuit, there is no power supply on the collector of VT4. How does VT4 saturate?
- GD32F350 development board adds PWM dimming
- MSP430 ADC conversion + mean filter
- World Cup tickets use RFID technology
- EEWORLD University ---- Linux Kernel Design
- TI eSMO library Fsmopos and Gsmopos parameter analysis