I've looked around and it seems that the PORTD has some issues being set as an input. I had my program working just fine until I decided to swap some pins to use the internal pullups on the PORTD to save on the external components. Previously PORTD was used as an output. Somehow I messed something up and the PORTD is still an output. I tried putting an external pull up resistor on the pins and it still doesn't work correctly, telling me it is driven as an output. Here is the function call I am using to set up the ports. Am I doing something wrong here? From the datasheet BIT7 of PORTE controlls the pullup resistors for PORTD, kind of messy when trying to use PORTE though. Thanks for the help guys. Oh, this is on a PIC18F4550.
// Initialise the PIC
static void initialisePic(void)
{
// PIC port set up --------------------------------------------------------
// Default all pins to digital
ADCON1 = 0x0F;
// Configure ports as inputs (1) or outputs(0)
TRISA = 0b00000000; //output for red LED's and center LED and G1 LED 11111111;
TRISB = 0b11111111; // paddle inputs
TRISC = 0b00000000; // output for G2-G4
//#if defined(__18F4550)
TRISD = 0b11111111; // pushbutton input
TRISE = 0b00000000; // buzzer and timer active light
//#endif
// Clear all ports
PORTA = 0;
LATA = 0b00000000;
PORTB = 0;
LATB = 0b00000000;
PORTC = 0;
LATC = 0b00000000;
//#if defined(__18F4550)
PORTD = 0;
LATD = 0b00000000;
PORTE = 0x80;
LATE = 0b10000000; //keep pull up on port D
//#endif
//these two line are needed to allow PORTD pullups to be engaged.
SPPCON = 0; //setup_psp(0); //PSP_DISABLED);
CCP1CON = 0; //setup_ccp1(0); //CCP_OFF);
CMCON = 0x07; //disable comparitors for pull ups to work
//Interupt registers
INTCON = 0b11000000; //global interupt turn on clears T0 interrupt
INTCON2 = 0b00000100; // sets pull ups on B and TMR0 high priority
LATE = 0b10000000; //Sets pull ups on D
T0CON = 0b00000000; //turns off timer
T1CON = 0b10110100; //sets up T1 timer and shuts it off
IPR1 = 0b00000011; //SETS TMR1 & TMR2 PRIORITIES TO HIGH
PIR1 = 0; //clears T2 interupt
T3CON = 0b00000001; //sets up T3 timer and gets it rolling
PIE2 = 0b00000000; // makes sure t3 timer doesn't set interrupt (USB interrupt enable here too)
// If you have a VBUS sense pin (for self-powered devices when you
// want to detect if the USB host is connected) you have to specify
// your input pin in HardwareProfile.h
#if defined(USE_USB_BUS_SENSE_IO)
tris_usb_bus_sense = INPUT_PIN;
#endif
// In the case of a device which can be both self-powered and bus-powered
// the device must respond correctly to a GetStatus (device) request and
// tell the host how it is currently powered.
//
// To do this you must device a pin which is high when self powered and low
// when bus powered and define this in HardwareProfile.h
#if defined(USE_SELF_POWER_SENSE_IO)
tris_self_power = INPUT_PIN;
#endif
// Application specific initialisation
applicationInit();
// Initialise the USB device
USBDeviceInit();
}