PDA

View Full Version : Internal OSC, how to?



PICante
- 6th January 2008, 18:04
Hello again!

I hope everybody had a good time during the holidays and also that you are having a good start on this New Year! :-)

Today I have fiddled with some code and I run into a problem. I get an “Error [118] Overwriting previous address content (2007)” when compiling. If I omit the first line “@ __CONFIG _INTOSC_OSC_NOCLKOUT” there are no errors!
I use MCS+ ,PBP and MPASM, the target is a 16F628A. According to the list of fuses in the *.INC file the alternatives are:

_RC_OSC_CLKOUT
_RC_OSC_NOCLKOUT
_ER_OSC_CLKOUT
_ER_OSC_NOCLKOUT
_INTOSC_OSC_CLKOUT
_INTOSC_OSC_NOCLKOUT
_INTRC_OSC_CLKOUT
_INTRC_OSC_NOCLKOUT

What I like to do is have the 16F628A run @ 4 MHz internally and be able to compile it without errors.
How do I make sure the clock setting in my code overrides the setting in the *.INC file?

Here is the code:


@ __CONFIG _INTOSC_OSC_NOCLKOUT

Cnt VAR BYTE 'Declare Cnt as a byte

TRISB = 0 ' Set PORTB pins as outputs

AGAIN:
FOR Cnt = 1 TO 3
PORTB.0 = 1 ' Turn ON LED
PAUSE 250 ' Wait 250ms
PORTB.0 = 0 ' Turn OFF LED
PAUSE 250 ' Wait 250ms
NEXT Cnt

PAUSE 2000 ' Wait 2 seconds

GOTO AGAIN ' Repeat

END ' End of program



Thanks for being here!
All the Best!

Darrel Taylor
- 6th January 2008, 18:32
Hi PICante.

Have a Great 2008.

Presetting Configuration Fuses (PIC Defines) into your Program
http://www.picbasic.co.uk/forum/showthread.php?t=543
<br>

PICante
- 6th January 2008, 18:48
Hi Darrel!

You Too!

Thanks, but this link is where I got the line which got me in trouble in the first place :-) “@ __config _INTRC_OSC_NOCLKOUT” and even after I have changed it (after reading the datasheet about the differences between 628 and 628A) to “@ __CONFIG _INTOSC_OSC_NOCLKOUT”!

Thanks.

Bruce
- 6th January 2008, 18:54
MPASM does not like multiple config declarations. Either comment out the defaults in the device header file, or change them in the header file & save it. You can't have the config directive in both the default header file and your code.

PICante
- 6th January 2008, 19:32
Hi Bruce,

Are you saying that the error I got is generated by MPSAM and not PBP?
In which order do the fuses in the 1. code, 2. *.INC file and the 3.programmer settings supersede each other? If I do not want to let the PBP automatically include the include file; where do I select this? If I remove it (the INC file) from the folder I get an error.
Anyway, which is the correct fuse for internal 4 MHz; there are a few to choose from?

Many questions, I am sorry!

Darrel Taylor
- 6th January 2008, 19:50
Sorry, I should have been more specific.

This post is in the thread I mentioned before.

What to do if i get "overwriting previous address content" error message?
http://www.picbasic.co.uk/forum/showthread.php?p=6775
<br>

Bruce
- 7th January 2008, 00:03
Yes this error is generated by MPASM. A list of MPASM assembler error codes can be found
in the MPASM help file.

You can't stop PBP from including device specific .INC files. You just need to learn how to
use/modify them for your own needs.

The error is due to the __config directive being seen in two places. 1 in the 16F628A.INC file,
and 1 in your code.

If you prefer to insert config options in your code, and use the MPASM assembler, then just
comment out the __config line in the include file.

If you insert config options in your code, and you're using the PM assembler, you don't need
to comment out config options. The PM assembler will use whatever config options you have
in your code & ignore the default config options in the 16F628A.INC file. MPASM will throw
the error.

From the 16F628A.INC file in your PBP install directory:


NOLIST
ifdef PM_USED
LIST
include 'M16F62xA.INC' ; PM header
device pic16F628A, xt_osc, wdt_on, mclr_on, lvp_off, protect_off
XALL
NOLIST
else
LIST
LIST p = 16F628A, r = dec, w = -302
INCLUDE "P16F628A.INC" ; MPASM Header
; __config _XT_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
NOLIST
endif
LIST
PBP automatically includes 16F628A.INC when you compile for this target.

If the PM assembler is used ifdef PM_USED = true, and the M16F62xA.INC file is also
included.

If MPASM is used, then the P16F628A.INC file located in your MPLAB install directory is used.

A list of all config options available for this PIC can be found in these secondary include files
that 16F628A.INC points to.

M16F62xA.INC if PM is used or P16F628A.INC if MPASM is used.

_INTOSC_OSC_NOCLKOUT is the correct option for using the internal osc, but MPASM will
complain if it sees the __config directive twice.

So;
1. Modify the config options in the PBP 16F628A.INC file.

or;
2. Comment the __config line out in this file, and drop them in your code.

If you read through both threads Darrel linked to above, it should be easy to understand.