Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Software Development System Installation (http://www.chiefdelphi.com/forums/showthread.php?t=32522)

Mike Betts 11-01-2005 09:02

Software Development System Installation
 
There have been numerous threads and posts concerning the new MPLAB, C18 compiler and problems with compiling default code. The purpose of this post/thread is to document my journey…

First of all, I am running XP home SP2 with the firewall ON in its default configuration. I am also running AVG 7.03 resident shield and Spybot 1.3 with inoculations resident.

First, I uninstalled old versions of MPLAB, C18 and IFI Loader, in that order. Uninstall of C18 was notable in that XP reported that C18 was already uninstalled and asked me if I wanted the icons removed. I said yes and moved on…

I downloaded the full version of MPLAB 7.00 from Microchip. I also downloaded C18 2.40 (via the FIRST link). I also downloaded IFI Loader 1.0.10 from IFI. Note that I did not use any files from the CDROM included in the 2005 kit.

I performed a full install of MPLAB 7.00 and answered NO to installation of ICD and ICE support. No issues.

I then performed a full install of C18 2.40 with, apparently, no issues. During the install, I checked all boxes involving the addition of C18 to my PATH, et cetera.

After the C18 install, XP complained "Application Has Failed to Start Because Framedyn.dll Was Not Found" when I started Spybot. I reinstalled Spybot which had no effect.

After reviewing information at http://support.microsoft.com/default.aspx?scid=kb;en-us;319114, I verified that framedyn.dll was not corrupted. However, I did find a problem in my PATH.

I corrected by PATH to be: C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32 \wbem;C:\mcc18\mpasm;C:\mcc18\bin;<and more PATH variables not relevant to FIRST> and that problem went away.

The IFI Loader installation went uneventfully except for it complaining that there were shared files in use. I told it to continue and the rest of the installation was normal.

Whew!

After all of that, I was able to build Team 177’s 2004 robot code, FRC’s 2005 default code, Kevin Watson’s 2005 navigation demonstration code and FRC’s 2005 camera code with no errors.

I will not be able to test on a robot until this afternoon. If I have problems, I’ll let everyone know…

I hope this information saves some of you some grief and frustration. Please feel free to post your experiences.

Regards,

Mike

P.S.: Moderator, please make this thread a sticky for the next week or two… Thanks.

Joe Ross 11-01-2005 09:37

Re: Software Development System Installation
 
Somebody else reported on FIRST Q/A that the new compiler corrupted the PATH environment variable on XP (ID967).

This is definitely something people need to watch out for.

Greg Marra 11-01-2005 10:10

Re: Software Development System Installation
 
XP Home SP1

I uninstalled the old versions of MPLAB and C18. However the C18 icon did not go away in the add/remove programs list, but further attempts to remove only told me it couldn't find it. This happens with some uninstallers, so I ignored it.

Then I rebooted.

Then I installed MPLAB 7.0, which went smoothly. Without rebooting I installed C18 2.4, checking all 6 of the check boxes when prompted, which also went smoothly. I then rebooted.

On boot my optical mouse didn't work, it was all lit up but wouldn't move the cursor. I rebooted and the same thing. Unplugging and replugging the mouse at the Welcome Screen fixed it.

Everything seems to be working perfectly.

Terry Sherman 11-01-2005 20:57

Re: Software Development System Installation
 
We've installed IFI Loader 1.0.10 and attempted to download the new FRC_2005 default code. It says that it loads but the LED on thr controller that describes program failure/fault blinks. We tried the same 2005 FRC Default code with the 1.0.2 IFI Loader and it loaded and ran correctly. We also updated the Main FRX code (*.bin file) from Innovation First.

Has anyone else seen this issue?
Thanks!

Mike Betts 11-01-2005 21:03

Re: Software Development System Installation
 
Quote:

Originally Posted by Terry Sherman
We've installed IFI Loader 1.0.10 and attempted to download the new FRC_2005 default code. It says that it loads but the LED on thr controller that describes program failure/fault blinks. We tried the same 2005 FRC Default code with the 1.0.2 IFI Loader and it loaded and ran correctly. We also updated the Main FRX code (*.bin file) from Innovation First.

Has anyone else seen this issue?
Thanks!

I would most definately post this to IFI: http://www.ifirobotics.com/forum/

CJO 11-01-2005 21:08

Re: Software Development System Installation
 
I think that these *may* be SP2 problems. I have setup the whole system on three SP1 machines running Pro, and had no problem, however, I am using a multipurpose loader/diagnostics tool that one of the IFI guys gave us at the nationals last year instead of the IFI loader.

DanDon 11-01-2005 21:45

Re: Software Development System Installation
 
Quote:

Originally Posted by CJO
I think that these *may* be SP2 problems. I have setup the whole system on three SP1 machines running Pro, and had no problem, however, I am using a multipurpose loader/diagnostics tool that one of the IFI guys gave us at the nationals last year instead of the IFI loader.

Hey CJO, is there any way you can upload that "multipurpose loader/diagnostics tool"?

I would much appreciate it,

Thanks,

Dan

CJO 11-01-2005 22:02

Re: Software Development System Installation
 
It is on a machine at school, but I'll try tomorrow. The real beauty of it (and the reason we got it) is it allows you to read programs out of the memory . . . so, if you forget to backup beofre you re-compile, and you are in the middle of a match, you can always restore back to where you were.

devicenull 11-01-2005 22:37

Re: Software Development System Installation
 
Quote:

Originally Posted by CJO
It is on a machine at school, but I'll try tomorrow. The real beauty of it (and the reason we got it) is it allows you to read programs out of the memory . . . so, if you forget to backup beofre you re-compile, and you are in the middle of a match, you can always restore back to where you were.

Send me a PM if you need somewhere to upload it

CJO 11-01-2005 22:40

Re: Software Development System Installation
 
Actually, I think I have it here, it is in a backup file, so, as soon as I finish restoring that particular disc, i'll post.

CJO 12-01-2005 00:40

Re: Software Development System Installation
 
I found the source, I cannot find an .exe so I am compiling, will post later.

CJO 12-01-2005 00:51

Re: Software Development System Installation
 
1 Attachment(s)
Ok, here you go,

un-tar and run.

USE AT YOUR OWN RISK

I'll post the source tomorrow. I also have source for the PIC18 firmware uploader, I am building that right now. I just put out the exe, I do not think that you will need any other files if you are running XP pro full install, I have tried it out on one machine. If it is the case that I am missing .dll's etc, I post, and I will include them. IFI loader should install all neccessary files.

Also, DO NOT HIT THE RUN BUTTON

CJO 12-01-2005 10:44

Re: Software Development System Installation
 
Ok, upon the advice of a couple of people I have decided not to post the bootstrap, firmware uploader, etc. because as someone put it "it is too much like leaving a loaded gun lying around." Also it is big. If anyone wants source/the other stuff, PM and I will e-mail you a link.

devicenull 15-01-2005 20:29

Re: Software Development System Installation
 
Just a question, is there a helpfile for this anywhere?
Wondering what:

RD PRG and RD EE do, BLK ERASE, will that wipe the program code or _everything_


Also, whats going to happen if I hit the run button? If its going to screw stuff up, I'm taking the button out with resource editor

russell 15-01-2005 22:17

Re: Software Development System Installation
 
I too am having issues with MPLAB. At school when we tried to install v 7.00 on our laptop it flashed up a bunch of error messages right as it finished the install, so I just hit ok on all of them, then tried to run it. It flashed up another error message, but we had to leave then. Another guy took the laptop home and is trying everything he can think of to get it to work, but he is currently installing it for the third time and it still isnt working. So meanwhile I came home to try to compile the rev-3 camera code (I havent compiled anything at home yet) and it said it couldnt find about a million things, so I changed some settings and fixed that, but now the only error left is this:
Quote:

MPLINK 3.90, Linker
Copyright (c) 2004 Microchip Technology Inc.
Error - could not find file 'clib.lib'.
Errors : 1
I reinstalled the IDE and C18 both and it still flashes up this message. Anyone have any ideas? I have located this clib.lib file but I cannot find any way to tell MPLAB where it is.

devicenull 15-01-2005 22:23

Re: Software Development System Installation
 
Quote:

Originally Posted by russell
I too am having issues with MPLAB. At school when we tried to install v 7.00 on our laptop it flashed up a bunch of error messages right as it finished the install, so I just hit ok on all of them, then tried to run it. It flashed up another error message, but we had to leave then. Another guy took the laptop home and is trying everything he can think of to get it to work, but he is currently installing it for the third time and it still isnt working. So meanwhile I came home to try to compile the rev-3 camera code (I havent compiled anything at home yet) and it said it couldnt find about a million things, so I changed some settings and fixed that, but now the only error left is this:


I reinstalled the IDE and C18 both and it still flashes up this message. Anyone have any ideas? I have located this clib.lib file but I cannot find any way to tell MPLAB where it is.

You didn't set up the include paths properly.. this is pretty easy to fix.
Open the workspace.
Project Menu->Build Options->Project
$INCDIR is compilerroot\h
$LIBDIR is compilerroot\lib
$LKRDIR is compilerroot\lkr
where compilerroot is the directory you installed the 2.40 compiler to. The IDE's pretty good about detecting the paths once you do one. It might be easier to set these in the suite defaults place

Project->Set Language Tool Options-> C18 Toolset->Search Paths and Directories.

russell 16-01-2005 14:18

Re: Software Development System Installation
 
Bad news. I tried what you suggested and had a few problems. It already had paths to all of those except $LKRDIR, so I set that one. However it still doesnt have paths to $AINDIR, $BINDIR, or $TMPDIR. The box for $AINDIR is all grey so you cannot fill it in, but the other two are not. I am not sure those two are necessary but whatever. The build still failed with the same message. And when I try to change it the other way you described I get to the C18 Toolset, and it shows each of them as already having paths (I gave all of them paths yesterday).
:confused: :confused: :confused:

Mark McLeod 16-01-2005 14:32

Re: Software Development System Installation
 
The only required paths are the LIB and INC.

Are these the paths for the toolsuite you have defined?
MPASM Assembler (mpasmwin.exe) (default location C:\Microchip\MPASM Suite\…)
MPLINK Object Linker (mplink.exe) (location C:\Microchip\MPASM Suite\…)
MPLAB C18 C Compiler (mcc18.exe) (location C:\mcc18\bin\mcc18.exe)
MPLIB Librarian (mplib.exe) (location C:\Microchip\MPASM Suite\…)

russell 16-01-2005 15:12

Re: Software Development System Installation
 
I have things kind of strewn about. My C drive is getting full so software now goes on D drive.

MPASM Assembler (mpasmwin.exe) C:\Program Files\Microchip\MPASM Suite\MPASMWIN.EXE
MPLINK Object Linker (mplink.exe) D:\mcc18\bin\mplink.exe
MPLAB C18 C Compiler (mcc18.exe) D:\mcc18\bin\mcc18.exe
MPLIB Librarian (mplib.exe) D:\mcc18\bin\mplib.exe

I dont remember installing this mpasm thingy, but I formatted both my hard drives since last year so I must have done it in the last few weeks..? In any case all of the .exes are actually in the locations stated above. The problem seems to be this clib.lib. Any idea how I specify it's path?

Mark McLeod 16-01-2005 21:33

Re: Software Development System Installation
 
Quote:

Originally Posted by russell
MPLINK Object Linker (mplink.exe) D:\mcc18\bin\mplink.exe
MPLAB C18 C Compiler (mcc18.exe) D:\mcc18\bin\mcc18.exe
MPLIB Librarian (mplib.exe) D:\mcc18\bin\mplib.exe

I suggest you switch to the locations I specified above for the Linker and Librarian. There are two versions of those files and they probably make the difference.

russell 16-01-2005 23:17

Re: Software Development System Installation
 
ok lemme try that real quick here...
Quote:

MPLINK 3.90, Linker
Copyright (c) 2004 Microchip Technology Inc.
Error - could not find file 'clib.lib'.
Errors : 1
:confused:
well it certainly didnt keep anything from happening, but it also didnt exactly make anything happen either

Mark McLeod 16-01-2005 23:41

Re: Software Development System Installation
 
Quote:

Originally Posted by russell
ok lemme try that real quick here...
:confused:
well it certainly didnt keep anything from happening, but it also didnt exactly make anything happen either

Well, clib.lib is specified in the 18f8520user.lkr file. I think LIBPATH is used to locate it.

russell 16-01-2005 23:50

Re: Software Development System Installation
 
huh? so I go into that file and specify the path in there?

russell 17-01-2005 00:17

Re: Software Development System Installation
 
Its fixed!! All this time all I had to do was hit the suite defaults button!

SchaeferB 21-07-2005 11:18

Re: Software Development System Installation
 
Quote:

Originally Posted by CJO
Ok, here you go,

un-tar and run.

USE AT YOUR OWN RISK

I'll post the source tomorrow. I also have source for the PIC18 firmware uploader, I am building that right now. I just put out the exe, I do not think that you will need any other files if you are running XP pro full install, I have tried it out on one machine. If it is the case that I am missing .dll's etc, I post, and I will include them. IFI loader should install all neccessary files.

Also, DO NOT HIT THE RUN BUTTON

Hi all,
i got a problem with the Bootloader:

i use a 18F458, so i includet the new ini file to get the device in the list,
when i start the original program and select 18F458 the program tells me that it has found the device.
if it is disconnected the device is also found
only if i select automatic mode the device isn't found.

if i try to read the device it tells me: Failed to read device...
i opened the hex file i programmed and pushed the write Device Button
after this i pushed the view Memory Button which opens 2 notepad windows:
EEDATA.MCP (this file is empty)
PROGMEM.MCP (shows my HEX file) --> starting with 000000 up to 007CD0
if i don't open the hex file the PROGMEM.MCP is also empty
next i pushed the release Button the warning appears i press the OK Button and nothing happens!
the program doesn't run, (i testet the program by writing it into the pic with the ICD2 and there it workes)
i do not understand why!!

what am i doing wrong? and:

what do i have to change in the bootload.asm?
i changed:
OLDCODE >> NEWCODE
#include P18F8720.inc >> #include P18F458.inc
and the Register1 i changed to Register
eg.: EECON1 >> EECON
the lines with EEADRH I deleted
probably this was wrong?

and in my program what should there be changed?
i changed:
OLDCODE >> NEWCODE
#pragma code InterruptVectorLow = 0x18 >> #pragma code InterruptVectorLow = 0x218
#pragma code InterruptVectorHigh = 0x8 >> #pragma code InterruptVectorLow = 0x208

do i have to let the program start at 0x200 and if so how coud i tell the program to do so, i am programming (under mplab IDE v 7.20 with the mcc16 newest release) in C.
my program needs 0x7CD0 space,
with the 0x200 Bootloader file it must be at 0x7ED0
the 18F458 has a maximum of 0x7FFF so it should fit

do i also have to change the adresses from the hex file because the code is 0x200 moved ?!?

with the program from CJO it isn't possible to connect, i also copied the ini file including the 18F458 part over the original,
after selecting the device the program tells me
no firmware version available...

i dont know what to do next i tried everything please
can anyone tell me whats wrong?
or is there another bootloader optimiced for the 18F458, a only "have to" uplode into the pic and all workes fine version?

pre-thanks for your answeres
Benedikt

Ryan M. 22-07-2005 07:03

Re: Software Development System Installation
 
Quote:

Originally Posted by SchaeferB
Hi all,
i got a problem with the Bootloader:

Hey Schaefer.

First, welcome to Chiefdelphi. We hope you enjoy the flight. :)

