I'm developing a frequency function for a PWM function later on. For some reason I'm having trouble with it, here's my code:
It compiles fine in C18 using the PIC18F1320, but nothing happens. Do any of you notice where the bug is?
Rich (BB code):
- //
- // PWM1.C
- //
- #include <p18f1320.h>
- #include <delays.h>
- #include <stdlib.h>
- #pragma config OSC=INTIO2, WDT=OFF, LVP=OFF, DEBUG=ON
- void freq(char pins, unsigned int frqcy, unsigned int timer) // Note & Timer driver; determines which note will be played and for how long
- {
- unsigned int times;
- INTCONbits.TMR0IF = 0; // Clear OVF Flag
- LATA = pins; // Initialize LATA
- TMR0L = frqcy & 0xFF;
- TMR0H = (frqcy >> 8) & 0xFF;
- T0CON|=0x80;
- for(times=timer;times>0;times--) // Duration of playing
- {
- TMR0H = (frqcy >> 8) & 0xFF; //Load TMR0H byte first
- TMR0L = frqcy & 0xFF; // Load TMR0L byte next
- while(!INTCONbits.TMR0IF); // Wait for timer
- ` INTCONbits.TMR0IF = 0; // Clear OVF Flag
- LATA = ~LATA; // Invert output
- }
- }
- void main()
- {
- ADCON1 = 0x0E; // ADC Settings as digital inputs from RA1-RA3
- OSCCONbits.IRCF0=1;
- OSCCONbits.IRCF1=1;
- OSCCONbits.IRCF2=1;
- T0CONbits.TMR0ON = 0; // Don't turn timer on yet
- T0CONbits.T08BIT = 0; // Timer0 is configured as 16-bit timer
- T0CONbits.T0CS = 0; // Use internal clock
- T0CONbits.PSA = 1; // Prescaler is not assigned
- T0CONbits.T0PS2 = 0;
- T0CONbits.T0PS1 = 0;
- T0CONbits.T0PS0 = 0;
- OSCCONbits.IRCF0=1;
- OSCCONbits.IRCF1=1;
- OSCCONbits.IRCF2=1;
- while(!OSCCONbits.IOFS);
- freq(0x01, 60990, 1000);
- }