CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Tiny bootloader image 18F4620 requested

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

Tiny bootloader image 18F4620 requested
PostPosted: Tue Jul 24, 2007 3:08 am     Reply with quote

Hi,

I'm looking for an 18F4620 image that works under TinyBldWin v1.93 and uses the internal oscillator of the chip.
I've come a long way with modifying an existing image. It seems to work, but I can only write my custom app once. I do reserve the bootloader space ofcourse. Then my custom app. always runs and the bootloader never reacts anymore.
When examining this issue it seems that writing the code by the TinyBldWin does change the LSB of the startup vector. It does not point anymore to "IntrareBootloader" but now to "bnz way_to_exit". That's way my custom app start right away. But this makes no sense....

Has anybody encountered this issue?

I'm currently working with TinyBldWin v1.9.1;
Build 1.9.3 can -not- find the pic with the "check pic" button. Anybody knows why?

Kind regards,
Edwin
Mark Weir



Joined: 11 Sep 2003
Posts: 51
Location: New Zealand

View user's profile Send private message

Bootloader
PostPosted: Tue Jul 24, 2007 2:40 pm     Reply with quote

Hi there,

Have you updated the ini file? you need to change these

SizeofBLD=264 - Add this line
SizeOfBLD_W=132 - Change this line

Basically if you are getting 1 bootloader then no more you have probably overwritten the data at the reset vector.

Good Luck

Mark
_________________
Life is too short to avoid asking questions
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

PostPosted: Tue Jul 24, 2007 3:04 pm     Reply with quote

Hi Mark,

Thank you for this very interesting tip. I would never have expected the buildsize of the bootloader in the ini-file.
Why do I need to also -add- a line SIzeofBLD ? Is the word count not enough?

Concerning the reset vector; I would expect tiny bootloader to not overwrite this area. Intercept the goto main opcode and write this at first_address.
But now the coin falls (this is a dutch saying Very Happy ) The TinybldWin app is probably doing this and therefore needs to know the size of the bootloader. Yes! I tried to find the asm code for this interception but I can't find it.

Do you know also why v1.9.3 is not reacting with the previous bootimages?

Thanks for this great tip!
Regards,
Edwin
Mark Weir



Joined: 11 Sep 2003
Posts: 51
Location: New Zealand

View user's profile Send private message

PostPosted: Tue Jul 24, 2007 3:20 pm     Reply with quote

Hi Edwin,

I spent several days doing exactly what you are doing now. I had to set up tinybootloader to work with 18F4620, intrc, 19200 baud on RS485 and at 32mhz.

I got some good info from a post labelled 'RS485 bootloader with sw reset'
Search for this on the forum. My application needs to upload at a prompt from software.

I am working with V1.91 also as I had problems with V1.93. I have since bought the Tiny Bootloader code from the designer as we will be building it into our application so we might find some of the problems as we work through this.

Cheers

Mark
_________________
Life is too short to avoid asking questions
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

PostPosted: Wed Jul 25, 2007 1:48 am     Reply with quote

Hi Mark,

Maybe I can ask you for a little bit more help? The SizeofBLD is working perfectly; reset vectors are now pointing to the place they should.
Thank so far. But now an other surprise is in place.

After the first write of my custom app it runs perfectly. When I read the flash with the ICD; both my app and the bootloader are in place. Reset vector and main vector perfectly on the right spot; with the right value.

Then when I cLick "checkpic" again I get the message

Searching for PIC ...
pic sending unknown data: "K" <> 74h=t
Check baudrate & Start Write while PIC is not sending serial data (e.g. in reset)
ERROR!

-- Skip below >> see next message

So I ICD read the flash again, and the bootloader has only destroyed itself !! All "FF" My app is still perfectly in place, the reset vector is still pointing to the startpoint where the bootloader was.

Look like a James Bond movie; kill the message after use Laughing

Any thoughts? Did you encounter this also??

Regards,
Edwin.


Last edited by Torello on Wed Jul 25, 2007 2:05 am; edited 1 time in total
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

PostPosted: Wed Jul 25, 2007 2:02 am     Reply with quote

Hi Mark,

The last message was not fully correct. The bootloader get a bit destroyed. The Main app vector is still in place but upto FF40 all opcode is erased.

