Troubles with bootloader on PIC16F1847

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
Jack Flanders
Posts: 337
Joined: 17 Apr 2008 02:53
Location: Fantasy Land

Troubles with bootloader on PIC16F1847

#1 Post by Jack Flanders » 26 Nov 2013 03:20

I'm trying to use the bootloader from the compiler example folder for PIC16's. It works as advertised on a PIC16F887 - no problems. But not so well on a PIC16F1847 which has the same size program memory. It appears to work until actually used and then it appears to overwrite the first locations in memory. Here's my experimental data if anyone has an idea:

Columns below are:
Line,Address,Opcode hex, Opcode ASM, <params>

1847 virgin bootloader first memory locations:
1 0000 3198 MOVLP 0x18
2 0001 2D98 GOTO 0x598

This is as expected for this source code:

Code: Select all

program boot16
include BootForAll16

main: org 0x1D98    ' org main
  orgall(0x1D98)    ' store bootloader code at the end of program memory
After compiling the bootloader and programming the PIC16F1847 and then downloading with the mikroelektronika bootloader tool, the memory looks like this:

1 0000 1008 BCF 0x8, 0
2 0001 0588 ANDWF 0x8, F
3 0002 2D98 GOTO 0x598
< from here, the target program code is placed>

Register #8 is the BSR: Bank Select Register. Why is the BSR getting adjusted just prior to a jump into far memory? And since the PCLATH reg is zero at reset, the program appears to jump to 0x598, no where near 0x1D98.

How are the first two instructions getting changed after using the bootloader?

I ask because at this point, neither the downloaded code works nor does the bootloader any longer. At reset, there is no string of 'ggggggggg...' coming out of the uart. Ideas, anyone?

:o :( :shock: :?

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: Troubles with bootloader on PIC16F1847

#2 Post by janni » 26 Nov 2013 14:35

Jack Flanders wrote:How are the first two instructions getting changed after using the bootloader?
Bootloader to work has to change the jump-to-main address of the original code. Problem is, for different processor families it has to be managed differently. PIC16s require different assembly instructions than enhanced PICs (even the number of instructions differs). Best take a look at this bootloader published at Libstock.

Jack Flanders
Posts: 337
Joined: 17 Apr 2008 02:53
Location: Fantasy Land

Re: Troubles with bootloader on PIC16F1847

#3 Post by Jack Flanders » 26 Nov 2013 17:27

Thanks Janni! I'll try that today.

Jack Flanders
Posts: 337
Joined: 17 Apr 2008 02:53
Location: Fantasy Land

Re: Troubles with bootloader on PIC16F1847

#4 Post by Jack Flanders » 27 Nov 2013 01:57

Ok, I now have the Libstock program Janni pointed to programmed in and running. Thanks Janni! :D

Haven
Posts: 40
Joined: 18 Mar 2017 21:20
Location: South Africa
Contact:

Re: Troubles with bootloader on PIC16F1847

#5 Post by Haven » 30 Jul 2021 11:46

Hi Jack,

I hope you are well?

I also need to get the boot loading for the pic16F1847 working, and so was wondering if you could share what you changed to the https://libstock.mikroe.com/projects/vi ... loader-16e project working as I see its for a PIC16F1938 . . .

I have tried the mikroe sample code, and while it sort of works the BL never starts and times out. So, I am sure its a configuration problem, I am not sure what to fix,'

Thankyou
Michael A Havenga
HavenTechnik | SP
WEB: http://www.haventechnik.com
twitter: @HavenTechnik

Haven
Posts: 40
Joined: 18 Mar 2017 21:20
Location: South Africa
Contact:

Re: Troubles with bootloader on PIC16F1847

#6 Post by Haven » 17 Aug 2021 23:47

Hi Guys,

I have been able to solve one of the issues that I mentioned. In this routine, which sets the comports, you also need to clear the ANALOGS, as I have done by clearing the ANSELB register. What this change is that the bootloading process proceeds and completes, where before it would just hang and then time out. The problem now is that the code will run once after the device is bootloaded but is a bit erratic, and then once you restart the device it stops working.

I did do a blank check, and the device is not blank so it's not as though the bootloading process erased the memory.

void Susart_Init(unsigned short brg_reg) org 0x1DCF {
unsigned short i;

RCSTA = 0x90;
TXSTA = 0x26;
//TRISC.B7 = 1;
//TRISC.B6 = 0;
ANSELB = 0x0; < - new change
TRISB.B1=1;
TRISB.B2=0;

while (PIR1.RCIF)
i = RCREG;

SPBRG = brg_reg;
}

Any help would be appreciated . . .
Michael A Havenga
HavenTechnik | SP
WEB: http://www.haventechnik.com
twitter: @HavenTechnik

Post Reply

Return to “mikroBasic PRO for PIC General”