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

AN1310 High-Speed Bootloader for PIC16 and PIC18 with CCS

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



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

AN1310 High-Speed Bootloader for PIC16 and PIC18 with CCS
PostPosted: Wed Jul 07, 2010 3:31 pm     Reply with quote

Hi, I'm trying to use the AN1310
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en546974
High-Speed Bootloader but with the CCS compiler. Someone could tell
me if has had this experience and how to relocate user code?
kthomas



Joined: 06 Jul 2010
Posts: 5

View user's profile Send private message

PostPosted: Wed Jul 07, 2010 5:55 pm     Reply with quote

I'm not familiar with that bootloader, but I've used the following to locate a bootloader at the top of memory on a dsPIC, with the application below. In this case the bootloader and application are two separate entities.


In the application:
Code:
    #ORG start, end {} // reserves space for the bootloader
    #ORG( end+5, getenv("PROGRAM_MEMORY")-1 ) default  // puts the code following this from the end of the bootloader thru the end of program memory


In the bootloader:
Code:
 #ORG start, end auto=0 default // tells the compiler to put all of the bootloader code in the designated range


Where start is the beginning of program memory and end is the end of your bootloader.
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Fri Jul 09, 2010 10:30 am     Reply with quote

Hi, I've been using a Bootloader to PIC18F4550 and I just needed to put this code the begin of my code!!!:
Code:
/********************************************************************************/
/*      BootLoader Activo                                              */
/********************************************************************************/
 #build(reset=0x800)
 #build(interrupt=0x808)
 #org 0x0000,0x07ff
 void bootloader() {
 #asm
 nop
 #endasm
}


But now I want to use this new AN1310 Bootloader with a PIC18F452 and I can not understand how to remap the code of my application.

Here is the code of my aplication:

Code:
#include <p18f452.h>
#pragma config OSC = HS, PWRT = ON, BOR = OFF, BORV = 27,WDT = OFF, STVR = OFF,LVP = OFF
#include <stdio.h>
#include <usart.h>

// BAUDRG is calculated as  = Fosc / (4 * Desired Baudrate) - 1

#define BAUDRG 86                   //  20MHz


void high_isr(void);
void low_isr (void);

#pragma code AppHighIntVector = 0x0008  // hardware high priority interrupt vector address
void AppHighIntVector(void)
{
    _asm GOTO high_isr _endasm          // branch to the high_isr() function to handle priority interrupts.
}

#pragma code AppLowIntVector = 0x0018   // hardware low priority interrupt vector address
void low_vector(void)
{
  _asm GOTO low_isr _endasm             // branch to the low_isr() function to handle priority interrupts.
}

#pragma code                            // return to the default code section

#pragma interrupt high_isr
void high_isr(void)
{
    LATDbits.LATD1 ^= 1;    // blink LED
    PIR1bits.TMR1IF = 0;    // clear Timer 1 interrupt flag
}

#pragma interruptlow low_isr
void low_isr(void)
{
    if(PIR1bits.RCIF)
    {
#ifdef INVERT_UART
        if(RCSTAbits.FERR && PORTCbits.RC7)
#else
        if(RCSTAbits.FERR && !PORTCbits.RC7)
#endif
        {
            // receiving BREAK state, soft reboot into Bootloader mode.
            Reset();
        }
        TXREG = RCREG;          // echo received UART character back out
        LATD ^= 0xF0;
    }

    if(INTCONbits.TMR0IF)
    {
        LATDbits.LATD0 ^= 1;    // blink LED
        INTCONbits.TMR0IF = 0;  // clear Timer 0 interrupt flag
    }
}

unsigned int brg;
void main()
{
   
#ifdef INVERT_UART
    LATCbits.LATC6 = 0;         // drive TXD pin low for RS-232 IDLE state
#else
    LATCbits.LATC6 = 1;         // drive TXD pin high for RS-232 IDLE state
#endif
    TRISCbits.TRISC6 = 0;

    if(!RCONbits.POR)
    {
        // Power On Reset occurred, bootloader did not capture an autobaud BRG value.
        brg = 0;
        RCONbits.POR = 1;       // flag that future MCLR/soft resets are not POR resets
    }
   
    TMR0H = 0;
    TMR0L = 0;
    T0CON = 0b00010110;
    INTCONbits.TMR0IF = 0;
    INTCONbits.TMR0IE = 1;
    INTCON2bits.TMR0IP = 0;

    TMR1H = 0;
    TMR1L = 0;
    T1CON = 0b00110111;
    T1CONbits.TMR1CS = 0;       // internal clock source (Fosc/4)
    PIR1bits.TMR1IF = 0;
    PIE1bits.TMR1IE = 1;
    IPR1bits.TMR1IP = 1;        // Timer 1 as High Priority interrupt
    RCONbits.IPEN = 1;          // enable interrupt priority
    INTCONbits.GIEH = 1;
    INTCONbits.GIEL = 1;

    LATD = 0;                   // turn off LEDs
    TRISD = 0;                  // enable PORTD LED outputs

    // wait for stable clock and host connection by waiting for first Timer 0 interrupt
    T0CONbits.TMR0ON = 1;       
    while(!LATDbits.LATD0);

    if(brg != 0)
    {
        printf( (far rom char*) "Bootloader BRG: %u\r\n", brg);
    }
    printf( (far rom char*) "\r\nHello world from PIC microcontroller!\r\n");
   
    // infinite loop, interrupts will blink PORTD pins and handle UART communications.
    while(1)
    {
    }
}

someone could give me a hand with this?
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