Second, in answer to your question, I don't know the answer to any of your questions (too low level for me :D), but for the last one, have you tried the latest version of the IFI Loader?

SchaeferB 25-07-2005 10:48

Re: Software Development System Installation
 
hi Ryan
i do not enjoy the fight :mad: . . . i worke on this bootloader for one week and it is not working yet!

i downloadet the IFI Loader you told me but i didn't find a source for the 18F458,

next problem is that my boss wants me to use the AN851 bootloader bowered by microchip, don't know why but now it has to be this one :eek:

next i tried to contact microchip but i am still on there list of todo :rolleyes:

perhaps anyone of you can help me with the asm file from the AN851,
i edited it to make it compile for the 18F458 but don't know if all changes were right,

hoping anyone can readthrough and help me
Code:

; *****************************************************************************
;        Software License Agreement                                   
;                                                                   
; The software supplied herewith by Microchip Technology           
; Incorporated (the “Company”) for its PICmicro® Microcontroller 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.                   
;                                                                   
;                                                                   
; Bootloader for PIC18F by Ross Fosler
; 03/01/2002        ... First full implementation
; 03/07/2002        Changed entry method to use last byte of EEDATA.
;                Also removed all possible infinite loops w/ clrwdt.
; 03/07/2002        Added code for direct boot entry. I.E. boot vector.
; 03/09/2002        Changed the general packet format, removed the LEN field.
;
; Memory Map
;        -----------------
;        |    0x0000        |
;        |    0x0002            |        Boot vector
;          |    0x0004        |        Unlock & write vector
;        |                    |       
;        |                |
;        |  Boot Block        |        (this program)
;        |                |
;        |    0x0200        |        Re-mapped Reset Vector
;        |    0x0208        |        Re-mapped High Priority Interrupt Vector
;        |    0x0218        |        Re-mapped Low Priority Interrupt Vector
;        |                |
;        |        |        |
;        |                |
;            |  Code Space        |
;        |                |
;        |        |        |
;        |                |
;        |    0x7FFE    |
;        -----------------
;
;
; 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                0x00        Read Version Information
;        RD_MEM                0x01        Read Program Memory
;        WR_MEM                0x02        Write Program Memory
;        ER_MEM                0x03        Erase Program Memory
;        RD_EE                0x04        Read EEDATA Memory
;        WR_EE                0x05        Write EEDATA Memory
;        RD_CONFIG        0x06        Read Config Memory
;        WT_CONFIG        0x07        Write Config Memory
;
; *****************************************************************************

 

