
PIC16F628 Pulse Width Modulation Controls Brightness of LED
by Lewis Loflin
Code example main loop:
main ; first loop increases brightness of LEDs clrf val ; val = 0 gg call delay_100ms movf val, w movwf CCPR1L ; output val to pwm RB3 movlw d'10' addwf val, F ; add 10 to val btfss STATUS, C ; check for carry goto gg ; no carry loop again ; decreases brightness of LEDs movlw 0xFF movwf val hh call delay_100ms movfw val movwf CCPR1L ; save val to register movlw d'10' subwf val, F ; subtract 10 from val save in val btfsc STATUS, C ; check for less than 0 goto hh ; no loop again clrf CCPR1L goto main
For how to calculate frequency and duty cycle for PIC PWM
see Working with Pulse-Width Modulation and the PIC Microcontroller
Download ASM code pwmdemo1.asm
See How I got into Electronics
- You Tube Videos for this Series
- Home Built PIC Development Board
- PIC16F628 PIC Using Rotary Encoder to Operate Stepper Motor
- Using a Serial ADC with PIC16F628
- Calculating Pulse-Width Modulation with a PIC
- PIC16F84A-628A Hardware Time Delays
- PIC16F84A-628A Timer Interrupt Delays
- PIC16F84A-628A Pullups and Interrupts
- PIC16F84A-628A Hardware Interrupts Tutorial
- Projects using PIC16F628:
- Home Built PIC16F628 Prototyping Board
- Exploring the Microchip PIC in Assembly
- Using a Microchip PIC with TLC548 Serial ADC
- Controlling PIC Pulse Width Modulation with a Serial ADC
- Using TMR0 on a PIC with Interrupts
- External Clock Crystal with PIC16F628 TMR1 Generates Interrupt
- PIC Using Rotary Encoder to Operate Stepper Motor
- PIC16F628 Pulse Width Modulation Controls Brightness of LED
- Another way to Turn On-Off PWM in a PIC
- TLC548 Serial ADC Spec. Sheet
- Programming PIC16F84A-PIC16F628A Interrupts by Example
- PIC16F84A-PIC16F628A Pull Up Resistors with Interrupts
- Programming PIC16F84A-PIC16f628a Timers by Example
- Programming PIC16F84A-PIC16F628A TMR0 Interrupts
- Programming PIC16F84A Software Delay Routines by Example
Web site Copyright Lewis Loflin, All rights reserved.
If using this material on another site, please provide a link back to my site.