PIC18 first time programing - help!!

Discussion in 'Embedded Systems and Microcontrollers' started by Shreder001, Jul 28, 2009.

  1. Shreder001

    Thread Starter Member

    Mar 7, 2009
    22
    0
    Hey guys this is my first time programing a PIC18 and a have a few questions. I am doing it in assembly language. My first goal is to turn an LED on but i cant quite seem to do that yet. Heres my program:

    #include <p18F2431.inc>
    CONFIG = _CONFIG1H, 0x06

    CONFIG = _CONFIG2L, 0x0E
    CONFIG = _CONFIG2H, 0x1E

    CONFIG = _CONFIG3L, 0x3C
    CONFIG = _CONFIG3H, 0x9D

    org 0000

    BANKSEL TRISA
    CLRF TRISA
    BANKSEL PORTA
    BSF PORTA,0


    end

    Im not sure how to configure it. Every time i try to build it, i get this error message:
    Missing argument(s) (configuration byte setting is missing)

    What do I do? Thanks!!!
     
  2. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Your syntax for setting the configuration bits is wrong.

    You can set individual function using the CONFIG command, eg
    Code ( (Unknown Language)):
    1.   CONFIG OSC = HSPLL
    2.   CONFIG WDTEN = ON
    3. ;and so on.
    Take a look at the P18F2431.INC file to see all the options.

    The other way to set the configuration bits is to write a hex value to the appropriate configuration register, as you are trying to do.
    The syntax to do it this way is
    Code ( (Unknown Language)):
    1.   __CONFIG _CONFIG2H,0x0E ;Note the double underline before the CONFIG!
    Once you settle on one method of setting the configuration bits you must stick with it all the way through. You can't mix them and set some bits with the CONFIG command and others with the __CONFIG command.
     
  3. Shreder001

    Thread Starter Member

    Mar 7, 2009
    22
    0
    Ok I did that, now i have a new prob. Here is my program now:

    #include <p18F2431.inc>
    CONFIG OSC = HS
    CONFIG FCMEN = OFF
    CONFIG IESO = OFF
    CONFIG PWRTEN = ON
    CONFIG BOREN = ON
    CONFIG BORV = 20
    CONFIG WDTEN = OFF
    CONFIG HPOL = LOW
    CONFIG LPOL = LOW
    CONFIG LVP = ON
    org 0000


    BANKSEL TRISA
    CLRF TRISA

    BANKSEL PORTA
    BSF PORTA,1


    end

    I can build it now, but RA1 is not turning on. Any thoughts?
     
  4. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    You don't use the bankswitch with the 18F and try LATB instead of PORTB
     
  5. Shreder001

    Thread Starter Member

    Mar 7, 2009
    22
    0
    Tried all of that, still doesn't work.
     
  6. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    Run it through the simulator. Also try using the internal osc for testing.
     
  7. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    PortA can be configured as either an analog port or a digital port. It defaults to analog so to use it as a digital port you have to set appropriate register (clear ansel0 I think should do it).
     
Loading...