Code for Interfacing PWM module in PIC 16F87X

Microcontroller Topics
Post Reply
User avatar
Magneto
Major
Major
Posts: 430
Joined: Wed Jul 15, 2009 1:52 pm
Location: London

Code for Interfacing PWM module in PIC 16F87X

Post by Magneto » Sat Oct 24, 2009 9:34 am

delay.h
(4.8 KiB) Downloaded 422 times
delay.c
(997 Bytes) Downloaded 433 times
always.h
(6.24 KiB) Downloaded 431 times
pwm.h
(45 Bytes) Downloaded 530 times

Code: Select all

#include <pic.h> 
#include "pwm.h"
#include "delay.h"


/*
	Initializing the PWM unit
*/
void InitPWM()
{
	TMR2 = 0;		// reset Timer2 
	
	PR2 = 255;		// 4 MHz oscillator and  PWM period
	
	CCPR1L = 50;	// set PWM duty cycle
	CCP1X = 0;		// 
	CCP1Y = 0;		//

	CCP1M3 = 1;		// set CCP1 mode to PWM
	CCP1M2 = 1;
	
	TRISC2 = 0;		// set RC2 as an output
	
	T2CKPS1 = 0;	// set Timer2 prescaler to 16
	T2CKPS0 = 0;
	TMR2ON = 1;		// start Timer2
}
Post Reply

Return to “Microcontrollers”