; *****************************************************************************
;        #include P18F452.INC                ; Standard include
        #include P18F458.inc
; *****************************************************************************



; *****************************************************************************
#define        MINOR_VERSION        0x04                ; Version
#define        MAJOR_VERSION        0x00

#define        RC_DLE                0x01
#define        RC_STX                0x02

#define        STX                0x0F
#define        ETX                0x04
#define        DLE                0x05
; *****************************************************************************



; *****************************************************************************
CHKSUM                equ        0x00                ; Checksum accumulator
COUNTER                equ        0x01                ; General counter
ABTIME_H        equ        0x02
ABTIME_L        equ        0x03
RXDATA                equ        0x04
TXDATA                equ        0x05

; Frame Format
;
;  <STX><STX>[<COMMAND><DATALEN><ADDRL><ADDRH><ADDRU><...DATA...>]<CHKSUM><ETX>

DATA_BUFF        equ        0x08                ; Start of receive buffer
       
COMMAND                equ        0x08                ; Data mapped in receive buffer
DATA_COUNT        equ        0x09       
ADDRESS_L        equ        0x0A
ADDRESS_H        equ        0x0B
ADDRESS_U        equ        0x0C
PACKET_DATA        equ        0x0D       
; *****************************************************************************


 
; *****************************************************************************
        ORG        0x0000                        ; Re-map Reset vector
        bra        Setup       
        bra        BootMode
        bra        StartWrite
        bra        WriteWaitEEData               

        ORG        0x0008
