Made a little more progress, also fixed some thing in what I already had. Any questions, comments, or suggestions ask away!
Code:' ***************************************************************************** ' Software License Agreement ' ' The software supplied herewith by PBP forum members ' (the “Company”) for Microchip's PICmicro® Microcontroller's is ' intended and supplied to you, the Company’s customer, for use ' solely and exclusively on Microchip PICmicro Microcontroller ' products. The software is owned by the Company and/or its ' supplier, and is protected under applicable copyright laws. All ' rights are reserved. Any use in violation of the foregoing ' restrictions may subject the user to criminal sanctions under ' applicable laws, as well as to civil liability for the breach of ' the terms and conditions of this license. ' ' THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, ' WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED ' TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A ' PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, ' IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR ' CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. ' ' ' This software has been ported from Microchip's AN851 bootloader ' Changes have been made and will be made as the company sees fit. ' This version is for 16F's, there is another version for 18F's ' ' ' Memory Map ' ----------------- ' | 0x0000 | Reset vector ' | | ' | 0x0004 | Interrupt vector ' | | ' | | ' |Boot Block | (this program) ' | | ' | 0x0200 | Re-mapped Reset Vector ' | 0x0204 | Re-mapped High Priority Interrupt Vector ' | | ' | | ' | | ' |Code Space | User program space ' | | ' | | ' | | ' | 0x3FFF | ' ----------------- ' ' Incomming data format: ' ' {STX}{STX}{DATA}{CHKSUM}{ETX} ' / \ ' ________/ \__________________________ ' / \ ' {COMMAND}{DLEN}{ADDRL}{ADDRH}{ADDRU}{DATA}... ' ' Definitions: ' ' STX - Start of packet indicator ' ETX - End of packet indicator ' LEN - Length of incomming packet ' DATA - General data up to 255 bytes ' CHKSUM - The 8-bit two's compliment sum of LEN & DATA ' COMMAND - Base command ' DLEN - Length of data associated to the command ' ADDR - Address up to 24 bits ' DATA - Data (if any) ' ' ' Commands: ' ' RD_VER 00 Read Version Information ' RD_MEM 01 Read Program Memory ' WR_MEM 02 Write Program Memory ' ER_MEM 03 Erase Program Memory (NOT supported by PIC16) ' RD_EE 04 Read EEDATA Memory ' WR_EE 05 Write EEDATA Memory ' RD_CONFIG 06 Read Config Memory (NOT supported by PIC16) ' WT_CONFIG 07 Write Config Memory (NOT supported by PIC16) ' ' **************************************************************************** ' ***************************************************************************** CHKSUM VAR BYTE ' Checksum accumulator COUNTER VAR BYTE ' General counter ABTIME VAR BYTE RXDATA VAR BYTE TXDATA VAR BYTE TEMP VAR BYTE ARRAYPOINTER VAR BYTE TEMPFLAG VAR BIT PCLATH_TEMP VAR BYTE ' Interrupt context STATUS_TEMP VAR BYTE ' save/restore registers W_TEMP VAR BYTE ' Frame Format ' ' {STX}{STX}[{COMMAND}{DATALEN}{ADDRL}{ADDRH}{ADDRU}{...DATA...}]{CHKSUM}{ETX} DATA_BUFF VAR BYTE[50] ' Start of receive buffer SAME ADDRESS AS COMMAND COMMAND VAR DATA_BUFF[0] ' Data mapped in receive buffer SAME ADDRESS AS DATA_BYTE DATA_COUNT VAR DATA_BUFF[1] ADDRESS_L VAR DATA_BUFF[2] ADDRESS_H VAR DATA_BUFF[3] ADDRESS_U VAR DATA_BUFF[4] 'PACKET_DATA VAR DATA_BUFF[5-49] 'Maybe we don't need this line?************** ' ***************************************************************************** ' This is the remapping section, note the interrupt also saves context ' ***************************************************************************** @ ORG 0x0000 ' Re-map Reset vector **Not sure how to set the address to start at VReset: PCLATH = 0 goto Setup @ ORG 0x0004 'standard interrupt vector **again not sure of the PBP equal for ORG VInt: W_TEMP = W 'I am assuming this will be the "W" register STATUS_TEMP = STATUS 'We may have trouble here. ASM uses SWAP so as not to affect the status STATUS = 0 PCLATH_TEMP = PCLATH PCLATH = 0 goto RVInt ' Re-map Interrupt vector ' ***************************************************************************** ***************************************************************************** ' Setup the appropriate registers. Setup: clrwdt READ $ff,temp 'get the value of last EEPROM location IF temp = $ff then goto SRX 'BL startup goto RVReset ' If not 0xFF then normal reset SRX: RCSTA = %10000000 ' Setup rx and tx, CREN disabled TRISC.6 = 0 ' Setup tx pin TXSTA = %00100110 STATUS.IRP = 1 ' ***************************************************************************** ' ***************************************************************************** Autobaud: ' ' ___ __________ ________ ' \__/ \__________/ ' | | ' |-------- p ----------| ' ' p = The number of instructions between the first and last ' rising edge of the RS232 control sequence 0x0F. Other ' possible control sequences are 0x01, 0x03, 0x07, 0x1F, ' 0x3F, 0x7F. ' ' SPBRG = (p / 32) - 1 BRGH = 1 OPTION_REG = %00000011 'sets tmr0 to 1:16 prescale STATUS.RP0 = 0 RCSTA.CREN = 0 gosub WaitForRise TMR0 = 0 ' Start counting gosub WaitForRise ABTIME = TMR0 ' Read the timer TEMPFLAG = ABTIME.0 ABTIME = ABTIME >>1 IF !TEMPFLAG THEN ABTIME.0 = 0 'Rounding SPBRG = ABTIME RCSTA.CREN = 1 ' Enable receive TEMP = RCREG ' To clear the Rx buffer TEMP = RCREG ' Both of them OPTION_REG = %11111111 'Return Option Reg to reset state ' ***************************************************************************** ' ***************************************************************************** ' Read and parse the data. StartOfLine: GOSUB RdRS232 ' Look for a start of line IF RXDATA != STX THEN Autobaud '{STX}{STX} ARRAYPOINTER = 0 ' Point to the beginning of Array CHKSUM = 0 ' Reset checksum GetNextDat: GOSUB RdRS232 ' Get the data IF RXDATA = STX THEN StartOfLine ' Check for a STX ' Yes, start over NoSTX: IF RXDATA = ETX THEN CheckSum ' Check for a ETX ' Yes, examine checksum NoETX: IF RXDATA = DLE THEN GOSUB RdRS232 ' Check for a DLE ' Yes, Get the next byte NoDLE: DATA_BUFF[ARRAYPOINTER] = RXDATA ' Store the data CHKSUM = CHKSUM + RXDATA ' Get sum ARRAYPOINTER = ARRAYPOINTER + 1 goto GetNextDat CheckSum: IF CHKSUM = 0 THEN Autobaud ' Checksum test ' ***********************************************




Bookmarks