; Minimal 68hc11e9 line-aware SCI "echo" program with typing-feedback using LEDs ; in less than 128 bytes RAM... ; Mike Spooner, April 2017 ; Pass this file through cpp preprocessor, then the as11 assembler #include "board.def" /* target-board specific constants */ #include "hc11e.def" /* (on-chip RAM size, etc) */ #include "buffalo.def" /* (monitor restart addr, remapped intr vectors) */ #include "mancon.def" /* manifest constants */ #include "lib.sym" ; pin-numbers of PORTB usage LED1 EQU $01 LED2 EQU $02 EVNT EQU $08 ; a program-drivable output-logic event pin ORG HIRAM bra init ; jump to program code, skip over variables counter FCB 0 ; 16-bit counter variable FCB 0 prmpt FCC "> " FCB 0 ; initialise the time-protected control registers and ; then initialise the rest of the system init ldx #CSREGS ; use X index-reg as ptr to base of control regs ldab TMSK2,X orab #$01 ; timer prescaler = /16 stab TMSK2,X ; initialise the SCI: ; 9600 baud, 8n1 ; transmitter enabled, transmitter-interrupts disabled, ; reciever enabled, single-drop, receiver-interrupts disabled ldab #$0C stab SCCR2,X ;ldab #$30 ; uncomment these to get 1200 baud ;stab BAUD,X ; ... ; initialise PORTB ; PORTB pins 0-1 used to drive a pair of debug LEDs ; PORTB pin 7 used to programatically generate low-going edge ldab #$00 stab PORTB,X ; main program main ldd #1 ; initialise line-counter to zero std counter prompt ldab #LED1 ; at start-of-line: light LED1, as a prompt bsr bpset ldaa counter ; and print the counter, as a prompt jsr sci_puthex ldaa counter+1 jsr sci_puthex ldy #prmpt jsr sci_putstr more jsr sci_getbyte ; wait for a byte from the SCI cmpa #ESC ; if we received an ESCAPE character beq done ; get out of here, else ; bsr upcase ; if character is lower-case, convert to upper-case jsr sci_putbyte ; echo it back ldab #LED2 ; toggle LED2, to provide per-character feedback bsr bptog ldab #LED1 ; turn off LED1, bsr bpclr ; because no longer at start-of-line cmpa #CR ; if received byte is not a CR bne more ; next ldaa #LF ; else emit an additional LF jsr sci_putbyte ldd counter ; increment the 16-bit line-counter addd #1 std counter bra prompt ; and start over done ldab #LED1+LED2 ; turn off both LEDs bsr bpclr jmp #BUFFALO ; restart the BUFFALO monitor ; convert ASCII code to upper-case ; argument: A = value to convert ; result: A = converted value ; clobbers: nothing upcase cmpa #'a' blt notlc cmpa #'z' bgt notlc suba #32 notlc rts ; clear specified PORTB pins (drive to logic-low) ; argument: B = pin bitmask ; clobbers: B bpclr comb ; invert mask andb PORTB,X bbstor stab PORTB,X rts ; set specified PORTB pins (drive to logic-high) ; argument: B = pin bitmask ; clobbers: B bpset orb PORTB,X bra bbstor ; set PORTB and return to caller ; toggle specified PORTB pins ; argument: B = pin bitmask ; clobbers: B bptog eorb PORTB,X bra bbstor ; set PORTB and return to caller