2

I am quite new to the PICs and especially with XC8 pic-as and MPLAB-X

I have a ultra minimal project i am working on, and i have some questions regarding the OSCCAL values located at the reset vector, and how to "not specify" them (for programming) while still be able to debug the program using the simulator.

Here is my code :

radix   dec

processor 10F202

CONFIG  WDTE = OFF
CONFIG  CP = OFF
CONFIG  MCLRE = OFF

#include "xc.inc"

;    PSECT resetVector, class=CODE
;resetVector:
;    MOVLW 14h

PSECT main, class=CODE
main:
MOVLW 1
GOTO main
END

When compiling and linking with additional flags -Wl,-pmain=0h i get this hex file (nothing at 0x1FF which is the reset vector and the MOVLW instruction to load the OSCCAL value)

:0300000001000AF2
:021FFE00EB0FE7
:00000001FF

I have not flashed that program, as i do not yet have a programmer, but it looks "okay".

Problem #1 : i cannot use the simulator to test the code, as it complains there is no section at 01FFh (the reset vector, which will then wrap around to 000h)

No source code lines were found at current PC 0x1ff.
Use Program memory view to see instruction code disassembly. 

If i then add a section to "simulate" the resetVector (MOVLW OSCCAL) by uncommenting the above section, and compile it with additionnal linker flags -Wl,-presetVector=1FFh i get the folling hex file :

:0300000001000AF2
:0101FF0014EB
:021FFE00EB0FE7
:00000001FF

There is a proper OSCCAL value of 14h loaded at 01FFh, and the simulator will start ok.

Problem #2 : if i would program a chip with this hex file, will it override the OSCCAL value already on the chip from factory calibration, by the value present in the hex file ? Or is it smart enough to ignore the value in the hex file, or rewrite the previous one after programming ?

Additionnal question #3 : is there any better way to specify section addresses than linker flags ? Using linker flags feels like more like a workaround than a feature or an ergonomic way to do this (and you have to add/remove flags everytime you modify your sections, which is cumbersome)

Thanks in advance for your insights.

2
  • See this link for another example on using the pic-as tool with the PIC10F202. Commented Nov 12 at 23:02
  • Thank ! In these examples the author adds a -DCODE=2 linker option, which on its own does not produce 2-bytes par word hex file : each psect needs its own delta=2 flag to produce a 2 bute per word hex. Any idea why the option seems ignored ? Commented Nov 16 at 11:35

1 Answer 1

2

1)You need first to write correct declarations in your code and compiler options.

PROCESSOR 10F202
   
#include <xc.inc>
radix   dec 

;Write in project properties...
;pic-as Global Options - Additional Options:-Wl,-presetVec=0h,-pcalValue=1FFh
    
; CONFIG
  CONFIG  WDTE = OFF            ; Watchdog Timer (WDT disabled)
  CONFIG  CP = OFF              ; Code Protect (Code protection off)
  CONFIG  MCLRE = OFF           ; Master Clear Enable (GP3/MCLR pin fuction is digital I/O, MCLR internally tied to VDD)
    
PSECT   resetVec,class=CODE,delta=2 
resetVec:
    movlw 1
    goto resetVec
    
  
PSECT   calValue,class=CODE,delta=2 
    movlw   0x10

2)In datasheet PIC10F202 section 9.2 is written:

Erasing the device will also erase the preprogramed internal calibration value. The calibration value must be read prior to erasing the part so it can be reprogramed correctly later.

Sign up to request clarification or add additional context in comments.

2 Comments

great answer, now with delta=2 all looks good.... Except the CONFIG ! It is at 1FFE in the hex file, and would map to FFF in device memory ... which only goes to 3FF. I tried to relocate the config, but Mplap does not let me remap it as it is an "absolute" section. If I cannot change it, how does the programmer guess that FFF should be placed at 3FF for the configuration word ? Thank
No, you can't see the CONFIG status in device program memory because the CONFIG address is 0xFFF. You can see the CONFIG status in menu: Production/Set configurations bits: Memory-Configuration Bits

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.