Adress space FFFF- FF40 + 8 (for the main app vector ) are again the famous 100 words. Is the TinybldWin still not fully aware of the new bootlader size??

Regards,
Edwin


Last edited by Torello on Wed Jul 25, 2007 12:30 pm; edited 1 time in total
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Wed Jul 25, 2007 10:03 am     Reply with quote

Post your email and I'll forward the image to you.
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

PostPosted: Thu Jul 26, 2007 3:20 am     Reply with quote

Hi Mark,

Still stuck on the point that TinybldWin erases the flash upto 0xFF40. And then programs the user app.

It still calculates with 100 words size for the bootlader (minus 4 of the vector).
This seems not being corrected by the ini-settings:

- SizeOfBLD_W= <word count>
- SizeOfBLD= <word count>*2

Do you've got a tip for me? I'm I still missing a setting? Should SizeOfBld be SizeOfBlD_B ??


Kind regards,
Edwin.
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

PostPosted: Thu Jul 26, 2007 4:10 am     Reply with quote

Hi All,

I put my hope on TinybldWin v1.93. Maybe this version does not erase a fixed 100 words.

First there is a change in the way RTS is being activated. RTS should reset the pic, then it waits in reception for 0x1C of the computer.

In version 1.93 RTS is not pulsed low any more, but *KEPT* low. Put a capacitor (~100nF, Rpullup=47k) in series with the Mclr line and v.193 seems to operate.

But, unfortunately, also v1.93 seems to erase upto 0xFF40 when SizeOfBLD_W=110 is used...

Still investigating
Mark Weir



Joined: 11 Sep 2003
Posts: 51
Location: New Zealand

View user's profile Send private message

Tiny B
PostPosted: Thu Jul 26, 2007 5:41 am     Reply with quote

Hi Edwin,
I can't understand why you are still overwriting.
I have copied the ini file for you to check your settings against:
[PIC]
COMport=COM1
COMspeed=19200

[WINDOW]
Top=40
Left=430
Width=541
Height=278

[OPTIONS]
PreCodes=12h
PulseRTS=0
ActiveRTS=0
SearchDelay=5
Timeout=300
SearchForCOMs=0
SizeofBLD=264
SizeOfBLD_W=132

[TERMINAL]
TerminalBufferLength=10000
SwitchToTerminal=0

When you make the changes you must save the file before closing it.

Cheers

Mark
_________________
Life is too short to avoid asking questions
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

PostPosted: Thu Jul 26, 2007 7:05 am     Reply with quote

Hi Mark,

I finally have found most of the troubles. Very Happy Very Happy

First off all:
You can not specify all different words lengths of builds. It probably has to do that the addresses are grouped in blocks of 64 bytes; I did not yet figured this out. But if I use SizeOfBLD_W=132 (my size was 110); it does not erase flash anymore upto 0xFF40
So now my bootimage for the 4620 internal oscillator 8Mhz/4*PLL/115200 works !!!

Other issues v191:
- The option SizeOfBLD (without _W) is not used

Bug/issues TinybldWin v1.93:
- has a **BIG** bug; after write flash it shifts the startup vector 2 bytes; so the goto bootloader is now suddenly at 0x0002. Yakkkk!
- The switching of com speeds (Write versus terminal) in TinybldWin v1.93 does not work very well. If you let it open the terminal automatically then you have to close and reopen the port to get to the right comspeed. The same more a less happens when at opened terminal you click "Check pic". The first time it does not find it and the second click is ok.

But because v193 has the write startup vector bug; I will use v191 for now.

Kind regards,
Edwin.
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

PostPosted: Thu Jul 26, 2007 7:54 am     Reply with quote

Hi Again,

Last part of the SizeOfBLD_W puzzle (I couldn't let is rest Smile ); The sizes may increase with stepsize of 32 words. I tried 8 and 16; but these don't work.

It worked at 132, 164, 196 words.

Now let's wait for v1.93 to get debugged. Tinybootloader is still my favorite.

For those interested in the image see code below. I still want to tweak it a little bit. But it works now :-)

