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 support@ccsinfo.com

TinyBootloader issues with P18F46K80

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



Joined: 10 Jan 2014
Posts: 22

View user's profile Send private message

TinyBootloader issues with P18F46K80
PostPosted: Fri Feb 14, 2014 1:25 am     Reply with quote

Hello everybody,

I've already try the "TinyBootloader" solution with a 18F46K20 and I had been really satsified by it. But I have used a precompiled hex file for this microcontroller and I did'nt have no problem to use it so.
Now I'm trying to do the same with a 18F46K80 microcontroller, but I don't have the precompiled hex file. So I decided to modify and reuse an asm file given for a similar microcontroller, the 18F6621, because of its flash memory size (64k).
But just modifiying :

Code:

LIST      P=18F46K80
        xtal EQU 8000000
        baud EQU 9600
        delaytime EQU 2000000

        #include <p18f46k80.inc>


IdTypePIC = 0x4B
#define max_flash 0x10000
#include "C:/Users/Greg/Documents/Projets MPLAB/try2.X/inc/spbrgselect.inc"



#define first_address max_flash-200



CONFIG XINST = OFF, FOSC = HS1, PLLCFG = OFF, WDTEN = OFF




My microcontroller is clocked by an external quartz oscillator ( 8Mhz). I use mpasm 5.53 as compiler, and because of it, I must use "the Extended Instruction Set" fuse to off to disable it. Is it because of that my microcontroller doesn't respond to the software ? Because it's my problem, I don't have any answer from the microcontroller when I check PIC or even when I try to program it. My hardware RS232 serial communication works well, I've test it with an other code. So my problem comes from my "tiny" hex file, but I really don't know why. I don't really know asm language, that's why my knowledge is limited on this kind of problem. I also attach my full asm file if you want to check it completly.
If someone have any idea on how to fix my problem or where the problem is...
Thank you,
Greg


Here is the full code:

Code:

   radix DEC
   LIST      P=18F46K80
xtal EQU 8000000
baud EQU 9600
delaytime EQU 2000000

   ;********************************************************************
   ;   Tiny Bootloader      18F series      Size=100words
   ;   claudiu.chiculita@ugal.ro
   ;   http://www.etc.ugal.ro/cchiculita/software/picbootloader.htm
   ;********************************************************************

      #include <p18f46k80.inc>
;IdTypePIC same as 18F6621 because of his flash memeory size (64k)
IdTypePIC = 0x4B
      #define max_flash 0x10000
#include "C:/Users/Greg/Documents/Projets MPLAB/try2.X/inc/spbrgselect.inc"   ; RoundResult and baud_rate

      #define first_address max_flash-200      ;100 words

      ;CONFIG   _CONFIG1H, _OSCS_OFF_1H & _OSC_HSPLL_1H
      ;CONFIG   _CONFIG2L, _BOR_ON_2L & _BORV_20_2L & _PWRT_ON_2L
      ;CONFIG   _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H
      ;CONFIG   _CONFIG4L, _STVR_ON_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
        CONFIG XINST = OFF, FOSC = HS1, PLLCFG = OFF, WDTEN = OFF

;----------------------------- 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
                     ;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/2000000+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

Ttelmah



Joined: 11 Mar 2010
Posts: 19383

View user's profile Send private message

PostPosted: Fri Feb 14, 2014 2:21 am     Reply with quote

Hint,

_Wrong Forum_

This is a forum for 'CCS C'. Not for MPASM, or for Tiny Bootloader....

Ask in a forum for one of these.....
baklou



Joined: 10 Jan 2014
Posts: 22

View user's profile Send private message

PostPosted: Fri Feb 14, 2014 2:40 am     Reply with quote

However, I saw these olders posts ....:

http://www.ccsinfo.com/forum/viewtopic.php?t=38204

https://www.ccsinfo.com/forum/viewtopic.php?p=121068

http://www.ccsinfo.com/forum/viewtopic.php?t=39700

https://www.ccsinfo.com/forum/viewtopic.php?p=121618

https://www.ccsinfo.com/forum/viewtopic.php?p=123372

...

and many mores.

That's why I was thinking someone could help me here...

I already added the same post on the microchip forum, and mailed Claudiu Chiculita, the Tinybooloader developper.

Thank you for welcoming me so "kindly"...

Regards, Greg
temtronic



Joined: 01 Jul 2010
Posts: 9178
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Feb 14, 2014 8:22 am     Reply with quote

Well, this is a C forum, not Assembler, so I understand Mr. T's comments.
One problem with that assembler code is that not every line is commented! That makes it very difficult for anyone to 'think' like the original programmer, in order to follow his way of coding. Odds are pretty good there's only a handful here who understand asm (though it's not that hard) and there are several bootloaders written in CCS C.
If you want to use that code, you'll have to wait for a reply from the author. He's the best bet.
Since you've gotten it to work with another PIC, I suggest you compare PICs and see what's different about them. Memory maps would be an obvious area, location of registers, etc. A 'side by side' comparision would be helpful.
Also, is your target PIC running? Could be a 'fuse' issue, so be sure the '1Hz LED' program runs before you try the bootloader!

hth
jay
baklou



Joined: 10 Jan 2014
Posts: 22

View user's profile Send private message

PostPosted: Mon Feb 17, 2014 1:51 am     Reply with quote

Ok, I understand well what are you meaning. You're right about the "side by side" comparision and analysis.
My PIC is working well, I already check it.

Thank you for your answer.

Greg
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