;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Preliminary: ; I assume that you have a working comunication routines: ; I called this routine as rpop (reception of one byte), tpush(transfer a byte) ; and print for the 'famous' string printer with a string ended by 0 ; ; Usage: lcall programa ; Then the program pops from comunication buffer (or directly) one hex line and program it in the flash. ; Be carefully and don't overwrite your own program ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;----------------------------------------------------------------------------------------------- ;Aknowelment of one line in .hex file ;gdph y gdpl; Store the true address ;vram :Address in RAM where we store the data ;Contador: Pointer to do the loop (Contador means Counter in spanish) ;Longitud: Lenght of the transmited data (longitud means length in spanish) ;----------------------------------------------------------------------------------------------- Hex2bin: mov suma,#0 lcall rpop cljne a,#':',error ;If dontīt start by colon we exit lcall rpop mov b,a lcall rpop lcall aschex2bin mov longitud,a ;Storing the length of the register mov contador,a mov suma,a ;The fisrt time i get the value, don't add lcall rpop ;Addr of the line mov b,a lcall rpop lcall aschex2bin mov gdph,a add a,suma mov suma,a lcall rpop mov b,a lcall rpop lcall aschex2bin mov gdpl,a add a,suma mov suma,a lcall rpop ;Gets the type of register mov b,a lcall rpop lcall aschex2bin ; Types of line possibles: ; 00 Normal Linel ; 01 End of file ; 02 Extended addressing (don't used because we have only 64k) jz l_h2b1 cjne a,#1,error ;If is not end of file, error (extended addr) lcall rpop lcall rpop mov a,#0ffh ret l_h2b1: mov dptr,#vram bucle: lcall rpop mov b,a lcall rpop lcall aschex2bin movx @dptr,a add a,suma mov suma,a inc dptr djnz contador,bucle xrl suma,#0ffh inc suma lcall rpop mov b,a lcall rpop lcall aschex2bin subb a,suma ret error: mov a,#1 ;Error Code, if we want we can put another ret ;--------------------------------------------------------------------------- ; ;Converting from hex ascii to binary ; the pseudo opcode cjm is a macro: ; CJM salta si arg1 < arg2 cjm MACRO dato1,dato2,salto cjne dato1,dato2,$+3 jnc $+5 ljmp salto ENDM ;--------------------------------------------------------------------------- aschex2bin: push acc mov a,b cjm a,#'A',l_a2b1 ; subb a,#'A'-'9' l_a2b1: subb a,#'0'-1 swap a mov b,a pop acc cjm a,#'A',l_a2b2 ; subb a,#'A'-'9' l_a2b2: subb a,#'0'-1 orl a,b ret ;--------------------------------------------------------------------------- ; Programing in the FLASH the recived .hex line ;--------------------------------------------------------------------------- Programa: lcall hex2bin jz l_pr1 ;If return a non cero value is an error cjne a,#0ffh,l_prerr ;If is FF is end of file lcall print db 13,10,'Final de fichero',0 ret l_prerr: lcall print db 13,10,'Error',0 ;Shows an error and ends ret l_pr1: mov auxr1,#1 ;Activate DPTR 0 mov dptr,#vram ;Addr in xram mov auxr1,#0 ;Activate DPTR 1 mov dph,gdph ;Addr in FLASH mov dpl,gdpl mov a,longitud mov r1,#009h ;Code of flash programing orl auxr1,#00100000b ; setb enboot lcall 0fff0h ;Calling flash programing anl auxr1,#11011111b ;clr enboot lcall print db 13,10,'Programed Line',13,10,13,0 ret