1. digitalkid

    Thread Starter New Member

    Nov 6, 2009
    1
    0
    Hi Guys,

    New to this, just starting out so be nice.

    I am trying to get the above PIC just to light up aan LED on RA1, the code compiles but does not do anything when I program the PIC. Could you look over the code to see if anything is wrong.

    #include <p18f2685.h>
    #include <delays.h>
    #include <string.h>

    // delay routines
    void delay_ms(int atime);
    void delay_us(int dtime);

    //void main (void)
    void main()
    {

    TRISA = 0; // set PORTA as OUTPUT
    TRISB = 0;

    for(;;) // forever
    {
    TRISA = (0xFF);
    PORTA = (0b11111111);
    TRISB = (0xFF);
    PORTB = (0b11111111);
    //PORTA = 0xff ; // turn all LEDs ON
    delay_ms(500) ; // wait 500 ms
    //PORTA = 0 ; // turn all LEDs OFF
    //delay_ms(500) ; // wait 500 ms
    }
    return(0);
    }

    //DELAYS//
    void delay_us(int dtime)
    {
    int a;
    for (a=0; a<dtime; a++)
    {
    Nop();
    Nop();
    Nop();
    Nop();
    }
    }
    void delay_ms(int atime)
    {
    delay_us(200);
    delay_us(200);
    delay_us(200);
    delay_us(200);
    delay_us(200);
    }
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    You have commented out both of the PORTA commands. Did you mean to do that?

    hgmjr
     
  3. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    In the for loop you have TRISA register equal to 0xFF which sets portA pins as inputs.The same is true for TRISB. Remove the TRISA and TRISB instruction from the loop if you want your pins to be defined as outputs (you have previously defined them).
     
  4. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    All PIC ports that are capable of performing analogue functions as well as digital functions will default to the analogue mode. In your case this means that if you want to use portA as a digital port you first have to turn off and analogue functions for that port. This includes things like disabling the AtoD converter, and any comparator functions.

    Take a look at the section on portA in the data sheet and see which registers control port A configuration.
     
  5. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    You need to disable comparators (CMPCON) and Analog features on Port A for the outputs.

    Also, You set TRISA = 0x0, then in the main loop, you set it to 0xFF (All Input)