VIntH
        bra        RVIntH                        ; Re-map Interrupt vector

        ORG        0x0018
VIntL
        bra        RVIntL                        ; Re-map Interrupt vector
; *****************************************************************************



; *****************************************************************************
; Setup the appropriate registers.
Setup        clrwdt
        clrf        EECON1
        setf        EEADR                        ; Point to last location
;        setf        EEADRH                       
        bsf        EECON1, RD                ; Read the control code
        incfsz        EEDATA, W
        bra        RVReset                        ; If not 0xFF then normal reset

        bcf        TRISC, 6                ; Setup tx pin
;        bsf        TRISC, 7                ; Setup rx pin

        movlw        b'10010000'                ; Setup rx and tx
        movwf        RCSTA
        movlw        b'00100110'               
        movwf        TXSTA

;        clrf        TRISB
;        btg        LATB, 0
; *****************************************************************************




; *****************************************************************************
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

        movlw        b'00001111'
        movwf        T0CON
        clrf        TMR0H
        clrf        TMR0L

        rcall        WaitForRise
 
        bsf        T0CON, TMR0ON                ; Start counting

        rcall        WaitForRise

        bcf        T0CON, TMR0ON                ; Stop counting

        movff        TMR0L, ABTIME_L                ; Read the timer
        movff        TMR0H, ABTIME_H

        movlw        0x05                        ; divide by 32
