I have this sample program to blink LED with PIC18F4550 using external oscillator.
I'm using a 20.000 MHz crystal oscillator with 30pF capacitors.
The problem is when I wire the capacitors the the ground the LED doesn't blink (still off), but when I disconnect them from ground (not wired) the LED starts blinking. Blink speed change with _XTAL_FREQ
.
Program works well with internal oscillator (just by setting FOSC = INTOSCIO_EC
)
Is there direction wiring of capacitor or oscillator?
Ground here is PIC Vss
This is when using PICKIT2 directly. When using the circuit alone like the scheme, nothing happens with FOSC = INTOSCIO_EC
configuration (not working), but works well with internal oscillator.
#include<p18f4550.h>
#include "delays.h"
/* COMPILER DIRECTIVES FOR CHIP CONFIGURATION BITS*/
#pragma config FOSC = HS //INTOSCIO_EC /* Sets the oscillator mode to HS */
#pragma config WDT = OFF /* Turns the watchdog timer off */
#pragma config LVP = OFF /* Turns low voltage programming off */
#pragma config DEBUG = OFF /* Compiles without extra debug code */
#define _XTAL_FREQ 12000000 //delay_ms change by changing this
void main(void) {
TRISD = 0xF0; // PORT B Setting: Set all the pins in port B to Output.
while (1) {
LATDbits.LATD0 = 1; // RD-0 to High
LATDbits.LATD1 = 1; // RD-1 to High
__delay_ms(50); // Half sec delay
LATDbits.LATD0 = 0; // RD-0 to LOW
LATDbits.LATD1 = 0; // RD-1 to LOW
__delay_ms(50); // Half sec delay
}
}
/* THE END */