PIC18F452- First time with development board

Discussion in 'Embedded Systems and Microcontrollers' started by AustinCann, Feb 8, 2011.

  1. AustinCann

    Thread Starter New Member

    Jan 30, 2011
    12
    0
    I had been using only the software debugging mode in the past. Today it was the first day on the development board. I got the board LEDS blinking. However when I wanted to make them blink on button input on development board, it simply did not work. I think I am probably not setting all registers. Here is the simple program I used:

    void main(void)
    {
    TRISA=0XFF;
    TRISC=0X00;
    while (1)
    {
    if (PORTA==1)
    {
    delay_ms(10);
    PORTC=0XFF;
    delay_ms(1000);
    PORTC=0X00;
    }
    }
    }
    Does it have to do something with ADCON0 and ADCON1 register?- I used RA4 (digital input on POR) and PORT D, but never got the LEDS blinking on input.
    Thanks
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    I don't know much C but I think this line
    if (PORTA==1)
    is checking for 00000001 on PORTA.
    If there is anything connected to any of the pins apart from RA0 that could be the problem.
     
  3. AustinCann

    Thread Starter New Member

    Jan 30, 2011
    12
    0
    I am doing it on the development board and all port pins are connected to buttons as active low. Without state of change, I reckon it wont make difference.
     
  4. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    I've had a look at the datasheet (Section 9) and it suggests putting ADCON1==7 before the TRIS instruction.
     
    AustinCann likes this.
  5. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    Hi,
    This is because PORTA is multiplexed to ADC as well. By default, the pins are analogue. To check for switch, the pin has to be digital. To make it digital add the line:
    Code ( (Unknown Language)):
    1. ADCON1=7;
    or
    Code ( (Unknown Language)):
    1. ADCON1=6;
    This tells the microcontroller to make all ADC-multiplexed inputs digital.
    You can place this before or after you set the direction of the port by writing to TRIS. Just write this before you use the pin.

    Hope this helps.
    Tahmid.
     
  6. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    Check page 184 of the datasheet.
     
Loading...