PDA

View Full Version : Starting with PIC18F



Gérard
- 7th May 2006, 14:15
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

Melanie
- 7th May 2006, 14:40
Here is a working example for 18F2420...



'
' 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...



;************************************************* ***************
;* 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...



;************************************************* ***************
;* 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.

Gérard
- 7th May 2006, 16:40
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