;This program illustrates how to set up and use the SCI ;(serial communications interface) port of the 68HC11. ;This program is designed to run autonomously (without Buffalo) ;and is designed to reside in EEPROM memory. scdr .cequ $102F ;address of sci data register scsr .cequ $102E ; " " " status register .org $B600 ;beginning of EEPROM memory lds #$0047 ;MUST INITIALIZE STACK POINTER!!!!!!!!!!! jsr init_serial ;initialize the serial port ;for 9600 baud/no parity/1 stop bit loop: ldx #hello ;point to message buffer jsr myoutstr ;send out characters in message buffer jsr myinchar ;wait for user to hit any key wait0: ldab scsr ;make sure transmitter buffer is empty bitb #$80 beq wait0 ;if not empty - wait staa scdr ;OK-echo the input character to the serial port cmpa #'q' ;if that key was "q" then quit beq quit ldx #mycrlf ;send CR/LF string jsr myoutstr bra loop quit: ldx #quitit jsr myoutstr bra * ;infinite loop to suspend execution myoutstr: ;This subroutine mimics the Buffalo ".outstr" routine loop0: ldaa 0,X ;read a character from the Buffer cmpa #$04 ;is it an end of transmission(EOT) character? beq leave ;if so leave the loop wait: ldab scsr ;make sure transmitter buffer is empty bitb #$80 beq wait ;if not empty - wait staa scdr ;OK-send character out the serial port inx ;Increment the pointer bra loop0 leave: rts ;all done EOT .cequ $04 hello: .db "Hello Hello Hello",13,10,EOT ;message buffer quitit: .db "This program is done - Later dude!",13,10,EOT mycrlf .db 13,10,EOT myinchar: ;subroutine to mimic the Buffalo inchar routine ;First wait for a character to arrive wait1: ldx #scsr brclr 0,X,$20,wait1 ;wait till RDRF bit is set-indicating a ldaa scdr ;read the data into Acc. A & return rts ;the brclr (reads scsr2) followed by the read of scdr ;will clear the RDRF bit init_serial: ;routine to initialize the serial port ;BAUD REGISTER BITS ----------------------------------------- ;TCLR 0 SCP1 SCP0 RCKB SCR2 SCR1 SCR0 ;X/0 0 1 1 X/0 1/0 1/0 1/0 --Values ;Assume bits 7,6,5,4,and 3 are 0,0,1,1 and 0 respectively. ;If SCPx are both 1's then SCRx determine the baud rate as follows: ;SCR2/SCR1/SCR0: ;110 ==> 150 baud 101 ==> 300 baud ;100 ==> 600 baud 011 ==> 1200 baud ;010 ==> 2400 baud 001 ==> 4800 baud 000 ==> 9600 baud baud .cequ $102B ;address of the 68HC11 Baud register sccr1 .cequ $102C sccr2 .cequ $102D b_4800 .cequ $01 b_9600 .cequ $00 ldaa #($30+b_9600) staa baud ;set baud rate clra staa sccr1 ;set for 8 data bits/1 stop bit/no parity ldaa #$0C staa sccr2 ;enable transmit and recieve rts .end