Turn Microchip PIC16F6128 PWM On-Off Using PORT Register

Example code:


main
; remaining code goes here
	banksel TRISB ; goto bank 1
	bsf TRISB, 3
	call delay_500ms
	bcf TRISB, 3
	call delay_500ms
	goto	main 

For how to calculate frequency and duty cycle for PIC PWM
see Working with Pulse-Width Modulation and the PIC Microcontroller

Instead of writing 0 value to PWM counters to turn off the output we simply change the IO pin RB3 to input with TRISB bit RB3 in bank 1.

Download the ASM code 16F628A_PWM.asm.

Pin out PIC16F628A


Related Videos, Links