DivB32        rrcf        ABTIME_H, F
        rrcf        ABTIME_L, F
        decfsz        WREG, F
        bra        DivB32
        btfss        STATUS, C                ; Rounding
        decf        ABTIME_L, F
       
        movff        ABTIME_L, SPBRG        ; Sync
; *****************************************************************************



; *****************************************************************************
; Read and parse the data.
StartOfLine
        rcall        RdRS232                        ; Look for a start of line
        xorlw        STX                        ; <STX><STX>
        bnz        StartOfLine               

HalfStart
        rcall        RdRS232                       
        xorlw        STX
        bnz        StartOfLine                ; Otherwise go back for another character

        lfsr        0, DATA_BUFF                ; Point to the buffer

        clrf        CHKSUM                        ; Reset checksum               
        clrf        COUNTER                        ; Reset buffer count
               
GetNextDat                               
        rcall        RdRS232                        ; Get the data
        xorlw        STX                        ; Check for a STX
        bz        HalfStart                ; Yes, start over       

NoSTX        movf        RXDATA, W
        xorlw        ETX                        ; Check for a ETX
        bz        CheckSum                ; Yes, examine checksum               

NoETX        movf        RXDATA, W
        xorlw        DLE                        ; Check for a DLE
        bnz        NoDLE

        rcall        RdRS232                        ; Yes, Get the next byte
       
