PIC16F628A  connected to 8 LEDs.

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


Loading


Pin connections PIC 16F628.

 


donate