/******************************************************************** * FileName: Internal Oscillator * Processor: 18F4520 * Compiler: MPLAB C18 v.3.06 * * This program uses the delays.h library to cause delays to flash an * LED. * * Modify: * To modify the frequency of the internal oscillator * Information can be found in the 18F4520 PIC datasheet * Click in the right hand panel for section 2.6 Internal Oscillator Block * Scroll down until you find REGISTER 2-2: OSCCON REGISTER (couple pages down) * For example you will need to set these bits: * OSCCONbits.IRCF2 = ????; * OSCCONbits.IRCF1 = ????; * OSCCONbits.IRCF0 = ????; * * Try picking a frequency OTHER than the default * Then pick a different value for these lines: * #define delayTime 50 * Delay10KTCYx(delayTime); * * * Author Date Comment *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ // David Fisher 9/9/07 /** Processor Header Files ***************************************** * * Include the appropriate header (.h) file, depending on device used * Example (for PIC18f4520): #include * * Alternatively, the header file may be inserted from the Project * window in the MPLAB IDE (or both is fine) ********************************************************************/ #include #include /** Define Constants Here ******************************************/ #define delayTime 50 /** Local Function Prototypes **************************************/ void low_isr(void); // not used here but I left the interrupt stuff void high_isr(void); // not used here but I left the interrupt stuff // ============================================================ // Configuration Bits // For details on PIC18F configuration bit settings, see // PIC18 Configuration Settings in MPLAB-IDE Help // ============================================================ #pragma config OSC = INTIO67 #pragma config WDT = OFF #pragma config LVP = OFF #pragma config BOREN = OFF #pragma config XINST = OFF // ============================================================ /** Declare Interrupt Vector Sections ****************************/ #pragma code high_vector=0x08 void interrupt_at_high_vector(void) { _asm goto high_isr _endasm } #pragma code low_vector=0x18 void interrupt_at_low_vector(void) { _asm goto low_isr _endasm } /** Declarations *************************************************/ // no global variables needed here /***************************************************************** * Function: void main(void) * ******************************************************************/ #pragma code void main (void) { /* Make all bits on the Port C (LEDs) output bits. * If bit is cleared, then the bit is an output bit. */ ADCON1 = 0x0F; TRISC = 0x00; while (1) { PORTC = 0x01; Delay10KTCYx(delayTime); PORTC = 0x08; Delay10KTCYx(delayTime); } } /***************************************************************** * Function: void high_isr(void) * PreCondition: None * Input: * Output: * Side Effects: * Overview: ******************************************************************/ #pragma interrupt high_isr // declare function as high priority isr void high_isr(void) { } /****************************************************************** * Function: void low_isr(void) * PreCondition: None * Input: * Output: * Side Effects: * Overview: ********************************************************************/ #pragma interruptlow low_isr // declare function as low priority isr void low_isr(void) { }