I have been learning PIC programming & decided to hook up a PIC18F4550 and have fun with it. But its not working. I am using a genuine PICkit 2. The PICkit is detecting & programming the MCU fine but when I try to run it, it does not work at all. I have a tried a simple LED blink program & a dimming program. The weird thing is that when i touch the pin (CKI/OSC1) connected to the crystal, the LED just turns on & stays on. I tried switching circuit components & even tried a different PIC18 MCU but the same problem remains. I am using the circuit on a breadboard. Please tell me what I have been doing wrong. I have 100nF capacitors between power & ground pins. I have enclosed the code & schematic. The 2nd code is written for a PIC18F14K50.
Blinking LED code-
#include<P18F4550.h>
void delay(unsigned int x);
void main()
{
while(1)
{
TRISD=0xFE; //RD0 is output
//toggle RD0 every 1s
PORTDbits.RD0=1;
delay(1000);
PORTDbits.RD0=0;
delay(1000);
}
}
void delay(unsigned int x)
{
unsigned int i;
unsigned char j;
for(i=0; i<x; i++)
{
for(j=0; j<165; j++);
}
}
LED dimming code-
LIST P=18F14K50, MM=OFF, R=HEX
#include<P18F14K50.inc>
org 0000H
CLRF TRISC, 0; PORTC IS USED FOR OUTPUT
BSF T0CON, T08BIT, 0; TIMER IN 8-BIT MODE
BCF T0CON, T0CS, 0; USE AS TIMER
BCF T0CON, PSA; USE PRESCALER
BCF T0CON, T0PS1, 0; PRESCALE VALUE=1:8
BCF T0CON, T0PS2, 0;
BCF T0CON, T0PS0, 0;
MOVLW 9EH; INITIAL COUNT VALUE
REPEAT: MOVWF TMR0L, 0
BTG PORTC, 0, 0; SQUARE WAVE ON RC0
BSF T0CON, TMR0ON, 0; START TIMER
AGAIN: BTFSS INTCON, TMR0IF, 0; CHECK FOR OVERFLOW
BRA AGAIN
BCF T0CON, TMR0ON
BCF INTCON, TMR0IF, 0
BRA REPEAT
end