NoDLE        movf        RXDATA, W

        addwf        CHKSUM, F                ; Get sum
        movwf        POSTINC0                ; Store the data

        dcfsnz        COUNTER, F                ; Limit buffer to 256 bytes
        bra        StartOfLine

        bra        GetNextDat

CheckSum       
        movf        CHKSUM                        ; Checksum test
        bnz        StartOfLine
; ***********************************************



; ***********************************************
; Pre-setup, common to all commands.
        movf        ADDRESS_L, W                ; Set all possible pointers
        movwf        TBLPTRL
        movwf        EEADR
        movf        ADDRESS_H, W
        movwf        TBLPTRH
;        movwf        EEADRH
        movff        ADDRESS_U, TBLPTRU

        lfsr        FSR0, PACKET_DATA

        movf        DATA_COUNT, W                ; Setup counter
        movwf        COUNTER
        btfsc        STATUS, Z
        reset                                ; Non valid count (Special Command)
; ***********************************************

 

; ***********************************************
; Test the command field and sub-command.
CheckCommand
        movf        COMMAND, W                ; Test for a valid command                       
        sublw        d'7'
        bnc        StartOfLine

        clrf        PCLATH                        ; Setup for a calculated jump
        clrf        PCLATU
               
        rlncf        COMMAND, W                ; Jump
        addwf        PCL, F
       
        bra        ReadVersion
        bra        ReadProgMem
        bra        WriteProgMem
        bra        EraseProgMem
        bra        ReadEE
        bra        WriteEE
        bra        ReadProgMem        ;ReadConfig
        bra        WriteConfig
; ***********************************************



; ***********************************************
; Commands
;
; In:        <STX><STX>[<0x00><0x02>]<0xFF><ETX>
; OUT:        <STX><STX>[<0x00><VERL><VERH>]<CHKSUM><ETX>
ReadVersion
        movlw        MINOR_VERSION
        movwf        DATA_BUFF + 2
        movlw        MAJOR_VERSION
        movwf        DATA_BUFF + 3

        movlw        0x03
        bra        WritePacket