Code:
   radix DEC
   LIST      P=18F4620   ; change also: Configure->SelectDevice from Mplab
   xtal EQU 32000000      ;  internal oscillator 8Mhz with 4* PLL
   baud EQU 115200         ;  baudrate
   
   ;********************************************************************
   ;   Tiny Bootloader      18F series   
   ;   [email protected]
   ;   http://www.etc.ugal.ro/cchiculita/software/picbootloader.htm
   ;   Modified by Edwin Baaij; tested with tinybldWin.exe v1.9.1
    ;   IMPORTANT: (dd 26/07/2007) use TinybldWin version 1.9.1 (v1.9.3 has a write bug; does not work)
   ;*******************************************************************
   
    ;   Copy these include files to your project directory (i.e. they are in the same
    ;   directory with your .asm source file), if necessary

   #include "icdpictypes.inc"   ; Takes care of: #include "p18fxxx.inc",  max_flash, IdTypePIC
   #include "spbrgselect.inc"   ; RoundResult and baud_rate

   #define first_address (max_flash-264)      ;132 words (264bytes)
    ; for the above: You can NOT specify all kinds of sizes; 100, 132, 164, 196... (these worked for me)
    ; Adapt tinybld.ini (first close TinybldWin.exe) Set SizeOfBLD_W=132 or you used size
   __CONFIG   _CONFIG1H, _IESO_OFF_1H & _FCMEN_OFF_1H & _OSC_INTIO67_1H
   __CONFIG   _CONFIG2L, _BOREN_OFF_2L & _PWRT_ON_2L
   __CONFIG   _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H
   __CONFIG   _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_PORTBE_3H
   __CONFIG   _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _DEBUG_OFF_4L & _XINST_OFF_4L
    __CONFIG   _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L &_CP3_OFF_5L
   __CONFIG   _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
   __CONFIG   _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
   __CONFIG   _CONFIG6H, _WRTB_OFF_6H & _WRTC_OFF_6H & _WRTD_OFF_6H
   __CONFIG   _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L  & _EBTR2_OFF_7L  & _EBTR3_OFF_7L
   __CONFIG   _CONFIG7H, _EBTRB_OFF_7H
;----------------------------- PROGRAM ---------------------------------
   cblock 0
   crc
   i
   cnt1
   cnt2
   cnt3
   counter_hi
   counter_lo
   flag
   endc
   cblock 10
   buffer:64
   dummy4crc
   endc
   
SendL macro car
   movlw car
   movwf TXREG
   endm
   
;0000000000000000000000000 RESET 00000000000000000000000000

      ORG     0x0000
      GOTO    IntrareBootloader

;view with TabSize=4
;&&&&&&&&&&&&&&&&&&&&&&&   START     &&&&&&&&&&&&&&&&&&&&&&
;----------------------  Bootloader  ----------------------
;PC_flash:      C1h            U      H      L      x  ...  <64 bytes>   ...  crc   
;PC_eeprom:      C1h               40h   EEADR   EEDATA   0      crc               
;PC_cfg         C1h         U OR 80h   H      L      1      byte   crc
;PIC_response:      type `K`
   
   ORG first_address      ;space to deposit first 4 instr. of user prog.
   nop
   nop
   nop
   nop
   org first_address+8

IntrareBootloader

    movlw   b'01110000'     ;set intrc to 8mhz
   movwf   OSCCON
   bsf     OSCTUNE,6,0    ;enable 4x PLL
   btfss   OSCCON,2      ;wait 'til internal osc is stable
   GOTO    $-2

   movlw b'00100100'      ;Set serial port Tx Status reg.
    ; !! Warning b2: Hi-baudrate bit set; so what out for low buadrates !
   movwf TXSTA
   movlw spbrg_value
   movwf SPBRG            ;baudrate register low byte
    ; !! WHAT about SPBRGH ?????
   movlw b'10010000'
   movwf RCSTA            ;Set serial port Rx Status reg. Enable serial port and receiver
                     
   rcall Receive         ;go receive a byte by polling (with timeout)
   sublw 0xC1            ;substract 0x1C (Host computer should have send 0x1C)
   bnz way_to_exit         ;if result!=0 exit bootloader

   SendL IdTypePIC         ;acknowledge host computer by sending PIC type (1 character) (see macro def.)

MainLoop
   SendL 'K'            ; "-Everything OK, ready and waiting."
mainl
   clrf crc
   rcall Receive         ;Upper
   movwf TBLPTRU
   movwf flag            ;(for EEPROM and CFG cases)
   rcall Receive         ;Hi
   movwf TBLPTRH
   movwf EEADR            ;(for EEPROM case)
   rcall Receive         ;Lo
   movwf TBLPTRL
   movwf EEDATA         ;(for EEPROM case)

   rcall Receive         ;count
   movwf i
   incf i
   lfsr FSR0, (buffer-1)
