PIC18F4550 PortA read problem

Discussion in 'Programmer's Corner' started by shoraff, Jun 5, 2010.

  1. shoraff

    Thread Starter New Member

    Jun 5, 2010

    I am doing a small project at home with an LCD and four push buttons connected to PIC18F4550 controller.

    LCD is connected to PORTD & PORTB, which is working perfectly fine. But four push buttons connected as keypad matrix is connected to PORTA, which is giving lot of issues.

    I have configures PORTA0:A1 as output pins and PORTA2:A3 as input pins. During initialization I have set - ADCON1 = 0x0f, CMCON = 0x07, TRISA=0x0C.

    I set the output A0 as high using LATA=0x01 and read the PORTA after few milli seconds. Delay routine is

    Code ( (Unknown Language)):
    1. [SIZE="1"]  for(i=0;i<100;i++)
    2.     {
    3.         _asm
    4.         NOP
    5.         _endasm
    6.     }[/SIZE]
    When I read PORTA, I always get junk data. When I don't press any key then the value should be zero as I mask the PORTA with 0x0C to consider only input pins.

    As well when I run the program in release mode, I feel the controller is getting reset.

    Can anyone help me in sorting this problem out?

    Initialization code
    Code ( (Unknown Language)):
    2. #pragma config FOSC=XT_XT //INTOSCIO_EC //4 MHz crystal
    3. #pragma config PLLDIV = 1
    4. #pragma config WDT=OFF
    5. #pragma config LVP=OFF
  2. retched

    AAC Fanatic!

    Dec 5, 2009
    A schematic of the setup would also be helpful to track down problems or bugs.
  3. shoraff

    Thread Starter New Member

    Jun 5, 2010

    I have attached the circuit diagram. Do let me know if you can view it.
  4. coldpenguin

    Active Member

    Apr 18, 2010
    With my 18f4550, I found it very sensitive to interference on the pins, you must have a 10k between vdd and MCLR, otherwise it will constantly reset.
    On my similar circuit, I put in 1MOhm resistors holding RA0-3 down to ground. Otherwise I could see it floating at around 3v (when running with the debugger it went high low high low)
  5. shoraff

    Thread Starter New Member

    Jun 5, 2010
    Thanks for the suggestion. I will try it out today evening :)