• AVR Freaks

Hot!Another PORTD Input Question PIC18F4550

Author
mn_vette
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2007/11/11 06:57:58
  • Location: 0
  • Status: offline
2012/11/24 08:06:43 (permalink)
0

Another PORTD Input Question PIC18F4550

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();
}
 
#1

8 Replies Related Threads

    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re:Another PORTD Input Question PIC18F4550 2012/11/24 15:02:21 (permalink)
    0
    Would look almost ok.
    What about PMP and possibly other shared features at PORTD?

    GENOVA :D :D ! GODO
    #2
    mn_vette
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2007/11/11 06:57:58
    • Location: 0
    • Status: offline
    Re:Another PORTD Input Question PIC18F4550 2012/11/24 18:23:25 (permalink)
    0
    I'm not exactly sure what a PMP is, but the only shared function that I saw in the data sheet was the Streaming Parallel Port(SPP).  So I attempted to disable that function by setting the SPPEN bit to zero in the SPPCON register. I added a few other things just to cover my bases though.  It didn't help.  Below is what I have in the code. 
     
    //these two line are needed to allow PORTD pullups to be engaged.
    SPPCON = 0;  //setup_psp(0);  //PSP_DISABLED);
    SSPCON1 = 0; //disable SPI functionality
    CCP1CON = 0; //setup_ccp1(0); //CCP_OFF);
    CCP2CON = 0; //disable both ccp modules
    ADCON0 = 0; //disalbe ADC function
    CVRCON = 0; //more disables
    HLVDCON = 0; //more disables
    CMCON = 0x07; //disable comparitors for pull ups to work
    post edited by mn_vette - 2012/11/24 18:38:57
    #3
    Mike017
    Super Member
    • Total Posts : 2698
    • Reward points : 0
    • Joined: 2007/08/25 08:11:31
    • Location: Lincoln, RI, USA
    • Status: offline
    Re:Another PORTD Input Question PIC18F4550 2012/11/24 18:53:59 (permalink)
    0
    Hi,
     

    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.
    How/what are you testing/seeing to determine PORTD is an output? Watch Window, meter, etc...
     
    Good Luck,
    Mike
    #4
    mn_vette
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2007/11/11 06:57:58
    • Location: 0
    • Status: offline
    Re:Another PORTD Input Question PIC18F4550 2012/11/24 23:15:24 (permalink)
    0
    I'm reading it as a pushbutton input and the code is constantly going to the code that is for the push button.  I tried an external pull up resistor with no change and I also checked the voltage with a multimeter and it is always in the low state.
    #5
    mn_vette
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2007/11/11 06:57:58
    • Location: 0
    • Status: offline
    Re:Another PORTD Input Question PIC18F4550 2012/11/25 07:10:10 (permalink)
    +3 (2)
    I got it figured out.  A function  call from a function call from a function call from some open source code I used for the USB setup was resetting the PORTD settings for some use as USB indicator lights.  I had pulled out the indicator light code, but forgot to pull out the port settings.  Line by line by line code checking got me through it.  Thanks for the confirmation that things looked ok, otherwise I would still be looking at some weird chip setup. 
    #6
    Mike017
    Super Member
    • Total Posts : 2698
    • Reward points : 0
    • Joined: 2007/08/25 08:11:31
    • Location: Lincoln, RI, USA
    • Status: offline
    Re:Another PORTD Input Question PIC18F4550 2012/11/25 13:52:14 (permalink)
    0
    Hi,
     
    Good. 'Makes sense. The port setup code looked OK in the SIM.
     
    Good Luck,
    Mike
    #7
    Phill Lima
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2017/06/13 17:08:54
    • Location: 0
    • Status: offline
    Re:Another PORTD Input Question PIC18F4550 2020/09/29 14:55:44 (permalink)
    0
    mn_vette
    I got it figured out.  A function  call from a function call from a function call from some open source code I used for the USB setup was resetting the PORTD settings for some use as USB indicator lights.  I had pulled out the indicator light code, but forgot to pull out the port settings.  Line by line by line code checking got me through it.  Thanks for the confirmation that things looked ok, otherwise I would still be looking at some weird chip setup. 

    hello, I have the same problem with you, and I also use the HID USB keyboard, my problem is only on the pins RD7 and RD6, they are not working as input, no matter what I do = /
    I've looked at the code anyway, and I can't find TRISD anywhere else in the code, you can share where you found your problem, which USB library?
    #8
    Aussie Susan
    Super Member
    • Total Posts : 3769
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re:Another PORTD Input Question PIC18F4550 2020/09/29 20:30:44 (permalink)
    +2 (2)
    I would not expect any answer on a thread that is 8 years old!
    Also, nearly every time someone says 'I have the same problem...' they don't!
    Start a new thread and tell us your environment, what works and what doesn't -what do you expect and what do you get. Ideally a small stand-alone app that exhibits the problem will help.
    Susan
    #9
    Jump to:
    © 2020 APG vNext Commercial Version 4.5