rcvoct                  ;read 64+1 bytes
   movwf TABLAT         ;prepare for cfg; => store byte before crc
   rcall Receive
   movwf PREINC0
   decfsz i
   bra rcvoct
   
   tstfsz crc            ;check crc
   bra ziieroare
   btfss flag,6         ;is EEPROM data?
   bra noeeprom
   movlw b'00000100'      ;Setup eeprom
   rcall Write
   bra waitwre
noeeprom
   btfss flag,7         ;is CFG data?
   bra noconfig
   tblwt*               ;write TABLAT(byte before crc) to TBLPTR***
   movlw b'11000100'      ;Setup cfg
   rcall Write
   bra waitwre
noconfig
                     ;write
eraseloop
   movlw   b'10010100'      ;Setup erase
   rcall Write
   TBLRD*-               ;point to adr-1
   
writebigloop   
   movlw 8               ;8groups
   movwf counter_hi
   lfsr FSR0,buffer
writesloop
   movlw 8               ;8bytes = 4instr
   movwf counter_lo
writebyte
   movf POSTINC0,w         ;put 1 byte
   movwf TABLAT
   tblwt+*
   decfsz counter_lo
   bra writebyte
   
   movlw   b'10000100'      ;Setup writes
   rcall Write
   decfsz counter_hi
   bra writesloop
waitwre   
   btfsc EECON1,WR         ;for eeprom writes ->
   bra waitwre            ;-> do wait for finish!. PC are fast these days
   
   bcf EECON1,WREN         ;disable writes
   bra MainLoop
   
ziieroare               ;CRC failed
   SendL 'N'
   bra mainl
;==========procedures ================

;********* Write *********************
Write
   movwf EECON1         ;move w to EECON1 (control register memory acccess)
   movlw 0x55
   movwf EECON2         ;magic register writen with first 0x55 ->
   movlw 0xAA
   movwf EECON2         ; -> then 0xAA
   bsf EECON1,WR         ; initiate the write by setting b1
   nop                  ; why this nop??
   return

;********* Receive *********************
; Explanation:
; cnt1-cnt2-cnt3 makes up 24 bit timeout down-counter.
; The Receive function will timeout and exit the whole bootloader
; if it does not receive a byte withing this time
; cnt1 is loaded with a number made depending on the used clock frequency.
; this is done to make the delay befor the user app start more a less constant ~ 1sec.

Receive
   movlw xtal/1000000     ; compute the clock depenting part
   movwf cnt1            ; load cnt1 with xtal/1000000
rpt2                  
   clrf cnt2            ; clear cnt2
rpt3
   clrf cnt3            ; clear cnt3
rptc
   btfss PIR1,RCIF         ; test if byte received; if not ->
   bra notrcv              ; ->branch to notrcv
   movf RCREG,w         ;of byte received, store w
   addwf crc,f            ;and add w to current crc sum
   return