; In:        <STX><STX>[<0x01><DLEN><ADDRL><ADDRH><ADDRU>]<CHKSUM><ETX>
; OUT:        <STX><STX>[<0x01><DLEN><ADDRL><ADDRH><ADDRU><DATA>...]<CHKSUM><ETX>
ReadProgMem
        tblrd        *+                        ; Fill buffer
        movff        TABLAT, POSTINC0

        decfsz        COUNTER, F               
        bra        ReadProgMem                ; Not finished then repeat

        movf        DATA_COUNT, W                ; Setup packet length
        addlw        0x05
                               
        bra        WritePacket


; In:        <STX><STX>[<0x02><DLENBLOCK><ADDRL><ADDRH><ADDRU><DATA>...]<CHKSUM><ETX>
; OUT:        <STX><STX>[<0x02>]<CHKSUM><ETX>
WriteProgMem
        movlw        b'11111000'                ; Force a boundry
        andwf        TBLPTRL, F
 
        movlw        0x08

Lp1        movff        POSTINC0, TABLAT        ; Load the holding registers
        tblwt        *+
        decfsz        WREG, F
        bra        Lp1
 
        tblrd        *-                        ; Point back into the block

        movlw        b'10000100'                ; Setup writes
        movwf        EECON1
        rcall        StartWrite                ; Write the data

        tblrd        *+                        ; Point to the beginning of the next block

        decfsz        COUNTER, F               
        bra        WriteProgMem                ; Not finished then repeat

        bra        SendAcknowledge                ; Send acknowledge


; In:        <STX><STX>[<0x03><DLENROW><ADDRL><ADDRH><ADDRL>]<CHKSUM><ETX>
; OUT:        <STX><STX>[<0x03>]<CHKSUM><ETX>
EraseProgMem
        movlw        b'10010100'                ; Setup writes
        movwf        EECON1

        rcall        StartWrite                ; Erase the row

        movlw        0x40                        ; Point to next row
        addwf        TBLPTRL, F
        clrf        WREG
        addwfc        TBLPTRH, F
        addwfc        TBLPTRU, F

        decfsz        COUNTER, F
        bra        EraseProgMem       

        bra        SendAcknowledge                ; Send acknowledge


; In:        <STX><STX>[<0x04><DLEN><ADDRL><ADDRH><0x00>]<CHKSUM><ETX>
; OUT:        <STX><STX>[<0x04><DLEN><ADDRL><ADDRH><0x00><DATA>...]<CHKSUM><ETX>
ReadEE
        clrf        EECON1

        bsf        EECON1, RD                ; Read the data
        movff        EEDATA, POSTINC0
       
        infsnz        EEADR, F                ; Adjust EEDATA pointer
;        incf        EEADRH, F

        decfsz        COUNTER, F
        bra        ReadEE                        ; Not finished then repeat

        movf        DATA_COUNT, W                ; Setup packet length
        addlw        0x05
                               
        bra        WritePacket


; In:        <STX><STX>[<0x05><DLEN><ADDRL><ADDRH><0x00><DATA>...]<CHKSUM><ETX>
; OUT:        <STX><STX>[<0x05>]<CHKSUM><ETX>
WriteEE       

        movff        POSTINC0, EEDATA
        rcall        WriteWaitEEData                ; Write data

        infsnz        EEADR, F                ; Adjust EEDATA pointer
;        incf        EEADRH, F

        decfsz        COUNTER, F               
        bra        WriteEE                        ; Not finished then repeat

        bra        SendAcknowledge                ; Send acknowledge
 

; In:        <STX><STX>[<0x06><DLEN><ADDRL><ADDRH><ADDRU>]<CHKSUM><ETX>
; OUT:        <STX><STX>[<0x06><DLEN><ADDRL><ADDRH><ADDRU><DATA>...]<CHKSUM><ETX>
;ReadConfig
;        movlw        b'11000000'
;        movwf        EECON1
;
;Lp5        tblrd        *+
;        movff        TABLAT, POSTINC0
;
;        decfsz        COUNTER, F
;        bra        Lp5                        ; Not finished then repeat
;
;        movf        DATA_COUNT, W                ; Setup packet length
;        addlw        0x05
;
;        bra        WritePacket


