|
|
View previous topic :: View next topic |
Author |
Message |
Mr ? Guest
|
How to modify CCS bootloader to compatible with 16f883/886? |
Posted: Tue Feb 12, 2008 1:05 am |
|
|
Any materials on how to make or modify a bootloader for a 16f883 or 886 chip? I can't find existing bootloaders which support this both chips, even tinyBL. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Feb 12, 2008 6:50 am |
|
|
At a quick glance the write procedure for the PIC16F883 or 886 only differs at details from most other PIC16 processors.
What makes you think the CCS bootloader is not compatible with the PIC16F883 or 886? One of the great features of the CCS compiler is that it provides generic wrapper functions for accessing the hardware, for example for reading and writing to Flash memory. I haven't heard of any problems these functions not supporting the PIC16F883 or 886. |
|
|
Mr ? Guest
|
|
Posted: Wed Feb 13, 2008 9:16 pm |
|
|
Quote: |
#include <16F883.h>
#device *=16
#use delay(CLOCK=8000000)
#use rs232(baud=9600, XMIT= PIN_C6, RCV= PIN_C7) // rs232 setting
#use i2c(Slave,sda=PIN_C4,scl=PIN_C3,address=0x60,force_hw)
#fuses INTRC_IO
#fuses NOWDT,NOMCLR,NOPROTECT,NOBROWNOUT,NOFCMEN,NOIESO,NOCPD
#define LOADER_END 0x1FF
#define LOADER_SIZE 0x1BF
#define LOADER_ADDR LOADER_END-LOADER_SIZE
#define BUFFER_LEN_LOD 64
int buffidx;
char buffer[BUFFER_LEN_LOD];
#define ACKLOD 0x06
#define XON 0x11
#define XOFF 0x13
#SEPARATE
unsigned int atoi_b16(char *s);
#ORG LOADER_ADDR+10, LOADER_END auto=0 default
void real_load_program (void)
{
int1 do_ACKLOD, done=FALSE;
int8 checksum, line_type;
int16 l_addr,h_addr=0;
int32 addr;
#if getenv("FLASH_ERASE_SIZE")>2
int32 next_addr;
#endif
int8 dataidx, i, count;
int8 data[32];
while (!done) // Loop until the entire program is downloaded
{
buffidx = 0; // Read into the buffer until 0x0D ('\r') is received or the buffer is full
do {
buffer[buffidx] = getc();
} while ( (buffer[buffidx++] != 0x0D) && (buffidx <= BUFFER_LEN_LOD) );
putchar (XOFF); // Suspend sender
do_ACKLOD = TRUE;
// Only process data blocks that start with ':'
if (buffer[0] == ':') {
count = atoi_b16 (&buffer[1]); // Get the number of bytes from the buffer
// Get the lower 16 bits of address
l_addr = make16(atoi_b16(&buffer[3]),atoi_b16(&buffer[5]));
line_type = atoi_b16 (&buffer[7]);
addr = make32(h_addr,l_addr);
#if defined(__PCM__) // PIC16 uses word addresses
addr /= 2;
#endif
// If the line type is 1, then data is done being sent
if (line_type == 1) {
done = TRUE;
#if defined(__PCM__)
} else if ((addr <LOADER_ADDR> LOADER_END) && addr < 0x2000){
#elif defined(__PCH__)
} else if ((addr <LOADER_ADDR> LOADER_END) && addr < 0x300000){
#endif
checksum = 0; // Sum the bytes to find the check sum value
for (i=1; i<(buffidx-3); i+=2)
checksum += atoi_b16 (&buffer[i]);
checksum = 0xFF - checksum + 1;
if (checksum != atoi_b16 (&buffer[buffidx-3]))
do_ACKLOD = FALSE;
else {
if (line_type == 0) {
// Loops through all of the data and stores it in data
// The last 2 bytes are the check sum, hence buffidx-3
for (i = 9,dataidx=0; i <buffidx> getenv("FLASH_WRITE_SIZE")
#if defined(__PCM__)
if ((addr!=next_addr)&&(addr&(getenv("FLASH_ERASE_SIZE")-1)!=0))
#else
if ((addr!=next_addr)&&(addr&(getenv("FLASH_ERASE_SIZE")/2-1)!=0))
#endif
erase_program_eeprom(addr);
next_addr = addr + 1;
#endif
write_program_memory(addr, data, count);
}
else if (line_type == 4)
h_addr = make16(atoi_b16(&buffer[9]), atoi_b16(&buffer[11]));
}
}
}
if (do_ACKLOD)
putchar (ACKLOD);
putchar(XON);
}
putchar (ACKLOD);
putchar(XON);
#ifndef _bootloader
reset_cpu();
#endif
}
unsigned int atoi_b16(char *s) { // Convert two hex characters to a int8
unsigned int result = 0;
int i;
for (i=0; i<2>= 'A')
result = 16*result + (*s) - 'A' + 10;
else
result = 16*result + (*s) - '0';
}
return(result);
}
#ORG default
#ORG LOADER_ADDR, LOADER_ADDR+9
void load_program(void)
{
real_load_program();
}
void main()
{
setup_oscillator( OSC_8MHZ );
// Clears out the rs232 buffer
//delay_ms (1000);
while (kbhit())
{
getc();
}
// Loop until 'L' is pressed
do
{
printf("Press L to download new software.\r\n");
} while (getc() != 'L');
// Let the user know it is ready to accept a download
printf("\r\nWaiting for download...");
// Load the program
load_program();
}
|
Which part should I change to make it work?
I already change the #include header file. |
|
|
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
|
Posted: Thu Mar 24, 2011 3:20 pm |
|
|
Hey Mr ? - Did you figure out how to get a bootloader for the 16F883 going? I've been playing around with it for a while but no success... :(
Do you have a solution you can share?
Thanks,
Ron |
|
|
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
|
Posted: Fri Mar 25, 2011 3:04 pm |
|
|
User Zilym from the Microchip forum posted an archive containing his version of a 16F883 bootloader which I used and worked fine. The link to the thread for future reference: http://www.microchip.com/forums/m347843.aspx |
|
|
|
|
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
|