18F4580 settings


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Config options and definitions vary from one device type to the next, so you can't always get away with cut & paste config options.

    Just look in the P18F4580.INC file in your MPASM directory for a complete list of options available for each device type.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Bruce, to be honest I don't have the understanding of these devices to really appreciate the info in that INC file...

    Here's my logic... for what its worth.

    The attached code works with a DS1307 module when using a 16F877A with just two small changes, namely the config settings are set to
    Code:
    @   __config _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF
    And the OSC value set to 20

    I swapped the PIC for an 18F4580, changed the OSC value to 48 and the config settings to
    Code:
    ASM 
    ;  __CONFIG    CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L
    ;  __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
      __CONFIG    _CONFIG2L, _PWRT_ON_2L  
      __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
      __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
      __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    It compiles with no errors, loads into the PIC, but the LCD is blank. Both chips used RC3 and RC4 for the Ic2 (SCL and SDA) and I've tried changing OSC to 20 instead of 48 but it still fails to display anything (even garbage) on the LCD.

    Why is life so difficult.... !
    Attached Files Attached Files
    Last edited by malc-c; - 26th March 2010 at 21:50.

  3. #3
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Well the PIC's working with those settings - I went back to basics and wrote the following simple basic "hello world" type code.

    Code:
    ASM  ; 18F2550/4550, 20mhz crystal
    ;  __CONFIG    CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L
    ;  __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
      __CONFIG    _CONFIG2L, _PWRT_ON_2L  
      __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
      __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
      __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    
    DEFINE  OSC 48
    
    clear
    
    ;----[LCD definitions]------------------------------------------------------
    DEFINE LCD_DREG  PORTB          ' LCD Data port
    DEFINE LCD_DBIT  0              ' starting Data bit (0 or 4)
    DEFINE LCD_EREG  PORTB          ' LCD Enable port
    DEFINE LCD_EBIT  5              '     Enable bit  (on EasyPIC 5 LCD)
    DEFINE LCD_RSREG PORTB          ' LCD Register Select port
    DEFINE LCD_RSBIT 4              '     Register Select bit   (on EasyPIC 5 LCD)
    DEFINE LCD_BITS  4              ' LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 4              ' number of lines on LCD
    DEFINE LCD_COMMANDUS 2000       ' Command delay time in us 
    DEFINE LCD_DATAUS 50            ' Data delay time in us
    
    ;---------------------------------------------------------------------------
    
    	
    counter var byte
    for counter = 1 to 10
    LCDOut $FE,2,"Number = ",dec counter
    pause 10
    next
    This displays "Number = " and counts from 1 to 10 on the LCD

    I've looked at the datasheet, but can't see anything obvious other than making the correct pins on Port C input or outputs (something I would of thought would of ported over from the code)

    Any suggestions

  4. #4
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Well expanding on the first test I now have data being read from the RTC module

    Code:
    ASM  ; 18F2550/4550, 20mhz crystal
    ;  __CONFIG    CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L
    ;  __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
      __CONFIG    _CONFIG2L, _PWRT_ON_2L  
      __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
      __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
      __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    
    DEFINE  OSC 48
    
    clear
    
    ;----[LCD definitions]------------------------------------------------------
    DEFINE LCD_DREG  PORTB          ' LCD Data port
    DEFINE LCD_DBIT  0              ' starting Data bit (0 or 4)
    DEFINE LCD_EREG  PORTB          ' LCD Enable port
    DEFINE LCD_EBIT  5              '     Enable bit  (on EasyPIC 5 LCD)
    DEFINE LCD_RSREG PORTB          ' LCD Register Select port
    DEFINE LCD_RSBIT 4              '     Register Select bit   (on EasyPIC 5 LCD)
    DEFINE LCD_BITS  4              ' LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 4              ' number of lines on LCD
    DEFINE LCD_COMMANDUS 2000       ' Command delay time in us 
    DEFINE LCD_DATAUS 50            ' Data delay time in us
    
    ;---------------------------------------------------------------------------
    
    
    RTCYear	Var	Byte
    RTCMonth Var Byte
    RTCDate	Var	Byte
    RTCDay	Var	Byte
    RTCHour	Var	Byte
    RTCMin	Var	Byte
    RTCSec	Var	Byte
    RTCCtrl Var	Byte
    
    SDA	Var	PORTC.4
    SCL	Var	PORTC.3
    
    main:
    I2CRead SDA,SCL,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCDay,RTCDate,RTCMonth,RTCYear,RTCCtrl]
    Lcdout $fe, 2,hex2 RTCDate, "/",hex2 RTCMonth, "/" , hex2 RTCYear,_
    		"  ", hex2 RTCHour, ":", hex2 RTCMin, ":", hex2 RTCSec
    goto main:
    So now just have to work out why the original code that worked with the 16F877A didn't / doesn't port across ?

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Malcolm,

    Read this thread. http://www.picbasic.co.uk/forum/showthread.php?t=543

    If you're still stuck let me know.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Bruce,

    Thanks for the reply. I've managed to port Mel's RTC code from the 16F877A to the 18F4580, however I have one config setting that I can't work out

    If I set the config bits in the programmer thus



    The code runs. However if I let the code set the config bits it fails to run correctly. It seems I need to set the Oscillator to HS-PPL in order for it to run at the correct speed. Could you advise me what I need to add to the code to set this correctly ?

    Edit:

    Forgot to mention I've tried
    Code:
    __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
    and get the "symbol not previously defined" error, even though I've edited the PBP INC file.
    Attached Images Attached Images  
    Last edited by malc-c; - 27th March 2010 at 12:36.

  7. #7
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Uhmmm steep learning curve

    I delved deep into that INC file in MPSAM folder and tried the following

    Code:
    ASM  
      __CONFIG    _CONFIG1H, _OSC_HSPLL_1H
      __CONFIG    _CONFIG2L, _PWRT_ON_2L  
      __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
      __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
      __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    Works fine now !

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