; In:        <STX><STX>[<0x07><DLEN><ADDRL><ADDRH><ADDRU><DATA>...]<CHKSUM><ETX>
; OUT:        <STX><STX>[<0x07>]<CHKSUM><ETX>
WriteConfig
        movlw        b'11000100'
        movwf        EECON1

        movff        POSTINC0, TABLAT        ; Write to config area
        tblwt        *+

        rcall        StartWrite

        decfsz        COUNTER, F
        bra        WriteConfig                ; Not finished then repeat
               
        bra        SendAcknowledge                ; Send acknowledge
; ***********************************************



; ***********************************************
; Send the data buffer back.
;
; <STX><STX>[<DATA>...]<CHKSUM><ETX>

SendAcknowledge
        movlw        0x01                        ; Send acknowledge

WritePacket
        movwf        COUNTER

        movlw        STX                        ; Send start condition
        rcall        WrRS232
        rcall        WrRS232

        clrf        CHKSUM                        ; Reset checksum

        lfsr        FSR0, DATA_BUFF                ; Setup pointer to buffer area       
       
SendNext                                ; Send DATA
        movf        POSTINC0, W
        addwf        CHKSUM
        rcall        WrData
        decfsz        COUNTER, F
        bra        SendNext

        negf        CHKSUM                        ; Send checksum
        movf        CHKSUM, W
        rcall        WrData

        movlw        ETX                        ; Send stop condition
        rcall        WrRS232

        bra        StartOfLine
; *****************************************************************************




; *****************************************************************************
; Write a byte to the serial port.

WrData
        movwf        TXDATA                        ; Save the data
 
        xorlw        STX                        ; Check for a STX
        bz        WrDLE                        ; No, continue WrNext

        movf        TXDATA, W               
        xorlw        ETX                        ; Check for a ETX
        bz        WrDLE                        ; No, continue WrNext

        movf        TXDATA, W               
        xorlw        DLE                        ; Check for a DLE
        bnz        WrNext                        ; No, continue WrNext

WrDLE
        movlw        DLE                        ; Yes, send DLE first
        rcall        WrRS232

WrNext
        movf        TXDATA, W                ; Then send STX

WrRS232
        clrwdt
        btfss        PIR1, TXIF                ; Write only if TXREG is ready
        bra        $ - 2
       
        movwf        TXREG                        ; Start sending

        return
; *****************************************************************************




; *****************************************************************************
RdRS232
        clrwdt

        btfsc        RCSTA, OERR                ; Reset on overun
        reset

        btfss        PIR1, RCIF                ; Wait for data from RS232
        bra        $ - 2                       

        movf        RCREG, W                ; Save the data
        movwf        RXDATA
 
        return
; *****************************************************************************




; *****************************************************************************
BootMode
        setf        EEADR                        ; Point to the last byte
;        setf        EEADRH
        setf        EEDATA                        ; Bootmode control byte
        rcall        WriteWaitEEData
        reset
; *****************************************************************************




; *****************************************************************************
WaitForRise
        btfsc        PORTC, 7                ; Wait for a falling edge
        bra        WaitForRise
        clrwdt
WtSR        btfss        PORTC, 7                ; Wait for starting edge
        bra        WtSR
        return
; *****************************************************************************




; *****************************************************************************
; Unlock and start the write or erase sequence.

StartWrite
        clrwdt

        movlw        0x55                        ; Unlock
        movwf        EECON2
        movlw        0xAA
        movwf        EECON2
        bsf        EECON1, WR                ; Start the write
        nop

        return
; *****************************************************************************




; *****************************************************************************
        ORG        0x000A

WriteWaitEEData
        movlw        b'00000100'                ; Setup for EEData
        movwf        EECON1
        rcall        StartWrite               
        btfsc        EECON1, WR                ; Write and wait
        bra        $ - 2               
        return
; *****************************************************************************








; *****************************************************************************
        ORG        0x200
RVReset                                       
;        clrf        TRISB
;        btg        LATB, 0
       


        ORG        0x208
RVIntH

        ORG        0x218
RVIntL
; *****************************************************************************


        END



All times are GMT -5. The time now is 01:32.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi