D-Kens
Joined: 09 May 2005 Posts: 35 Location: Toulouse (France)
|
How to write to Data Memory in a PIC18F4620 ? |
Posted: Fri Jan 11, 2008 8:08 am |
|
|
Hi...
I'm trying to adapt old programs, formerly coded for a PIC16F877 target, to run them now on a PIC18F4620. I compile my code using PCW C Compiler v3.249.
My problem is with Microchip's bootloader : I got ASM code from the Application Note AN851, and managed to have it to work on my microcontroller. To enter the boot mode, one need to write the value (0xFF) to the last address of Data Memory on the component, and to reset the PIC. The assembly code given by Microchip is the folowing :
Code: | setf EEADR
setf EEADRH
setf EEDATA
movlw b'00000100
movwf EECON1
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1, WR
nop
btfsc EECON1, WR
br a $-2 ; The actual line is "br a" withouth the space, but it's replaced by bra if I type it on the forum
reset |
If I enter that into my C code, between #asm and #endasm tags, the compiler shows an error on the "bra $-2" line, because it seems the C compiler doesn't accept the "$" character. So I'm looking for the equivalent to those commands in C, if available, or any other way to write to the last address of the Data Memory. I tried to use "write_eeprom()", but it didn't seem to work (or maybe I don't use the right address ?).
Well, I begin to feel desperate about that bootloader issue : if anyone could help me, it'd be a great news.
Regards,
Christophe. |
|
SET
Joined: 15 Nov 2005 Posts: 161 Location: Glasgow, UK
|
|
Posted: Fri Jan 11, 2008 8:38 am |
|
|
It would be easier to do this in C:
Code: | write_eeprom(LAST_LOC, 0xFF);
reset(); |
Function names are from memory, please check that they are right in CCS documentation! |
|