/******************************************************************* * FileName: David Fisher Exam 2 Problem 2.c * Processor: PIC18F4520 * Compiler: MPLAB C18 v.3.06 * * This program flashes PWM2 at 10 Hz using a 10% duty cycle * * * Creation and Revisions: * Author Date Comments * David Fisher ********************************************************************/ /** Header Files ***************************************************/ #include #include #include /** Configuration Bits *********************************************/ #pragma config OSC = INTIO67 #pragma config WDT = OFF #pragma config LVP = OFF #pragma config BOREN = OFF /** Define Constants Here ******************************************/ /** Local Function Prototypes **************************************/ /** Global Variables ***********************************************/ /******************************************************************* * Function: void main(void) ********************************************************************/ #pragma code void main (void) { OSCCONbits.IRCF2 = 0; // 31250 MHz OSCCONbits.IRCF1 = 0; OSCCONbits.IRCF0 = 0; OpenTimer2(TIMER_INT_OFF & T2_PS_1_4); //PWM period =[(period ) + 1] x 4 x TOSC x TMR2 prescaler OpenPWM2(194); // 194 Timer ticks = 10 Hz with these settings SetDCPWM2(102); // 10% duty cycle while (1) { // This area loops forever } }