Starting with PIC18F


Closed Thread
Results 1 to 3 of 3
  1. #1
    Gérard's Avatar
    Gérard Guest

    Default Starting with PIC18F

    There are a lot of thread concerning the configuration words for the 18F but nothing sounds definitively clear (in my mind).
    Does anybody write a template example for that part of code ?
    TKS a lot
    Gérard

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Here is a working example for 18F2420...

    Code:
    	'
    	'	PIC Defines
    	'	===========
    
    	@ __CONFIG    _CONFIG1H, _IESO_OFF_1H & _FCMEN_OFF_1H & _OSC_INTIO67_1H
    				' Oscillator Switch-over Disabled
    				' Fail-Safe clock Monitor Disabled
    				' Set for Internal Oscillator RA6 & RA7 Enabled
    	@ __CONFIG    _CONFIG2L, _BOREN_ON_2L & _PWRT_ON_2L & _BORV_42_2L
    				' Brown-Out Reset Enabled
    				' Power-On Timer Enabled
    				' Brown-Out Trip set to 4.2v
            @ __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
    				' WatchDog is ON
    				' Watchdog Postscaler set to 1:128
    	@ __CONFIG    _CONFIG3H, _MCLRE_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_PORTC_3H
    				' MCLR is OFF (internal)
    				' PortB 4:0 is digital on Reset
    				' CCP2 is Multiplexed with PortC.1
            @ __CONFIG    _CONFIG4L, _STVREN_ON_4L & _ENHCPU_OFF_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
    				' Stack Under/Overflow will Reset System
    				' Enhanced CPU Addressing Disabled
    				' Low-Voltage Programming is OFF
    				' DEBUG is Disabled
    	@ __CONFIG    _CONFIG5L, _CP1_ON_5L & _CP0_ON_5L
    				' Code Protect
            @ __CONFIG    _CONFIG5H, _CPB_ON_5H & _CPD_ON_5H
    				' EEPROM is Code Protected
    				' Boot Block code is Code Protected
    It WILL give you WARNINGS when used with the latest MPASM but they can for the time being be ignored.

    If compiling with a command line such as...

    PBPW -p18F2420 MyFile -ampasm -v

    The you must first modify the 18F2420.INC file found in your PBP Root directory (NOT the one in the \INC directory). The modification is nescessary to ensure that CONFIG statements are not duplicated, as CONFIG duplication is not permitted within the MPASM Assembler...

    Here is the 18F2420.INC file BEFORE it was mmodified...

    Code:
    ;****************************************************************
    ;*  18F2420.INC                                                 *
    ;*                                                              *
    ;*  By        : Leonard Zerman, Jeff Schmoyer                   *
    ;*  Notice    : Copyright (c) 2004 microEngineering Labs, Inc.  *
    ;*              All Rights Reserved                             *
    ;*  Date      : 12/31/04                                        *
    ;*  Version   : 2.46                                            *
    ;*  Notes     :                                                 *
    ;****************************************************************
            NOLIST
        ifdef PM_USED
            LIST
            "Error: PM does not support this device.  Use MPASM."
            NOLIST
        else
            LIST
            LIST p = 18F2420, r = dec, w = -311, f = inhx32
            INCLUDE "P18F2420.INC"   ; MPASM  Header
            __CONFIG    _CONFIG1H, _OSC_XT_1H
            __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
            __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
            __CONFIG    _CONFIG4L, _LVP_OFF_4L & 0bfh ;_XINST_OFF_4L
            NOLIST
        endif
            LIST
    EEPROM_START	EQU	0F00000h
    BLOCK_SIZE	EQU	8
    And here it is AFTER modifification...

    Code:
    ;****************************************************************
    ;*  18F2420.INC                                                 *
    ;*                                                              *
    ;*  By        : Leonard Zerman, Jeff Schmoyer                   *
    ;*  Notice    : Copyright (c) 2004 microEngineering Labs, Inc.  *
    ;*              All Rights Reserved                             *
    ;*  Date      : 12/31/04                                        *
    ;*  Version   : 2.46                                            *
    ;*  Notes     :                                                 *
    ;****************************************************************
            NOLIST
        ifdef PM_USED
            LIST
            "Error: PM does not support this device.  Use MPASM."
            NOLIST
        else
            LIST
            LIST p = 18F2420, r = dec, w = -311, f = inhx32
            INCLUDE "P18F2420.INC"   ; MPASM  Header
    
            NOLIST
        endif
            LIST
    EEPROM_START	EQU	0F00000h
    BLOCK_SIZE	EQU	8
    Rename the original file as something like 18f2420-Original.INC so that if you ever need to revert to it, you can do so easily without reinstalling the whole of PICBasic from your Master Disk.

  3. #3
    Gérard's Avatar
    Gérard Guest


    Did you find this post helpful? Yes | No

    Smile Better....

    Thanks for your quick answer Mélanie.

    It works better despite I did not modify the .inc files already, except I got some "Overwriting previous adress contents (0000 to 0006..)

    I've been heard about something like that in some thread.

    Best regards

    Gérard

Similar Threads

  1. Cordic trig assembly code for PIC18f
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 54
    Last Post: - 8th September 2015, 05:36
  2. pic18f driving usb printers
    By ephesus in forum USB
    Replies: 18
    Last Post: - 22nd March 2012, 02:07
  3. Starting new project - Any ideas/suggestions?
    By Megahertz in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th February 2010, 16:06
  4. Set the starting time with ds1302 picbasic
    By crisxstyle in forum Off Topic
    Replies: 9
    Last Post: - 30th September 2008, 15:14
  5. PIC 18F242 not starting
    By manxman in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th March 2007, 17:00

Members who have read this thread : 1

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