Inhaltsverzeichnis

R8C Forth

Deutsche Version dieses Textes

The German electronics Magazin Elektor distributed in its December 2005 issue a Renesas-R8C-Board produced by Glyn. The Software by Glyn distributed in the Magazin contained a C-Cross-Compiler for Windows. But it is more interesting to have a Forth System on this CPU.

division of functions

State 27mai2006

The System is now production quality.

Downloading gforth

The current Development Version of Gforth can be loaded using pserver CVS. For Windows-User without ambition to install Cygwin, there is a Snapshot as a setup.exe Installer containing the current Development Version of GForth.

Downloading gforth-ec

The Gforth-R8C can be loaded and flashed in the R8C Flash as a S-Record-File.

Installation and Usage of gforth

Prior to installing Cygwin and compiling Gforth from the Source (./configure && make), it is recommended to install libffi to be able to interface with C-Libraries.

All required libraries are available out-of-the box when using the supplied setup.exe Installer. The Windows Program Menü additionaly contains the entry „Bash“ which opens a BASH-Shell. All following Commands are given for a freshly opened BASH-Shell (for Cygwin-User: in Gforth-Directory).

Creating a ROM-Image for the R8C

The file rom-r8c.mot can be build using

./build-ec r8c

(will be the same as gforth-r8c.mot). There will also be a File data-r8c.mot created, which canbe used to repair a corrupted Data-Flash. The File rom-r8c.mot is loaded in Flash. Now we can connect to the R8C using a standard Terminal using 38400 Baud 8N1 (for example with Hyperterm, which is in the default Windows install — Set connection to „COMx“) and interactivly with the Forth in the R8C. The communication will go over the same serial Interface that is used to flash the R8C — no need for recabling. Downloading Forth Source with a normal Terminal Program is not possible, because Xon/Xoff is to slow. It is possible to cur'n'paste Forth Sorucecode to the Terminal when the Linefeed delay is set to 250ms.

You can play around with the Forth in the R8C, for example

1 2 + .
lcdpage
s" Hello World" lcdtype
adc@ .

All possible Forth commands (words) can be listed with

words

showing last defined words first.

Forth-Terminal using gforth

The GForth „build-in“ terminal can be started using the command

./gforth arch/r8c/terminal.fs

By default, the communication will be over COM2 — if needed, the source file can be edited to support a defferent COM-Port, or — when using an USB Converter — map the USB Serial Interface to COM2 using the Windows Devicemanager. In Linux the Device /dev/ttyUSB0 is used by default. This default can also be cahnged by editing the source.

Using the terminal, the ported Tetris-for-Terminals by von Dirk Zoller can be started:

include arch/r8c/tt.fs

(this will take a while — the R8C is compiling the code itself). Start Tetris with

tt

LED Blinkenlights for R8C

A simple „Blinkenlights“ Demo, that will autostart after Reset:

rom
: light!  led!  &100 ms ;
: runlight  1 light! 2 light! 4 light! 8 light!
  4 light! 2 light! ;
: blinkenlights  BEGIN  lauf  key?  UNTIL ;
' blinkenlights is bootmessage
ram
savesystem

The program will run until a key on the terminal is pressed.

ADC Converter in the R8C

A loop that reads from the ADC (Analog to Digital Converter) and prints the value on the LCD:

: adcmeter
  BEGIN  6 adc@ 0 <# #s #> lcdpage lcdtype &200 ms
         key? UNTIL ;

Multitasker

This a simple Multitasker that allows exactly one backgroundtask:

rom
 
Variable bgtask ram $20 cells allot rom
:noname  bgtask @ 0= ?EXIT
    rp@ bgtask @ sp@ cell+ bgtask ! sp! rp! ;
IS pause
: task r> bgtask $20 cells + !
  bgtask $20 cells + bgtask $10 cells + !
  bgtask $10 cells + bgtask ! ;
:noname echo @ IF
     BEGIN pause key? UNTIL THEN (key) ;
is key
 
ram

An adapted version of the Blinkenlights Demo above:

rom
: light!  led!  &100 ms ;
: run  1 light! 2 light! 4 light! 8 light!
  4 light! 2 light! ;
: blinkenlights
  task  BEGIN  run  AGAIN ;
ram

Text Scroller

Similar to the Blinkenlights we can create a Text Scroller. The scroll speed is controlled with the potentiometer on ADC channel 6.

rom
 
Create text
," GNU Forth EC R8C -- Microprozessor -- "
Create ledtable 1 c, 2 c, 4 c, 8 c, 4 c, 2 c,
Variable /text
 
: scroller  task
  BEGIN  text count /text @ over mod /string
         16 min dup >r lcdpage lcdtype
         r@ 16 < IF  text 1+ 16 r@ - lcdtype  THEN
         rdrop 1 /text +!
         /text @ 6 mod ledtable + c@ led!
         6 adc@ 2/ ms
  AGAIN ;
 
ram