*FILENAME: main.asm (run convert for 1K; offset 63) *BOOTSTRAP DOWNLOADER PROGRAM *Programs an S-record file into internal EEPROM, after doing bulk erase, *via SCI at 1200 baud; for 9.8304MHz 68HC711D0 *04 April 1999 * system addresses rbase equ $0000 ;power up register base address STACK equ $00FF ;put stack at top of ram RAM equ $40 ;Beginning of Ram eeprom equ $E000 ;Beginning of EEPROM DELAY equ $0700 ;Approx. 5 ms for 8 MHz clock rate ;DELAY equ $ffff ;Approx. 5 ms for 8 MHz clock rate * * standard registers equates * porta equ $00 ;input/output port portb equ $04 ;output port portd equ $08 ;portd, serial communications ddrd equ $09 ;data direction register, portd tcnt equ $0e ;timer count toc1 equ $16 ;output compare, register 1 toc2 equ $18 ;output compare, register 2 tflg1 equ $23 ;main timer interrupt flags tmsk2 equ $24 ;timer interrupt mask register, prescaler baud equ $2b ;sci baud rate control sccr2 equ $2d ;sci control register 2 scsr equ $2e ;sci status register scdr equ $2f ;sci data, read (rdr) and write (tdr) adctl equ $30 ;a/d control register, not used adr1 equ $31 ;a/d channel 1 register, not used bprot equ $35 ;EEPROM block protect register option equ $39 ;system options pprog equ $3b ;EEPROM program control register hprio equ $3c ;misc. control register config equ $3f ;system configuration register opts equ %00011011 ;a/d off, stop delay, clock monitor, 1 s COP tmask equ %00000011 ;timer prescale mask: E/16 onmsk equ %10000000 ;mask for timer flag, on time over offmsk equ %11000000 ;mask for timer flag, off time over bdmsk12 equ %00110011 ;1200 baud with 8 MHz crystal bd9msk12 equ %00100101 ;1200 baud with 9.8304 MHz crystal ptdmsk equ %00000010 ;portd data direction: input, except txd sc2msk2 equ %00001100 ;mask to enable both transmit and receive tdremsk equ %10000000 ;transmitter ready flag rdrfmsk equ %00100000 ;receiver ready flag PAGE0 TEMP1: rmb 1 ;note that variables overwrite boot code TEMP2: rmb 1 CODE init: sei lds #STACK ;initialize stack ldaa #0 staa config ldaa #$e5 staa hprio ;Place micro into Expanded mode ldaa #opts ;load in system options staa option ldaa #bd9msk12 ;baud = 1200 for 9.8304Mhz crystal ; ldaa #bdmsk12 ;baud = 1200 for 8Mhz crystal staa baud ldaa #sc2msk2 ;disable interrupts, enable rcvr. & xmtr. staa sccr2 M0: bsr GetChar ;look for S record cmpa #'S' bne M0 bsr GetChar cmpa #'1' ;if not S1 record then beq Load1 cmpa #'9' ;if S9 record then bne M0 bsr GetByte ;get byte count tab subb #2 bsr GetAddress ;get execution address Load9: bsr GetByte ;get checksum byte (and ignore it) decb bne Load9 cpy #0 beq * jmp 0,Y ;start execution at user address Load1: bsr GetByte ;S1 record so get byte count tab subb #3 ;adjust for address and checksum bytes bsr GetAddress ;get address dey ;adjust address for L1B loop bra L1B L1B: bsr GetByte ;repeat iny ; get a byte and write it to EEPROM bsr Write ; increment EEPROM address decb ; decrement # of bytes bne L1B ;until all bytes in record programmed bra M0 ;get next S-record *********************************************************************** *Procedure Definitions: *********************************************************************** * * Fetches one character from the SCI, * and returns it in register A. GetChar: bset porta,%01000000 ldaa scsr ;get sci flags anda #rdrfmsk ;mask off irrelevant bits beq GetChar ;loop until character found ldaa scdr ;get character bclr porta,%01000000 rts * Converts 2 hex characters to a single byte value, * and returns it in register A. GetByte: GB1: bsr GetChar bsr Hex2Bin lsla lsla lsla lsla staa TEMP1 bsr GetChar bsr Hex2Bin oraa TEMP1 rts Hex2Bin: * Converts an ASCII hex character in register A * to a binary nibble and returns it in register A. cmpa #'9' bls HEX adda #9 HEX: anda #$f rts GetAddress: * Extracts load address and returns it in register Y. pshb ;preserve byte count bsr GetByte staa TEMP2 bsr GetByte tab ldaa TEMP2 xgdy pulb rts Write: * Writes the value contained in register A to the address pointed to * by register Y. pshb ;preserve byte count staa 0,Y bsr Delay_5_ms pulb rts Delay_5_ms: ldx #DELAY D1: dex bne D1 rts last equ ($-init) END