18F2431 Learning Curve


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    172

    Default 18F2431 Learning Curve

    Hi All,

    I got my 18F2431 today and I am trying to learn how to fly it.
    I thought I would start with a very simple LCD routine:

    Code:
    '****************************************************************
    '*  Name    : LCD_18F2431                                      *
    '*  Author  : Barry Phillips                                    *
    '*  Notice  : Copyright (c) 2012 Baztronics                     *
    '*          : All Rights Reserved                               *
    '*  Date    : 22/06/2012                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : LCD test program for 18F2431                                                *
    '*          :                                                   *
    '****************************************************************
    
    ' Define LCD registers and bits
    Define	LCD_DREG	PORTB
    Define	LCD_DBIT	0
    Define	LCD_RSREG	PORTB
    Define	LCD_RSBIT	5
    Define	LCD_EREG	PORTB
    Define	LCD_EBIT	4
    Define	LCD_BITS	4
    Define	LCD_LINES	2
    
    Mainloop:
    LCDOUT  $FE, $01                    ' Clear screen
    LCDOUT  $FE, $80, "Hello World"
    Pause 1000                          ' Pause 1 second
    LCDOUT  $FE, $C0, "Hello Again"
    pause 5000                          ' Pause 5 seconds
    goto Mainloop                       ' Loop forever
    When I tried to complie the program I get the following error messages

    [ASM WARNING] Invalid RAM location specified. (0) : Warning [219]

    repeated 13 times.

    I was expecting a severe learning curve with this new device but I would have thought something as simple as this would have been straight forward.

    Can someone please enlighten me on what needs to be done to correct this problem?

    Cheers
    Barry
    VK2XBP

  2. #2
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    172


    Did you find this post helpful? Yes | No

    Default Re: 18F2431 Learning Curve

    Update:

    It was a very long day yesterday!
    I realised this morning that I had the wrong device selected in MCS. It compiles now but there ares still problems.
    I did see "Hello World" appear on the first line of the LCD but it took a couple of seconds to get there...and it only happened once.
    I obviously have the set-ups all messed up. I can't even do a simple LED Blink on RC0

    Back to the datasheet.

    Cheers
    Barry
    VK2XBP

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,159


    Did you find this post helpful? Yes | No

    Default Re: 18F2431 Learning Curve

    Oscillator speed?

    Or is that not required any more with v3.0 (I'm still on v2.60).

    Robert

  4. #4
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    172


    Did you find this post helpful? Yes | No

    Default Re: 18F2431 Learning Curve

    I am using the internal oscillator which defaults to 8MHz
    I also tried the program with

    DEFINE OSC 8

    preceeding the LCD definition statements, all to no avail

    I was even more disappointed that my Blinky LED program didn't work

    Code:
    TRISA = 0               ' Set PORTA as output
    
    LED    VAR  PORTA.0     ' Assign name "LED" to PORTA.0
    
    mainloop:
       High LED             ' Turn on LED connected to PORTA.0
       Pause 500            ' Delay for .5 seconds
    
       Low LED              ' Turn off LED connected to PORTA.0
       Pause 500            ' Delay for .5 seconds
    
       Goto mainloop        ' Go back to loop and blink LED forever
       
       End
    I have +5V connecteds to pins 7 and 20 (AVdd and Vdd) and 0V connected to pins 8 and 19 (AVss and Vss). I have a 10k pull-up resistor from MCLR (Pin 1) to +5V and 330R in series with LED connected from RA0 (Pin 2) to 0V. I even tried fliping the LED just in case I put it in backwards!

    Any ideas on why this thing won't work as expected?
    Perhaps the default for RA0/AN0 is an analog input pin? I thought the TRISA = 0 statement would overide...

    Cheers
    Barry
    VK2XBP

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: 18F2431 Learning Curve

    How are the configs setup?
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,159


    Did you find this post helpful? Yes | No

    Default Re: 18F2431 Learning Curve

    I always stay away from analog pins until I get a basic program running.

    Robert

  7. #7
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: 18F2431 Learning Curve

    Hi Barry,

    To include your configs in your pbp 3.0 code is pretty easy. Here are some examples: http://www.picbasic.co.uk/forum/show...963#post110963

    The bare bones ones to include would be these (though I have not tried running it on internal yet): Note it defaults to 4 mhz, unless you set the oscon bits for something else.
    Code:
      #CONFIG
        __CONFIG    _CONFIG1H, _OSC_IRCIO_1H
        __CONFIG    _CONFIG2H, _WDTEN_ON_2H & _WDPS_512_2H
        __CONFIG    _CONFIG4L, _LVP_OFF_4L
    
      #ENDCONFIG
    
    ADCON0 = %00000000
    ADCON1 = %00000000
    Last edited by ScaleRobotics; - 23rd June 2012 at 06:03.
    http://www.scalerobotics.com

  8. #8
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: 18F2431 Learning Curve

    Include the line

    DEFINE OSC xx

    And set all the options to disable (watchdog, brown-out, etc) to start with.

    Robert
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  9. #9
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: 18F2431 Learning Curve

    Hi,
    Here are the CONFIGs I use for my 2431:
    Code:
    #CONFIG
        CONFIG OSC = HSPLL
        CONFIG FCMEN = ON
        CONFIG IESO = OFF
        CONFIG PWRTEN = ON
        CONFIG BOREN = ON
        CONFIG BORV = 42
        CONFIG WDTEN = OFF
        CONFIG WDPS = 512
        CONFIG WINEN = OFF
        CONFIG PWMPIN = OFF
        CONFIG LPOL = HIGH
        CONFIG HPOL = HIGH
        CONFIG T1OSCMX = OFF
        CONFIG MCLRE = ON
        CONFIG STVREN = ON
        CONFIG LVP = OFF
        CONFIG DEBUG = OFF
        CONFIG CP0 = ON
        CONFIG CP1 = ON
        CONFIG CP2 = ON
        CONFIG CP3 = ON
        CONFIG CPB = OFF
        CONFIG CPD = OFF
        CONFIG WRT0 = OFF
        CONFIG WRT1 = OFF
        CONFIG WRT2 = OFF
        CONFIG WRT3 = OFF
        CONFIG WRTC = OFF
        CONFIG WRTB = OFF
        CONFIG WRTD = OFF
        CONFIG EBTR0 = OFF
        CONFIG EBTR1 = OFF
        CONFIG EBTR2 = OFF
        CONFIG EBTR3 = OFF
        CONFIG EBTRB = OFF
    #ENDCONFIG
    If you're running on the internal oscillator then you need to change from HSPLL to IRCIO.

    The oscillator section of the datasheet indicates that the internal oscillator defaults to 4Mhz but looking at the initialization condition of the OSCCON register it seems like bits 4,5,6 are all zero on power up - which would give you 31kHz. If you then have the clock DEFINED to 8MHz your 500ms PAUSE will actually be 322 seconds....

    So, without actually testing this I'd try something like
    Code:
    DEFINE OSC 8
    OSCCON = %01110010   ' Internal oscillator, 8MHz
    /Henrik.

  10. #10
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    172


    Did you find this post helpful? Yes | No

    Default Re: 18F2431 Learning Curve

    Thanks Henrik.

    There is SO MUCH in the datasheet for this device!
    Just when you think you have everything under control, something else raises its ugly head

    I will try your configs and recommended changes over the next 24-48 hours and report back - hopefully with good news.

    I went out this afternoon and bought a couple of crystals to play with - just in case. I now have 4, 8 and 20Mhz crystals to plug in, if and when required.

    Cheers
    Barry
    VK2XBP

  11. #11
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    172


    Did you find this post helpful? Yes | No

    Default Re: 18F2431 Learning Curve

    Hi Henrik,

    I am pleased to advise that I now have a simple LCDOUT and LED Blink program operating as expected.
    When I went through the '2431 datasheet regarding OSCON Register I selected OSCON = %0111110 which is somewhat different to what you suggested.
    Both work but I am curious to know how, when and why bits 0-3 of the OSCON register should be used. Any comments?

    My next stage of experimentation will be to get the serial LCD display working in the background using the HSEROUT statement. From there I will move onto ADCin to read a pot and follow up with the HPWM command.

    Progress is slow but I am trying to understand "why" things are the way they are in conjunction with learning "how" to do things.

    Cheers
    Barry
    VK2XBP

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts