; on-chip-EEPROM-resident firmware for Cherryside project, version 1.1 ; Target: 68hc11e ; #include "board.def" #include "hc11e.def" #include "buffalo.def" #include "mancon.def" OPT c ; show cycle-counts in listing-output ORG OC_EEPROM ; delay for a specified number of milliseconds ; arguments: Y = number of milliseconds ; clobbers: Y ; ; Note: the particular loop construct below is independant of memory timings ; (internal or external, ROM or RAM), independant of 68hc11 flavour ; (A,D,E,F,J,K,M N,P) and variant (11, 711, 811). However, it is not immune ; to interrupts, which may be noticeable in the presence of very-high-frequency ; interrupt sources handled by slow ISRs... ; ; number of iterations of 16-bit register decrement-and-branch loop for 1ms ; 148 is appropriate for 1Mhz E-clock (4MHz XTAL) ; 296 is appropriate for 2MHz E-clock (8MHz XTAL) ; 444 is appropriate for 3MHz E-clock (12MHz XTAL) ; 592 is appropriate for 4MHz E-clock (16MHz XTAL) MSLOOPCNT EQU XTAL/27000 ; sic, works for any XTAL frequency ; delayms pshx ; save regs dly00 ldx #MSLOOPCNT ; do { x = MSLOOPCNT dly01 dex ; do { --x bne dly01 ; } while (x > 0); dey ; --y; bne dly00 ; } while (y > 0) pulx ; restore regs rts ; return to caller ; synchronously output nibble value as an ASCII hex digit to the SCI ; Arguments: A = nibble value ; clobbers: A sci_putxnbl anda #$0f ; mask off the high nibble adda #$30 ; ASCIIfy cmpa #$39 ; is digit? ble scipx0 adda #$07 ; adjust for hex digit > 9 scipx0 bsr sci_putbyte ; and send to SCI rts ; output byte value as pair of ASCII hex digits to the SCI ; Arguments: byte value ; clobbers: A sci_puthex psha lsra ; handle high nibble lsra lsra lsra bsr sci_putxnbl pula ; handle low nibble bsr sci_putxnbl rts ; transmit a nul-terminated string via the SCI ; arguments: Y = address of string ; clobbers: Y, A sci_putstr ldaa 0,Y ; get current character beq tailrtn ; are we finished? bsr sci_putbyte ; output character iny ; point to next character bra sci_putstr ; transmit a buffer via the SCI ; arguments: Y = buffer address, B = buffer length ; clobbers: A, B, Y sci_write tstb ; anything to do? beq tailrtn sciw00 ldaa 0,Y ; get source byte bsr sci_putbyte ; send it iny ; point to next source byte decb ; are we finished now? bne sciw00 tailrtn rts ; transmit a byte via the SCI ; arguments: A = byte to transmit sci_putbyte brclr SCSR,X #$80 * ; wait for TDRE(SCSR) staa SCDR,X ; load byte into transmitter ; note: also clears TDRE flag rts ; receive a byte via the SCI (and wait for it to arrive if needed) ; returns: A = byte received sci_getbyte brclr SCSR,X #$20 * ; wait for RDRF(SCSR) ldaa SCDR,X ; gather byte from receiver ; note: also clears RDRF flag rts libend equ *