Electronic – Checking if microchip or software is broken

pic

I've build a circuit with a pic18F4550, I'm trying to power up 8 leds, but I get no output voltage from any output pin.

I suspect the pic might be broken because while building the circuit I made two mistakes:
– I wired the 5v regulator wrongly, and supplied 9v to the pic for the first time
– on one side of the pic I connected power to vss and ground to vcc

However, after noticing my mistakes and fixing them, I reprogrammed pic and got no error (I'm using MPlabX and PicKit2). Also the pic is not heating up or anything like that.

I triple checked all the wires and schematics, but there is only 5v in the two vcc pins, and 0v in the output ports.

This is my program:

#pragma config XINST = OFF
#if defined(__XC)
    #include <xc.h>        /* XC8 General Include File */
#elif defined(HI_TECH_C)
    #include <htc.h>       /* HiTech General Include File */
#elif defined(__18CXX)
    #include <p18cxxx.h>   /* C18 General Include File */
#endif
#if defined(__XC) || defined(HI_TECH_C)

#include <stdint.h>        /* For uint8_t definition */
#include <stdbool.h>       /* For true/false definition */

#endif
#define NO_CLRWDT
#define SYSCLK          20000000
#define PLL             4
#define SYSCLK_PLL      (SYSCLK*PLL)
#define FCY             (SYSCLK_PLL/2)

#include "system.h"        /* System funct/params, like osc/peripheral config */
#include "user.h"          /* User funct/params, such as InitApp */

void main(void){
    TRISD = 0x00;
    TRISC = 0x00;
    PORTC = 0xFF;
    PORTD = 0xFF;
    while(1){
    }
}

Could my pic be broken? and how can I check or debug the issue? I'm newbie at both soft and electronics.

Best Answer

From my extensive experience of screw-ups and facepalms when building up circuits for PICs, if the chip still programs and verifies successfully, you're probably ok.

The problem you're having is in your code. Here's a list of probable causes:

  1. You don't have configuration bits set, so the FOSC bits are running as default. The default FOSC on an 18F4550 is an external clock. Unless you actually have an external clock connected to OSC1 (which you probably don't), your program won't execute.

  2. The watchdog timer is default to on, which means it's running and constantly resetting your chip. It should be disabled in the configuration bits.

  3. You have no infinite loop at the end of your code. Without an infinite loop, the program will reach the end of the program space and reset the chip. You can do something as simple as putting "while(1);" as the last line in your main function.