Now we have communication with the TLM we may see what can be achieved. Try the following:
1 2 + . (cr) Error: + is undefined
As this is the start we do not have many Forth words loaded yet. To help with interactive development any word in the Library may be loaded from the keyboard with REQUIRED. e.g.
REQUIRED + (cr) ok
1 2 + . (cr) 3 ok
Brilliant the TLM can add 1 and 2 to get 3.
All seems to be working so let us jump up to the real thing and try a multi-tasked program with timer driven interrupts.
Type: FLOAD \DEMO\COUNTER (cr)
Unresolved references:
*** No words Unresolved ***
Statistics:
Last Host Address: $4C80C
Last Target Code Address: $478
Last Variable Address: $AC
Last EE2 Address: $0 ok
You should see something like this. You may have noticed the top centre of the PC screen flash through two files.
What happened? First we input FLOAD \DEMO\COUNTER.F. FLOAD is the Forth word for File Load. It takes the next space delimited input string as a file name and tries to interpret the contents. It has the same effect as you typing the file contents at the keyboard. These are ASCII sequential files that only contain ASCII characters. You will notice that no file extension was used, FLOAD assumes .F if non is given. So if you use .F for all your files then you may refer to them by name only.
The file COUNTER.F asks for another file, 18FMULTI.F to be loaded to make up the demo program. As each one loads it's path and name appear at the top of the screen.
Now you have loaded the demo, let's run it. Type:
GO (cr)
The counter demo is now running.
To see the results we may use the TLM task to inspect the counter tasks values e.g.
COUNTER1 @ . COUNTER2 @ . (cr)
We will see that COUNTER1 is incrementing at ~1 sec intervals and COUNTER2 is incrementing many thousands per second. The task controlling COUNTER2 is just running as fast as it can. The COUNTER1 task is controlled by Timer0 which is set to overflow ~1/sec with a 4MHz clock. The interrupt routine is using a priority interrupt with a fast return, RETFIE ,S to restore the WREG, STATUS and BSR. As the GP, FSR1, is used this is saved in GP-SAVE. The interrupt shown here may be used to AWAKEN any task by just changing the task reference.
We may now load the second, more complex, demonstration by using;
?REM NEW-APP (cr)
?REM or Ctrl-R key resets the TLM and the PIC. NEW-APP erases the PIC Flash code space from $200 to the end of the code memory and resets all the pointers back to where we were after first loading IRTC and TLM. We may now load the second demonstration with;
FLOAD \DEMO\CONVERTOR
The files will load and the code will be incrementally programmed into the code space.
This demonstration also consists of two tasks. The first, CONVERSION-TASK, increments a value and then converts it to an ASCII string and places it in BUFFER. The second, RESULT-TASK, converts the string back to a number and places the answer in RESULT. The CONVERSION-TASK runs to a STOP and is restarted by an ~1 sec interrupt similar to that in demo1. The RESULT-TASK runs as ofter as it can. If we look at RESULT with the TLM task;
RESULT @ .
We will see the value returned increment at an ~1 sec rate. The tasks are prevented from interfering by semaphores which are described later.
To stop the demo Type:
?REM (cr)
PIC18Fxxx Stack Empty ok
you should see something like this. We now are back to before running the demo.
We have loaded several new words, the only one you have used of so far is GO. IRTC can show you them all in two ways.
The first is to use the editor WinView. Type:Ctrl-O and select the file COUNTER.F in the \DEMO directory.
The editor screen should appear with the contents of the file COUNTER.F displayed. This is the so called load screen for the demo program. You will see the file name that appeared on the top of the screen during FLOAD, with the word INCLUDE before it. INCLUDE and FLOAD are the same, it is just that the file reads better by using the word include. The rest of the file is the code required for the demo with comments with a \ before them at the end of a line.
The editor has a Browse mode that lets you look at files without being able to alter the contents. So let us use this to examine the word GO from the Win32For console window:
TV GO (cr)
You should now see the editor screen with the cursor flashing on a : before the word GO. This is the definition of the word that we have just run.
Now we will see one of the most useful features of Win32Forth, viewing. When a word is defined a link is generated to the position inside the file from whence it came. When we VIEW, the word is found and the link used to show the file in the place the word was defined.
We may now navigate around the Source files to see how the demo was programmed.
Note: To see the help definitions of Library words use TH <name>.
The Demo, or any application may be removed with NEW-APP.
Enter the Remote mode with your application or the demo loaded and type NEW-APP. IRTC will revert to the condition it was when first loaded with only the TLM words in the Target. The PIC Flash code space will be erased for all the sectors from APP-START to the value in ROM-END, the end of the application.