using_pic18f4620
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
using_pic18f4620 [2006/09/28 23:42] – admin | using_pic18f4620 [2011/11/18 12:14] (current) – removed spam lpdunwell | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Using the PIC18F4620 or PIC18F4520 ====== | ||
+ | FIXME This is really outdated!!! | ||
+ | |||
+ | Historically, | ||
+ | |||
+ | The following are intructions on converting old apps, and developing new apps, to run on the PIC18F4620. Small changes to the procedure make it compatible with the PIC18F4520 also. | ||
+ | \\ | ||
+ | \\ | ||
+ | |||
+ | ====== OS Layers ====== | ||
+ | |||
+ | MIOS v1.9b or above is required. You will need to download the MIOS source from | ||
+ | \\ | ||
+ | The Bootloader and MIOS recompile steps which follow should not be necessary for most cases of '4620 use, as these components are now available precompiled and packaged in a zip file [[http:// | ||
+ | \\ | ||
+ | \\ | ||
+ | ===== Bootloader ===== | ||
+ | |||
+ | Bootloader v1.2, which is packaged with MIOS v1.9 and up, will need to be recompiled as follows:\\ | ||
+ | |||
+ | * Extract the MIOS source files from the zip\\ | ||
+ | * Edit bootloader\main.asm\\ | ||
+ | * Change | ||
+ | |||
+ | #define PIC_DERIVATIVE_TYPE 0 | ||
+ | To | ||
+ | #define PIC_DERIVATIVE_TYPE 1 | ||
+ | \\ | ||
+ | * Compile the project FIXME wiki link | ||
+ | \\ | ||
+ | * Burn the hex file to the PIC FIXME wiki link | ||
+ | \\ | ||
+ | |||
+ | ===== MIOS ===== | ||
+ | |||
+ | The MIOS Operating System itself must also be compiled, as follows:\\ | ||
+ | |||
+ | * Edit src\mios.h from the MIOS source files\\ | ||
+ | * Change | ||
+ | |||
+ | #define PIC_DERIVATIVE_TYPE 0 | ||
+ | To | ||
+ | #define PIC_DERIVATIVE_TYPE 1 | ||
+ | \\ | ||
+ | * Compile the project FIXME wiki link | ||
+ | * also see: [[Compiling the MIDIbox source on Linux]] - using GPASM (Linux, Mac) instead of MPLAB (Windows) | ||
+ | \\ | ||
+ | * Upload the hex file with MIOS Studio FIXME wiki link | ||
+ | |||
+ | |||
+ | //Please note that the above instructions should work for PIC18F4520 also. The only difference is that the PIC_DERIVATIVE_TYPE should be ' | ||
+ | \\ | ||
+ | \\ | ||
+ | |||
+ | ====== Application Layer ====== | ||
+ | |||
+ | Once your PIC18F4620 has the Bootloader burned onto it, and MIOS uploaded, you are ready to upload your application. A few modifications may be required:\\ | ||
+ | |||
+ | ===== Migration ===== | ||
+ | |||
+ | If you have an existing ASM-based application, | ||
+ | |||
+ | * Extract the ' | ||
+ | * Overwrite the files contained in the source of your application. | ||
+ | |||
+ | //Take note that this may overwrite customisations you have made to your application, | ||
+ | \\ | ||
+ | |||
+ | ===== ASM ===== | ||
+ | |||
+ | If your application is either:\\ | ||
+ | |||
+ | - a freshly migrated application (as above) | ||
+ | - a brand new ASM-based project based on a skeleton >= v1.9 | ||
+ | - an ASM-based application which already requires MIOS v1.9 or greater (like MBSID v1.7303) | ||
+ | |||
+ | Then the following steps are required:\\ | ||
+ | |||
+ | * Edit mios.h in the source of your application\\ | ||
+ | * Change | ||
+ | |||
+ | #define PIC_DERIVATIVE_TYPE 0 | ||
+ | To | ||
+ | #define PIC_DERIVATIVE_TYPE 1 | ||
+ | \\ | ||
+ | * Compile the project FIXME wiki link | ||
+ | \\ | ||
+ | * Upload the hex file with MIOS Studio FIXME wiki link | ||
+ | \\ | ||
+ | |||
+ | |||
+ | ===== C ===== | ||
+ | |||
+ | If your application is C-based, then the following steps are required. Some are optional recommendations, | ||
+ | |||
+ | == Note on compile errors == | ||
+ | |||
+ | When compiling your C-based application, | ||
+ | |||
+ | Linking project | ||
+ | warning: processor mismatch in " | ||
+ | |||
+ | This error is caused by SDCC compiling the application for the PIC18F452. Fortunately, | ||
+ | |||
+ | ==== Header and Library ==== | ||
+ | |||
+ | In the case that you should need to take advantage of the additional EEPROM on the newer PICs, the following alterations to the library and header are necessary: | ||
+ | |||
+ | * Edit pic18f452.c in the source of your application\\ | ||
+ | * Change | ||
+ | |||
+ | sfr at 0xfa9 EEADR; | ||
+ | sfr at 0xfab RCSTA; | ||
+ | To | ||
+ | sfr at 0xfa9 EEADR; | ||
+ | sfr at 0xfaa EEADRH; | ||
+ | sfr at 0xfab RCSTA; | ||
+ | |||
+ | * Edit pic18f452.h in the source of your application\\ | ||
+ | * Change | ||
+ | |||
+ | extern __sfr __at 0xfa9 EEADR; | ||
+ | extern __sfr __at 0xfab RCSTA; | ||
+ | To | ||
+ | extern __sfr __at 0xfa9 EEADR; | ||
+ | extern __sfr __at 0xfaa EEADRH; | ||
+ | extern __sfr __at 0xfab RCSTA; | ||
+ | \\ | ||
+ | //Note that the filenames stay as pic18f452.*, | ||
+ | \\ | ||
+ | |||
+ | ==== C-Wrapper ==== | ||
+ | |||
+ | The C-Wrapper will need to be edited as follows:\\ | ||
+ | |||
+ | * In the source of your application, | ||
+ | * Change | ||
+ | |||
+ | #define PIC_DERIVATIVE_TYPE 0 | ||
+ | To | ||
+ | #define PIC_DERIVATIVE_TYPE 1 | ||
+ | \\ | ||
+ | |||
+ | If you want to use this function, you may want to apply a small fix to the DEC2BCD Helper: | ||
+ | * In the source of your application, | ||
+ | * Change | ||
+ | |||
+ | < | ||
+ | global _MIOS_HLP_Dec2BCD | ||
+ | |||
+ | movwf MIOS_PARAMETER1 | ||
+ | movff FSR0L, | ||
+ | movf PREINC2, | ||
+ | goto MIOS_HLP_Dec2BCD | ||
+ | </ | ||
+ | To | ||
+ | < | ||
+ | global _MIOS_HLP_Dec2BCD | ||
+ | |||
+ | movff FSR0L, | ||
+ | movff PREINC2, | ||
+ | |||
+ | goto MIOS_HLP_Dec2BCD | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== Linker Script ==== | ||
+ | |||
+ | |||
+ | Modifications should be made to the linker script in order to take advantage of the additional capabilities of the 4620/ | ||
+ | If you are using a standard, PIC18F452-based application, | ||
+ | |||
+ | === Extend Codepage === | ||
+ | |||
+ | Both the 4620 and 4520 have extended code memory. To utilise this fully, make the following alterations: | ||
+ | |||
+ | * In the source of your application, | ||
+ | * Change | ||
+ | |||
+ | CODEPAGE | ||
+ | To | ||
+ | CODEPAGE | ||
+ | |||
+ | |||
+ | If you are using a GLCD with your PIC18F4620 the GLCD Font of the MIOS will be overwritten by this change though, as it lies in the range of 0x7C00-0x7FFF. There are __two__ approaches to prevent this (also see forum thread http:// | ||
+ | |||
+ | * To leave out the Font space in the PIC´s code memory, change | ||
+ | |||
+ | | ||
+ | To | ||
+ | | ||
+ | | ||
+ | |||
+ | __**or**__ try this solution from TK: | ||
+ | |||
+ | * copy the mios_glcd_font.inc file from the MIOS release into your application directory, rename it to mios_glcd_font.asm | ||
+ | * add following code to the file header: | ||
+ | |||
+ | LIST P=PIC18F4620, | ||
+ | DEFAULT_FONT code | ||
+ | FONT_ENTRY MACRO width, height, x0, char_offset | ||
+ | dw ((height) << 8) | (width), ((char_offset) << 8) | (x0) | ||
+ | ENDM | ||
+ | |||
+ | |||
+ | * change the " | ||
+ | * add a " | ||
+ | * add the new .asm file to the MAKEFILE.SPEC (behind the MK_SET_OBJ statement) | ||
+ | * change the font pointer within the Init() routine: | ||
+ | |||
+ | void Init(void) | ||
+ | { | ||
+ | MIOS_GLCD_FontInit(0xfcfc); | ||
+ | } | ||
+ | |||
+ | * if you are working under MacOS or Linux, type "perl tools/ | ||
+ | |||
+ | The first approach has the advantage, that it isn't required to upload the font again and again with each program update. | ||
+ | The second approach that new fonts can be inserted into the project in a similar way. | ||
+ | Please see the forum article mentioned above on instructions how to use labels in combination with fonts. | ||
+ | |||
+ | === Add Databanks === | ||
+ | |||
+ | \\ | ||
+ | In order to give our application the ability to recognise all that lovely, lovely RAM in the newer '4620 and '4520 PICs, one or a mixture of the following options is required: | ||
+ | |||
+ | ==Standard Bank Size== | ||
+ | |||
+ | * In the source of your application, | ||
+ | * Change | ||
+ | < | ||
+ | DATABANK | ||
+ | |||
+ | ACCESSBANK NAME=accesssfr | ||
+ | </ | ||
+ | To | ||
+ | < | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | |||
+ | ACCESSBANK NAME=accesssfr | ||
+ | </ | ||
+ | \\ | ||
+ | ==Extended Bank Capacity== | ||
+ | |||
+ | __**Be Careful doing this!!**__ | ||
+ | This can do weird things like make variables always = 0 where the memory that variable is stored in, crosses boundaries of 256b blocks. Do not make banks any larger than required, and try to let them begin at round numbers (100, 200, 300,...). This still might not even work. - stryd_one | ||
+ | |||
+ | |||
+ | The above change will enable SDCC to allocate the variables in your application to any of the specified banks above. The very observant among you may have noticed that these banks are 256 bits each.... So what happens if you want to use a variable which is greater than 256 bits in size, such as a large array, or string of characters? For this, you will need to create a bank of extended size, and you will need to direct your application to use that bank to store your large variable. | ||
+ | |||
+ | In order to create memory banks of extended capacity, it is necessary to section off a greater range than those given above. A good way to go about this is to combine two or more of the default banks. The following are examples of this. | ||
+ | |||
+ | Making a single, 512-bit bank: | ||
+ | < | ||
+ | DATABANK | ||
+ | // DATABANK | ||
+ | // DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | |||
+ | ACCESSBANK NAME=accesssfr | ||
+ | </ | ||
+ | //Note that the START of the bank is the same as the START of the first bank removed, and the END of the bank, is the same as the END of the last bank removed.// | ||
+ | |||
+ | \\ | ||
+ | This can be extended into larger ranges, and multiple customised ranges, as below: | ||
+ | < | ||
+ | DATABANK | ||
+ | // DATABANK | ||
+ | // DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | // DATABANK | ||
+ | // DATABANK | ||
+ | // DATABANK | ||
+ | // DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | |||
+ | ACCESSBANK NAME=accesssfr | ||
+ | </ | ||
+ | \\ | ||
+ | |||
+ | Or of course you could make the whole lot into one bank if you wanted to. This is NOT recommended though!: | ||
+ | < | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | |||
+ | ACCESSBANK NAME=accesssfr | ||
+ | </ | ||
+ | \\ | ||
+ | === Add Sections === | ||
+ | |||
+ | In order to assist in the use of these memory banks, we can give create ' | ||
+ | |||
+ | < | ||
+ | DATABANK | ||
+ | |||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | DATABANK | ||
+ | |||
+ | DATABANK | ||
+ | DATABANK | ||
+ | |||
+ | ACCESSBANK NAME=accesssfr | ||
+ | |||
+ | SECTION | ||
+ | |||
+ | SECTION | ||
+ | SECTION | ||
+ | SECTION | ||
+ | </ | ||
+ | |||
+ | You may create as many or as few sections as you require for your application. | ||
+ | |||
+ | |||
+ | |||
+ | ==== Application Code ==== | ||
+ | |||
+ | Once these sections are created, you can use them within your application, | ||
+ | |||
+ | # | ||
+ | |||
+ | For example, referencing the above section: | ||
+ | |||
+ | < | ||
+ | #pragma udata b512 MIDI_Table | ||
+ | unsigned char MIDI_Table[512]; | ||
+ | </ | ||
+ | |||
+ | **It is recommended to avoid this wherever possible.** Allow the compiler to allocate the memory wherever possible! | ||
+ | |||
+ | Check [[http:// | ||
+ | |||
+ | \\ | ||
+ | * Compile the project FIXME wiki link | ||
+ | \\ | ||
+ | * Upload the hex file with MIOS Studio FIXME wiki link | ||
+ | \\ | ||
+ | \\ | ||
+ | \\ | ||
+ | |||
+ | Still reading? Shouldn' |