The Program
The example program is presented here as it is listed on the printer. -- Next
HOLON-11 / Application 12.12.98 Module Application The program consists of a command line interpreter (monitor), which communicates with a remote terminal via the SCI port. The monitor functions are invoked with single character commands. Groups 1. SCI port 2. Commands 3. Main
HOLON-11 / Application / SCI port 12.12.98 Page 1
SCI port
\ Defines the serial port driver functions for polled communication.
\ Waits for and reads a character at the SCI port.
Code SCI@ ( -- b )
ldab # $28 \ RDRF and OR bits
begin bitb SCSR 0<> until \ wait for a character
ldab SCDR clra pshd \ read char and push on stack
next
\ Writes the byte b to the SCI port.
Code SCI! ( b -- )
begin ldab SCSR 0< until \ wait until the port is free
puld stab SCDR \ send byte
next
\ Initializes the SCI port.
: SetupSCI
$30 BAUD c! \ 9600 baud
$00 SCCR1 c! \ 8 data, 1 stop bit
$2C SCCR2 c! \ enable read and write (RE,TE)
;
\ Directs the standard Forth execution vectors emit and key to the SCI
\ port. The default action of cr, cr0, emits the CR and LF codes and
\ resets a character counter.
: SCI=Terminal
make emit SCI! make key SCI@ make cr cr0 ;
HOLON-11 / Application / Commands 12.12.98 Page 2
Commands
\ A set of functions that are invoked by single letter commands. Add new
\ commands and functions according to your needs.
\ Prints byte b as a binary number.
: .bin ( b -- )
base @ 2 base ! swap 8 #. base ! ;
: ReadPortA
." Port A is " PORTA c@ .bin ;
\ Delivers the value of the free running timer of the 68HC11.
Code Counter ( -- n )
ldd TCNT 1push
: ReadTimer
." The free running timer contains " Counter decimal u. ;
\ A string object.
" 0F" String Byte$
\ Asks for a byte in hex notation, converts it to a number and writes the
\ value to port A.
: WritePortA
hex ." Enter a byte as a hex number and press <Enter>: "
ask Byte$ upcase Byte$
Byte$ Number? if drop PORTA c! else 2drop then ;
\ Displays 16 bytes at address adr.
: DumpLine ( adr -- )
16 0 do dup c@ 2 #. space 1+ loop drop ;
\ Displays 128 memory bytes starting at address adr.
: DumpMemory ( adr -- )
hex ." Memory contents at $" dup 4 #.
." and following:" cr
8 0 do dup DumpLine cr 16 + loop drop ;
\ Display the contents of the internal HC11 register block using an
\ universal memory dump function.
: ReadRegisters
$1000 DumpMemory ;
HOLON-11 / Application / Main 12.12.98 Page 3
Main
\ The main program and the cold start code. Press Ctl+F7=PROM to create
\ the code image for the EPROM. Set the limits of the code image in the
\ word SetROM at the start of the module Basis.
: SetupTerminal
SetupSCI SCI=Terminal hex
cr ." Please enter your commands." ;
\ The program.
: Main
SetupTerminal
begin cr ." > " key $5F and
case
ascii A of ReadPortA endof
ascii B of WritePortA endof
ascii C of ReadTimer endof
ascii D of ReadRegisters endof
ascii E of cr ." End of program" exit endof
emit endcase
again ;
\ Sets up the Forth machine and starts the program.
\ In the test version the application returns to the monitor via SWI.
Label InitProgram
lds # MainSP0 \ sets up the data stack
ldd # MainRP0 std RP \ and the return stack
ldab # 3 stab TMSK2 \ prescale the timer
ldy # DoMain 2 + \ .. return hook to monitor ..
jmp ' Main \ run program
\ Points the reset vector to the cold start code.
\ -- Have you set the correct memory limits? See SetRAM and SetROM --
( SetResetVector )
InitProgram vRESET SetVector