#include "c:\miniide\hcs12.inc" CR equ $0D LF equ $0A org $1000 buf ds.b 60 cx ds.b 1 org $2000 lds #$1800 ; set up stack pointer movw #SCI0_isr,UserSCI0 ; set up SCI0 interrupt vector jsr init_SCI0 jsr newline ;move cursor to the next line ldx #msg1 jsr puts2SCI0 jsr newline ldx #prompt ; prompt the user to enter a string jsr puts2SCI0 ; " ldx #buf ; read a string from the keyboard jsr getsSCI0 ; " jsr newline ; move cursor to next line ldx #buf ; echo the entered string to the monitor jsr puts2SCI0 ; " jsr newline ; move cursor to the next line cli ldx #msg2 ; output msg2 using interrupt-driven method jsr puts_SCI0 ; " jsr newline swi msg1 fcc "This is polling version." db 0 prompt fcc "Enter a message:" db 0 msg2 fcc "This is interrupt message!" db 0 ; ************************************************************************** ; The following subroutine uses interrupt-driven approach to output a string ; pointed to by index register X to SCI0. ; ************************************************************************** puts_SCI0 bset SCI0CR2,$80 ; enable transmission and TDRE interrupt cli ; enable global interrupt loop ldaa 0,x ; get a character to be output bne loop ; reach the end of string? bclr SCI0CR2,$80 ; disable TDRE interrupt sei rts SCI0_isr ldab SCI0SR1 ; clear the RDRF flag staa SCI0DRL ; output the character in A inx stx 3,sp rti ; ************************************************************************** ; The following subroutine outputs a CR/LF pair to move cursor to the next ; line. ; ************************************************************************** init_SCI0 movb #$00,SCI0BDH movb #156,SCI0BDL ; set baud rate to 9600 movb #$4C,SCI0CR1 movb #$0C,SCI0CR2 rts ; ************************************************************************** ; The following subroutine move the cursor to the start of the next row. ; ************************************************************************** newline ldaa #CR jsr putc2SCI0 ldaa #LF jsr putc2SCI0 rts ; ************************************************************************** ; The following subroutine outputs a character to SCI0 using polling method. ; ************************************************************************** putc2SCI0 brclr SCI0SR1,TDRE,* staa SCI0DRL rts ; ************************************************************************** ; The following subroutine outputs a NULL-terminated pointed to by X using ; the polling method. ; ************************************************************************** puts2SCI0 ldaa 1,x+ beq done_puts jsr putc2SCI0 bra puts2SCI0 done_puts rts ; ***************************************************************************** ; The following function uses the polling method to read a character from SCI0. ; ***************************************************************************** getcSCI0 brclr SCI0SR1,RDRF,* ; wait for the arrival of a character ldaa SCI0DRL ; read the character rts ; **************************************************************************** ; The following function uses the polling method to read a string from SCI0. ; and store the string in a buffer pointed by index register X. ; The string is terminated by the carriage return. ; **************************************************************************** getsSCI0 jsr getcSCI0 cmpa #CR ; is it a carriage return beq donegets staa 1,x+ ; save the character and increment the pointer bra getsSCI0 donegets clr 0,x ; terminate the string by a NULL character rts end