??? 06/20/05 23:05 Read: times |
#95400 - straighforward? Responding to: ???'s previous message |
Erik, you broke the "peace" first! :-)
In fact, I don't believe there is any self-programming(IAP)-capable '51 clone which is NOT "straighforwardly" programmed. It goes almost always the following way: - set up address to be written to (sometimes writing to dedicated registers) - set up data to be written (maybe writing to dedicated register) - start programming writing to some "flash command" register - check if programming finished (reading from a status register), or simply wait for a given time, or the processor stalls for the time of programming. Most of the time it is necessary to run the program in a different part of memory than the programmed memory. Particularly, for T89C51RD2 the data memory can be programmed by the following code (this code of course has to reside in the bootloader area; you cannot run out of user area)(this is no secret, hints can be found in the datasheet): ;Disclaimer: Use at your own risk. May be completely wrong. FCON EQU 0D1h ;flash control SFR ;FCON = FPL3 FPL2 FPL1 FPL0 FPS FMOD1 FMOD0 FBUSY FCON_PROG1 EQU 050h FCON_PROG2 EQU 0A0h FCON_MAP_FL EQU 08h ;maps flash for MOVX write FCON_MOD_FL EQU 00h ;which area accessed:user flash/XAF/HSB FCON_MOD_XAF EQU 02h FCON_MOD_HSB EQU 04h ;program 1 byte in A into [dptr] Flash_ProgByte: push ie clr ea mov FCON,#FCON_MAP_FL|FCON_MOD_FL movx dptr,@a mov FCON,#FCON_PROG1|FCON_MOD_FL mov FCON,#FCON_PROG2|FCON_MOD_FL Flash_ProgWait: mov a,FCON jb acc.0,Flash_ProgWait mov FCON,#0 pop ie retA remark: for the T89/AT89, there is no need to erase flash before programming. I also went through what I had here and determined the resources needed. ;this is the T89C51RD2 bootloader ;returns bootloader version (IAP call 08) - 24h ;uses the current register set (and does not modify rb0, rb1) ;may disable interrupts for a while (but does not modify them) ;interrupts should be OK, as during programming it disables them ; ;resources usage (stack excl. 2 bytes for the IAP call itself): ; ;IAP call (r1) stack registers ;00 (read ID) 0 dptr (contains the accessed XAF address) ;02 (program data byte) 2 r2, acc (returns ALWAYS zero!) ;03 (read device data) 0 (acc - contains the read byte) ;04 (erase SBV+BSB) 2 r4, acc, dptr ;05 (program SSB) 2 r4, acc, dptr ;06 (program SBV+BSB) 2 r4, acc, dptr ;07 (misc read) 0 dptr, (acc) ;08 (bootloader version) 0 (acc) ;09 (program data page) 2 r2, r4, r6, dptr, AUXR1, acc (returns ALWAYS zero!) ; ----------------------------- ;this is the AT89C51ED2 bootloader ;returns bootloader version (IAP call 0F) - 00h (and both 0E calls return 00h) ;uses the current register set (and does not modify rb0, rb1) ;contrary to datasheet, most functions (except 09) don't explicitly use DPTR0, but the current DPTR ;contrary to T89... it does NOT disable interrupts... ; ;resources usage (stack excl. 2 bytes for the IAP call itself): ; ;IAP call (r1) stack registers ;00 (read ID) 0 dptr (contains the accessed XAF address) (acc) ;01 (erase block) 0 r0, r1, dptr, acc ;02 (program data byte) 0 acc ;03 (read device data) 0 (acc - contains the read byte) *undocumented* ;04 (erase SBV+BSB) 0 acc, dptr *undocumented* ;05 (program SSB) 0 acc, dptr ;06 (program SBV+BSB) 0 acc ;07 (misc read) 0 dptr, (acc) *undocumented - dptr=0003h reads XAF address 06h...*) ;09 (program data page) 0 r0, dptr, AUXR1, acc (returns ALWAYS zero!) ;0A (program X2,BLJB) 2 r0, r1, r2, dptr, (acc) ;0B (read HSB) 0 dptr, (acc) ;0E (read boot ID) 0 (acc) ;0F (read boot version) 0 (acc) The usual disclaimer: Use at your own risk. I may be completely wrong and you can have a different version of the bootloader. Jan Waclawek |