notrcv
   decfsz cnt3            ; cnt3--;  while (cnt3!=0) ->
   bra rptc            ; -> poll byte received again
   decfsz cnt2            ; cnt2--;  while (cnt2!=0) ->         
   bra rpt3                ; -> cnt3=0; poll byte received again  (I don't understand cnt3 is already 0, so can also do bre rptc ??)
   decfsz cnt1            ; cnt1--; if zero exit bootloader=, and branch to first-address. Here is the user app main vector located
   bra rpt2
way_to_exit
   bcf   RCSTA,   SPEN      ;deactivate UART
   bra first_address
;*************************************************************
; After reset
; Do not expect the memory to be zero,
; Do not expect registers to be initialised like in catalog.
END

Peter273
Guest







PostPosted: Mon Sep 03, 2007 12:31 pm     Reply with quote

Weird....

I recompiled the code using MPASM for use with 18F4620/18F4680 with minor modifications in the asm file (removed #fuses for instance, I personally like the use of the programmers features to modify fuses over "fixed" settings, and even WinPic has no probs with it for that matter).
Am using it at 19200baud on a 4680 (sometimes a 4620 since almost identical).
Tiny bootloader V1.93 worked flawless for me upto now from start.
Never had to cope with the "incrementing reset vector', but then I am not using it as a production programmer either.

Did have some things I had to take care of :
Low Voltage Programming disabled
ENHanced CPU instructions disabled
Watchdog disabled (but its value preset as I want it to be after enabling it by SWDTEN in my user-software to be loaded)
LPT1OSC hi power

Did also have to change the icdpictypes.inc though to add the 4680 (inserted a copy of the part of the 4620 for this).

Reading these posts now, I checked what MPASM made of the code (didn't really verify before, but I'm bit of unaware of 'deep' assembler since mainly using C or C++ platforms for several other purposes).
Just fiddled around some for what I thought fitted my purposes.

Saw that MPASM made 200byte code of what I did, fyi the .lst file ends with :
Code:

MEMORY USAGE MAP ('X' = Used,  '-' = Unused)
0000 : XXXX------------ ---------------- ---------------- ----------------
FF00 : ---------------- ---------------- ---------------- --------XXXXXXXX
FF40 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
FF80 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
FFC0 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXX----

All other memory blocks unused.
Program Memory Bytes Used:   200
Program Memory Bytes Free: 65336
MPASM  5.03                       18F4680.ASM   6-26-2007  23:28:15         PAGE 51

Errors   :     0
Warnings :     0 reported,     0 suppressed
Messages :     0 reported,     0 suppressed


The Tiny .ini fle has the line "SizeOfBLD_W=100" in it (I assume default ??), and no line "SizeOfBLD". Never modified it myself in that respect.

For your info I add the .asm file I compiled here:
Code:

radix DEC
LIST      P=18F4680   ; change also: Configure->SelectDevice from Mplab
xtal EQU 40000000      ; you may want to change: _XT_OSC_1H  _HS_OSC_1H  _HSPLL_OSC_1H
baud EQU 19200         ; the desired baud rate
delaytime EQU 1000000   ; for 40MHz: 1000000 gets about 1sec, for 20MHZ: 2000000 gets about 1sec
   ; The above 4 lines can be changed and buid a bootloader for the desired frequency (and PIC type)
   
;***********************************************************
   ;   Tiny Bootloader      18F series      Size=100words
   ;   [email protected]
   ;   http : / / w w w . etc.ugal.ro/cchiculita/software/picbootloader.htm
;***********************************************************
   

   #include "../inc/icdpictypes.inc"   ;takes care of: #include "p18fxxx.inc",  max_flash, IdTypePIC
   #include "../inc/spbrgselect.inc"   ; RoundResult and baud_rate

      #define first_address max_flash-200      ;100 words
   
   ;can we dump these ? winpic etc have the function of configuring all
;   __CONFIG _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
;   __CONFIG _CONFIG2L, _PWRT_OFF_2L & _BOREN_OFF_2L
;   __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_1_2H
;   __CONFIG _CONFIG3H, _MCLRE_ON_3H & _PBADEN_OFF_3H ;& _CCP2MX_PORTBE_3H not in 4680
;   __CONFIG _CONFIG4L, _DEBUG_OFF_4L & _LVP_OFF_4L & _STVREN_OFF_4L & _XINST_OFF_4L
;   __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L
;   __CONFIG _CONFIG5H, _CPB_OFF_5H
;   __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L
;   __CONFIG _CONFIG6H, _WRTB_OFF_6H & _WRTC_OFF_6H
;   __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L
;   __CONFIG _CONFIG7H, _EBTRB_OFF_7H & _DEVID1 & _IDLOC0


;----------------------------- PROGRAM ---------------------------------
   cblock 0
   crc
   i
   cnt1
   cnt2
   cnt3
   counter_hi
   counter_lo
   flag
   endc
   cblock 10
   buffer:64
   endc
   
SendL macro car
   movlw car
   movwf TXREG
   endm
   
;0000000000000000000000000 RESET 00000000000000000000000000

      ORG     0x0000
      GOTO    IntrareBootloader

;view with TabSize=4
;&&&&&&&&&&&&&&&&&&&&&&&   START     &&&&&&&&&&&&&&&&&&&&&&
;----------------------  Bootloader  ----------------------
;PC_flash:      C1h            U      H      L      x  ...  <64>   ...  crc   
;PC_eeprom:      C1h               40h   EEADR   EEDATA   0      crc               
;PC_cfg         C1h         U OR 80h   H      L      1      byte   crc
;PIC_response:      type `K`
   
   ORG first_address      ;space to deposit first 4 instr. of user prog.
   nop
   nop
   nop
   nop
   org first_address+8
IntrareBootloader
                     ;init serial port
   movlw b'00100100'
   movwf TXSTA
   movlw spbrg_value
   movwf SPBRG
   movlw b'10010000'
   movwf RCSTA
                     ;wait for computer
   rcall Receive         
   sublw 0xC1            ;Expect C1h
   bnz way_to_exit
   SendL IdTypePIC         ;send PIC type
MainLoop
   SendL 'K'            ; "-Everything OK, ready and waiting."
mainl
   clrf crc
   rcall Receive         ;Upper
   movwf TBLPTRU
      movwf flag         ;(for EEPROM and CFG cases)
   rcall Receive         ;Hi
   movwf TBLPTRH
      movwf EEADR         ;(for EEPROM case)
   rcall Receive         ;Lo
   movwf TBLPTRL
      movwf EEDATA      ;(for EEPROM case)

   rcall Receive         ;count
   movwf i
   incf i
   lfsr FSR0, (buffer-1)
rcvoct                  ;read 64+1 bytes
      movwf TABLAT      ;prepare for cfg; => store byte before crc
   rcall Receive
   movwf PREINC0
   decfsz i
   bra rcvoct
   
   tstfsz crc            ;check crc
   bra ziieroare
      btfss flag,6      ;is EEPROM data?
      bra noeeprom
      movlw b'00000100'   ;Setup eeprom
      rcall Write
      bra waitwre
noeeprom
      btfss flag,7      ;is CFG data?
      bra noconfig
      tblwt*            ;write TABLAT(byte before crc) to TBLPTR***
      movlw b'11000100'   ;Setup cfg
      rcall Write
      bra waitwre
noconfig
                     ;write
eraseloop
   movlw   b'10010100'      ; Setup erase
   rcall Write
   TBLRD*-               ; point to adr-1
   
writebigloop   
   movlw 8               ; 8groups
   movwf counter_hi
   lfsr FSR0,buffer
writesloop
   movlw 8               ; 8bytes = 4instr
   movwf counter_lo
writebyte
   movf POSTINC0,w         ; put 1 byte
   movwf TABLAT
   tblwt+*
   decfsz counter_lo
   bra writebyte
   
   movlw   b'10000100'      ; Setup writes
   rcall Write
   decfsz counter_hi
   bra writesloop
waitwre   
   ;btfsc EECON1,WR      ;for eeprom writes (wait to finish write)
   ;bra waitwre         ;no need: round trip time with PC bigger than 4ms
   
   bcf EECON1,WREN         ;disable writes
   bra MainLoop
   
ziieroare               ;CRC failed
   SendL 'N'
   bra mainl
    
;******** procedures ******************

Write
   movwf EECON1
   movlw 0x55
   movwf EECON2
   movlw 0xAA
   movwf EECON2
   bsf EECON1,WR         ;WRITE
   nop
   ;nop
   return


Receive
   movlw xtal/delaytime+1   ; for 20MHz => 11 => 1second delay
   movwf cnt1
rpt2                  
   clrf cnt2
rpt3
   clrf cnt3
rptc
      btfss PIR1,RCIF         ;test RX
      bra notrcv
       movf RCREG,w         ;return read data in W
       addwf crc,f            ;compute crc
      return
notrcv
   decfsz cnt3
   bra rptc
   decfsz cnt2
   bra rpt3
   decfsz cnt1
   bra rpt2
   ;timeout:
way_to_exit
   bcf   RCSTA,   SPEN         ; deactivate UART
   bra first_address
;**********************************************************
; After reset
; Do not expect the memory to be zero,
; Do not expect registers to be initialised like in catalog.
 END


Seems to get garbeled a bit while entering here, but you gurus will know what to take care of....

Never (upto now) had ANY kind of probs using this setup, usually (re)program about 16 devices in a row (updating).
And I can imagine some of you gurus to shake their heads for using 200 bytes instead of the promised 100... but I'm not really in a cramped space since I only use about 78% of program flash and an ampel 38% of RAM, so I really don't care for 100bytes more or less in my app.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group