

| postzegel | 'poss say ghull' | = stamp |
| egel | 'ay ghull' | = hedgehog |
| boek | 'book' | = book |




Once noForth is running, load the noForth tools to get additional functionality like: .S SEE
and WORDS. Download the file noforth tools.f on your PC. Then upload the file to the Egel-kit or Launchpad using your communication program.
With some programs it is possible to copy/paste the source code into the window of the communication-program.
WORDS' will show an overview of the dictionary. Well done! noForth and the tools are running, and you have loaded your first noForth-program..
FLASH .
TOOLS\'. Type this to delete the old source-code.
Then load the new source-code and see what effect your changes have.
For more information on shields, see the 'noForth documentation'.
FLASH ( -- ) \ starts the simple flasher
In this example 8 LEDs are controlled by a noForth program.
If this is the first time you use noForth on a MSP430, it might be good to first work through chapter 0,
which gives a detailed overview of the steps needed to get a noForth program running.
Connect the cathodes of the LEDs together on the
breadboard with wires connect them to
the ground using a 100 Ohm resistor, and finally connect the ground of the breadboard to the ground of the LaunchPad.
COUNTER ( -- ) Binary counter on P2 RUNNER ( -- ) Running light on P2* Open images in a new window for a better resolution.
This chapter builds on the previous chapter. The addition is the S2‑switch
(if you use the Egel-board and/or MSP-EXP430G2 than the switch is already on the board), which is connected to port P1.3 for input. 1.
COUNTER ( -- ) Binary counter on P2 RUNNER ( -- ) Running light on P2When the S2‑switch is held down the LEDs will run at a higher speed in
COUNTER and RUNNER.
This chapter is an extension of chapter 1 and 2. This time a potentiometer of about 4K7 is added. Connect the center wire of the potentiometer to P1.7 and the other two wires to VCC and ground.
SHOW-ADC1 ( -- ) Show ADC result in binary SHOW-ADC2 ( -- ) Show ADC result as VU-meter SHOW-ADC3 ( -- ) Show ADC result on screen as text
The only way these routines differ are in the way the results are shown.
* Open images in a new window for a better resolution.
STARTUP or press the reset key, and all communication
will go through Bluetooth.
Received characters will be shown on the LEDs.
STARTUP program!
Bit input comes from P1.3 (S2).
RELAY-CONTROL ( -- )
Try different kinds of delays by changing the lines in the word RELAY-CONTROL
with the backslashes. Only select one option at a time!
Being able to control a stepper motor is very useful for robot- and other projects where something has to move.
noForth on a MSP430 micro-controller makes it easy!
STEPPER ( -- ) Change direction with S2‑switch.
ONE-STEP you may select single phase,
two phase or half step driven stepper control. Only choose one method at a time.
STEPPER ( -- ) Change direction with S2-switch.
ONE-STEP you may select single phase,
two phase or half step driven stepper control. Only choose one method at a time!
Measuring distances is useful in many applications. It can easily be done with an ultrasound sensor and a MSP430.
MEASURE - Show distance in steps of 2cm binary on LEDs
CYCLUS ( -- ) Cycle once thru PWM range POWERCONTROL ( -- ) Set PWM value using two switches
The two switches control the brightness of the LED by varying the duty-cycle.

| Load the assembler before the e10 noForth programs,
some parts of the program are in assembler code.
|
RC-TRANSMITTER ( -- ) Send the RC5 on/off command
A shift-register converts serial data to parallel data,
this makes it possible to control a 7-segment display with 3 wires to the MSP430.
CHARACTERS ( -- ) Show all implemented characters COUNTER ( -- ) Show a decimal counter DICE ( -- ) Simulate a tumbling dice
A LCD-display with 2 lines of 16 characters is useful in a lot of projects. Only 6 connections are needed to show text on the display.
One more connection controls the contrast of the display. In this example timer-A1 generates the needed PWM-signal.
Connect a 3 Volt version of a 1602 LCD display with P2.0 .. P2.5 (see schematics)
P1.6 is the contrast control output for the LCD.
>CONTRAST. Values between 0 and 16 are valid.
>CONTRAST ( +n -- ) Set contrast to +n (valid values: 0:16) DEMO1 ( -- ) Show text message 1 DEMO2 ( -- ) Show text message 2
Connect the SR04 sensor or similar, with four wires to the MSP430
place a LED-board or connect individual LEDs (see schematics).
The word DISTANCE starts the US-sensor, and returns a distance to the nearest object in centimeter.
When in the source-code in the word DISTANCE, >CM is changed to
>MM the distance is returned in millimeters.
The usable range of available US-sensors varies. The cheap Chinese HC-SR04 modules have a range of 2cm to 220cm.
Other variants may have different ranges, sometimes up to 600 cm.
The photo shows three pin-compatible replacements for the HC-SR04.
US-ON ( -- ) Activate ultrasonic hardware DISTANCE ( -- cm ) Show object distance in cm (or mm) MEASURE ( -- ) Show object distance on LEDs
The outputs are P1.6 and P2.1.
The timers in the MSP430 are well suited to generate sounds of varying frequencies.
By using two timers, two different frequencies can be generated at the same time.
The frequency range is 61 Hz to 39000 Hz. In this example P1.6 and P2.1 are used as outputs.
HONK ( -- ) Sound a heavy horn HUNTING ( -- ) Play the hunting horn BJOHN ( -- ) Play Brother JohnAnd for e14b:
>DTMF ( addr u -- ) Convert string to DTMF tones WILLEMO ( -- ) Call the author FORTHGG ( -- ) Call Forth-gg chairman
The 12kHz and 32kHz noForth words activate the Very Low Frequency or 32kHz oscillator.
At 12kHz serial communication is not possible, due to the low and inaccurate frequency of the VLO.
At 32kHz communication is only possible at 9600 baud.
To allow for a function-check with an oscilloscope or logic analyzer,
two additional programs activate the 12kHz or 32kHz frequency on output P1.0.
For more information about the built-in capacitors for the 32kHz oscillator, see SLAU144J.PDF page 274 and beyond.
The MSP430 can function with or without a crystal. To ensure good accuracy without a crystal,
T.I. calibrates every individual MSP430.
The calibration-data for the DCO starts at address 10F6 (within the info-flash segment A starting at 10C0) and
both e15a and e15b make use of the calibration-data.
12KHZ ( -- ) Use VLO oscillator
32KHZ ( -- ) 32kHz oscillator active
1MHZ ( -- ) Set DCO at 1 MHz
8MHZ ( -- ) Use DCO at 8MHz
16MHZ ( -- ) DCO on 16MHz
BLINK ( ccc -- ) Run blinker at freq. 'ccc'
Example of BLINK this is how: BLINK 32KHZ or one of the other frequencies.
It demonstrates that the timing of the MSP430 is independent of the used system-clock by flashing
both LEDs every 6 seconds. After the program is finished, the default MPU frequency is restored.
| Load the assembler before the e16 noForth programs,
the software RS232 routines are in assembler code.
|
This example shows how to code half, and full duplex UART-connections using only
software (=bitbang method). That is without using the specific UART hardware on the MSP430.
You can use the following commands to test your program in the old RS232 configuration (before pressing RESET):
RS-ON To initialise software RS232.
CH # RS-EMIT MANY To test RS232 output.
COLD When these routines work.
RS-ON routine is skipped and you're back in the original configuration.
This example shows how to measure a distance with a US-100 sensor in serial mode using RS232.
The word DISTANCE starts the US-sensor, and returns the distance to the nearest
object in millimeters. The distance-measurement by the US-100 module is very stable due to
the built-in temperature compensation.
The range of the sensor is about 30mm to 4000mm and it works from 2.4 Volt to 5 Volt.
The used serial mode has an increased resolution.
RS-ON ( -- ) Activate sofware serial interface DISTANCE ( -- mm ) Show object distance in millimeters MEASURE ( -- ) Show object distance on screen
This chapter provides an interface to the Robotic sensor module Even
if you do not own such a sensor-module, it might still be a useful example.
For instance when you want to add a couple of DIY touch-sensors to a robot.
Adapting the software for that is easy.
| Print layout for the simple robotic sensor unit. On it two feelers, a PIR sensor and two LEDs. |
The internal schematic of the SB312A smart PIR sensor unit. Note that the sensor
has it's own 3 Volt voltage stabiliser. The sensor output already has a 10 kOhm resistor.
MOTION? ( -- fl ) True when PIR sensor senses motion TOUCH-LEFT? ( -- fl ) True when left feeler bend TOUCH-RIGHT? ( -- fl ) True when right feeler bend ?LED ( fl -- ) LEDs on when fl is true SENSORS ( -- ) Test the sensor module
Cut two small pieces from a tin can, each about 3x3 cm (not critical).
Solder a 20cm long lead to each of the pieces. Cover one of the pieces on both sides with duct tape,
put the second piece on top and fix it with a third piece of duct tape.
The two pieces of tin are now separated by a single layer of duct tape.
And that's it, you have constructed a capacitive switch!
It is important that the metal pieces do NOT touch each other directly.
Mechanically more stable capacitive switches can be made from PCB-material.
Size and form are not very critical.
Connect the switch as shown in the schematic, load program e19a and run TOUCH.
Then, as long as you touch the switch, the onboard-LEDs are toggled.
Please take a look at the source-code. It is pretty short and it contains a neat trick.
Normally a capacitive switch needs calibrating, but this software is self-calibrating.
In addition, it will also handle any drift of the capacity of the switch.
This functionality takes only a few lines of noForth code and works so well that the
software functions with almost any reasonable switch.
Which is proof that beautiful things can happen when you mix the features of
the MSP430 with the power of noForth!
TOUCH-ON ( -- ) Activate the touch interface TOUCH? ( -- f ) True when the sensor is touched SHOW ( -- ) Shows the inner workings TOUCH ( -- ) Touch and switch LEDs - example
border=(ref0+ref1)*.752) Calculate the difference between current measurement & reference:
diff=(ref0+ref1)-(pad0+pad1)3) Detect a touch of the slider:
diff > border4) Calculate the position bewteen 0% and 100%:
Percentage=((((ref0-pad0)x100)/diff),100)min
Cut two oblong pieces of tin from a tin can, about 2x7cm.
Cut one of the pieces into 2 long triangles.
Solder 3 leads of ~20cm to the three pieces.
Cover both sides of the oblong piece with duct tape.
Add the 2 triangular pieces, making sure that none of the 3 pieces make contact,
and fix these also with duct tape.
Connect the leads according to the schematic.
Load program e19b and run DIMMER. From than on, the powerLED on P2.4
lights when touching the slider. And by sliding your finger over the slider to either end,
the power-LED dimms or brighthens.
SLIDE-ON ( p0 p1 -- ) Activate p0 & p1 for the slider SLIDER? ( -- % tf|ff ) Not touched = 0 or perc. & true DIMMER ( -- ) Adjust the brightness of a led .SLIDE ( -- ) Show the slider inner workings
TOUCH-ON ( -- ) Activate touch interface TOUCH? ( px -- f ) Flag is true when 'pin' is touched TOUCH ( px -- ) Switch led on pin touched TOUCH2 ( p1 p0 -- ) Toggle LEDs on pins p0 & p1 TOUCHTWO ( -- ) Switch two leds on pins touched
Connect the switch as shown in the schematic, load program e19c and run TOUCH.
Then, as long as you touch the switch, the onboard-LEDs are toggled.
Please take a look at the source-code. This code is a little more advanced
and it uses the watchdog interval interrupt to sample the timer A0.
TOUCH-ON ( -- ) Activate the touch interface TOUCH? ( -- f ) True when the sensor is touched SHOW ( -- ) Shows the inner workings TOUCH ( -- ) Touch switch LEDs - example
Program e19d is a more advanced and flexible driver for a capacitive switch,
and is more suitable for serious use. This example lets you specify
which IO-pin is used for the switch or slider. Note that it needs only one timer for
one or more switches, and for the slider too. The used software polls the
selected CapTouch inputs in a small and efficient interrupt routine.
This example lets you use the high four pins of port P1 as touch input!
Please read the source-code for more details.
TOUCH-ON ( -- ) Activate the touch interface TOUCH? ( px -- f ) Flag is true when px is touched TOUCH ( px -- ) Led is on, when the px is touched TOUCH2 ( p1 p0 -- ) Toggle LEDs on touching p0 & p1 TOUCHTWO ( -- ) Switch two leds on pins touched SLIDE-ON ( p0 p1 -- ) Activate p0 & p1 for the slider SLIDER? ( -- % tf|ff ) Not touched = 0 or perc. & true DIMMER ( -- ) Change PWM value on pin P1.0 .SLIDE ( -- ) Slider inner workings demo MULTI ( -- ) Show both slider & switch

This example shows how to use timer‑A0 in compare mode to generate timer interrupts.
Both SMCLK (high frequency) or ACLK (low frequency) can be used to drive the timer.
|
Load the assembler before the e20 noForth programs,
the software RS232 routines are in assembler code.
|
PERIOD. Higher means slower. The default content of PERIOD is 1.
5 TO PERIOD
SMCLK-ON ( -- ) Activate timer-A0 with SMCLK ACLK-ON ( -- ) Activate timer-A0 with ACLK TIMER-OFF ( -- ) Deactivate timer-A0
|
Load the assembler before the e21 noForth program,
the interrupt-routines are in assembler code.
|
SERVO ( pos srv -- )
where pos can have a value between 0 and 200. The word MOVE-SERVOS
changes the position of each servo endlessly.

SERVO-ON ( -- ) Activate servo interrupt SERVO-OFF ( -- ) Deactivate servo interrupt SERVO ( pos srv -- ) Set servo 'srv' to 'pos' (0-200) MOVE-SERVOS ( -- ) Move both servos endlesslyAbout RC servos
|
This example implements Pulse Width Modulation on 3 outputs using timer-A0. It can be used to control items like lamps, electric motors or LEDs. Load the assembler before the e22 noForth program.
|
SHOW-PWM changes all 3 outputs differently every 64 milliseconds.
Forth command:
>POWER ( pow n ) Set the power of output 'n' to 'pow'
'pow' is between 0-100
SHOW-PWM ( -- ) Change all three PWM outputs endlessly
| Load the assembler before the e23 noForth program,
the interrupt routine is in assembler code.
|
LED ( -- ) starts the demo
This example shows how to initialize and use the watchdog-timer.
WATCHDOG ( u -- )Test watchdog trigger point to 'u' milliseconds. In steps of 160 millisec.
When used as an interval-timer, the watchdog again counts down to zero (see chapter 24).
But, instead of a restart, triggers an interrupt.
In this example, the watchdog interrupt lowers the value MS) to zero.
INTERVAL ( ms -- )Switch red LED on when interval starts, green LED goes on when the interval is finished.
This is a fun example. It shows how to make a egel-kit or launchpad react to a remote-control of a television!
If you use a launchpad, there is a bit of fiddling with hardware, but the result is an excellent base for extensive
remote-control functionality.
The IR-receiver must be a 36 kHz, 3 Volt version, like TSOP34536.
RC-TEST, connect 6 LEDs or a LED-module to P2.2 to P2.7.
RC-TEST shows the received 6-bits key-code on the LEDs.
RC-POWER ( -- ) Control output P2.4 using on/off key RC-TEST ( -- ) Display RC-5 commands binary on LED-array
Above: Output from the RC-5 receiver; below: Toggle of the power LED.
Measuring is a standard task for a micro-controller.
This example shows how to measure time-periods, frequency and rotational speed (in RPM = revolutions per minute).
| Load the assembler before the e27 noForth programs,
the interrupt routines are in assembler code.
|
PERIOD to start the period-measurement.
Pressing S2 twice toggles P1.3 twice and the time-interval between the two toggles is measured and printed.
The length of an external pulse connected to p1.3 can also be measured. Please note that the pulse must be 3.3 Volt.
Suitable conversion must be done when not. Add amplification when the signal is too small, add an attenuator-network
when the signal is too large.
The code of example e27b can be tested with a second Egel kit or Launchpad. Run program e14 on the second Egel kit/launchpad
and connect output P1.6 of the e14 example to input P1.3 of this example.
Then type: 100HZ TONE0 in the E14 example, type FREQUENCY in the e27b example and see
the results on your screen.
RPM.
PERIOD ( -- ) \ File e27a, measure time-period FREQUENCY ( -- ) \ File e27b, measure frequency RPM ( -- ) \ File e27c, measure rotation speed

|
Load the assembler before the e30 noForth programs,
some USCI routines are in assembler code.
|
RUNNER1 ( -- ) Running light with output only RUNNER2 ( -- ) Running light with switch input too SHOW ( -- ) Show I2C input on outputsMore: Wikipedia on I2C and I2C.org
|
Please load the correct I2C-primitives first
|
EEPROM-DEMO ( -- ) Sample input of the switches to EEPROM
for 10s, and then display them.
|
Please load the correct I2C-primitives first
|
TIMER ( -- ) Flash LEDs every 10 seconds ALARM ( sec min -- ) Alarm goes off after given time CLOCK ( -- ) Show 24-hour clock SET-CLOCK ( sec min hr -- ) Set 24-hour clockMore: Wikipedia on I2C and I2C.org
|
Please load the correct I2C-primitives first
|
ADC ( +n -- byte ) Read ADC input '+n' DAC ( byte -- ) Write DAC output with 'byte' ANALOG ( -- ) Output analog data on LEDsMore: Wikipedia on I2C and I2C.org
This example demonstrates the use of a real-time-clock (=RTC) and the use of an EEPROM, both connected via I2C
| Please load the correct I2C-primitives first
|
TIMER ( sec min -- ) prints 'READY' after given time
ALARM ( -- ) Alarm goes off 10 seconds
SET-CLOCK ( sec min hr -- ) Set 24-hour clock
CLOCK ( -- ) Show 24-hour clock
GATHER ( -- ) Store clock-data in EEPROM
till a key is pressed
SHOW ( -- ) Show data stored in EEPROM
This example shows how to connect to a 16 by 2 character LCD using an I2C IO-driver PCF8574 and how to use it.
| Please load the correct I2C-primitives first
|
LCD-SETUP ( -- ) Initialize the LCD LCD-EMIT ( ch -- ) Send character 'ch' to the LCD LCD-TYPE ( adr u -- ) Type string 'a' 'u' to the LCD DEMO ( -- ) Type a message on the LCD
In this example we show how to use the YL-40 module. It contains a PCF8591 analog to digital converter, and is connected to a LDR,
a thermistor, a potentiometer and a LED as output.
It is a great module to start experimenting with analog to digital converters.
| Please load the correct I2C-primitives first
|
0 ADC on pin AIN0 | = LDR |
1 ADC on pin AIN1 | = thermistor |
2 ADC on pin AIN2 | = free |
3 ADC on pin AIN3 | = potentiometer |
DAC on pin AOUT | = LED |
ADC ( +n -- byte ) Read ADC input '+n' leaving 'byte' DAC ( byte -- ) Write 'byte' to DAC output ANALOG ( +n -- ) Read input '+n' send to screen & DAC
These files are intended as a basis for constructing your own I2C applications, either bit-bang or USCI.
Note that the bit-bang implementation does not handle clock-bit stretching.
Controlling one or more micro-controllers (MPU) by another MPU is very useful (and fun) functionality.
This example shows how to do that with the I2C protocol. This is obviously an advanced topic.
But the source-code is well structured and commented in detail, and with some effort you should be able to understand how it works.
You can learn a lot in this way.
|
Load the assembler before the e38a/b noForth programs, the I2C routines are in assembler code.
|
Connect two or more MSP-EXP430G2 Launchpads to each other. You may also use Egel Kits (from the Forth users group).
Add 6 or 8 LEDs and connect VCC, GND, P1.7 to SDA and P1.6 to SCL in the usual way.
Connect the SDA and SCL-lines of the master and slave(s) to each other.
Don t forget the two line-protection resistors of 220 ohm for each slave. See schematics.
Program e38a implements the I2C master, program e38b the I2C slave.
For both versions there are examples of in- and output (see the list below).
The master/slave Forth commands are always used in pairs (see the table in the source-code).
One MPU executes a word from the first row in the table, the other has to execute the corresponding word from the second row.
MASTER-TRIO implements a master with two slaves!
The code is pretty solid, >SLAVE and SLAVE> give an error-message when the addressed device does not respond.
MASTER-OUT ( -- ) Show a running light on LEDs & slave 1
MASTER-IN ( -- ) Change flash speed with data from slave
MASTER-IO ( -- ) Running light, delay with S2 from slave
MASTER-TRIO ( -- ) Count on slave 1, running light slave 2
Change speed with S2 from slave 1
SLAVE-IN1 ( -- ) Display data from master SLAVE-OUT ( -- ) Send S2 to master, flash LEDs SLAVE-IO ( -- ) Get & send data from/to master SLAVE-IN2 ( -- ) Display data in slave 2

This chapter is the SPI-based pendant of chapter 38. It shows the control of one MPU by another MPU using the SPI-protocol.
The SPI-protocol is much faster than I2C, and is thus more suitable when high speed is important.
Wiring:SPI-SLAVE1 and SPI-MASTER on the other unit.
SPI-MASTER ( -- ) Send binary counter, display answer SPI-SLAVE1 ( -- ) Display received data & sent it back SPI-SLAVE2 ( -- ) Translation of TI-example
About SPI
In this example analog data is collected and send from one MPU to another using the SPI-protocol.
Connect the SPI lines of USCI-B0 P1.5, P1.6 & P1.7 to the same pins on the other board and connect 6 LEDs to P2.
Start SLAVE on the unit with the LED-board and MASTER on the other.
P1.3 on the master-board is used as analog input, it is wired to a 4k7 potmeter between VCC (3,3 volt) and ground (see schematics).
MASTER ( -- ) Send ADC to slave, receive data from slave SLAVE ( -- ) Display ADC, sent count back
About SPI
The display module has two 74HC595
shift register chips as drivers.
| OE\ | = low enables the outputs |
| MR | = master-reset low resets the shift-register |
| DS | = data input |
| SHCP | = clock input |
| STCP | = Strobe acts on a positive transition |
COUNTER ( -- ) Run counter on LED-display TU. ( u -- ) Print number on LED-display TCLR ( -- ) Clear LED-display TDASH ( -- ) Print dashes on LED-display TMESSAGE ( -- ) Print message on LED-display
This example is great fun, it shows how to wirelessly connect two boards with each other on the 2.4 GHz band!
|
Load the assembler before the e43 noForth programs,
the SPI routines are in assembler code.
|
For a Launchpad, connect the SPI lines of USCI-B0 with the nRF24L01+ in this way:
P1.5 = CLOCKPULSE,
On the Egel-kit you can simply put the nRF24L01-module on the connector marked nRF24L01.
Connect a powerLED & 47 ohm resistor, and a LDR & 2k2 resistor for the remote control examples (see schematics).
SPI reg: SLAU144J.PDF page 445ff.
CHECK, all commands are always used in pairs. One of the pair on each board.
All commands are stack-neutral.
CHECK ( -- )
| Check for disturbances on the selected RF-channel (channel 112 or 128). |
CONTROL & LAMP
| Simple one way remote control. |
NRF-SEND & NRF-REC
| A counter demo, displayed on both boards (bi-directional communication). |
REMOTE & RECEIVER
| Remote controlled lamp, with lamp status feedback. |
Connect a WS2812 LED-strip with 4 to 1000 LEDs to P1.7, +5 volt and ground.
Program e44a is the easier to understand version of the WS2812
LED-controller. The program e44b has a virtual field length as extra.
With this field function longer LED strings can be addressed in smaller chunks, which are repeated to the end of the LED string.
It is possible to control over a 1000 LEDs with this code. It takes about 33ms to address this much LEDs.
Just type: dm 1000 >LEDS or the actual number of LEDs connected.
>LEDS ( +n -- ) Set number of LEDs connected ALL ( dc -- ) Color (double number) to all LEDs S1 S2 S3 ( -- ) Three colorful shift-reg. examples S4 S5 ( -- ) Two multi-dot shift-register examples RAINBOW ( -- ) Set a rainbow divided over all LEDsA few of the Forth user commands for e44b:
>FIELD ( +n -- ) Set LED field length MSHIFT ( -- ) Multi-dot shift-register example VOLUME ( -- ) Volume effect example BOUNCE ( -- ) Bouncing dot example RAINBOW ( -- ) Shift a rainbow divided over all LEDs

MSP430 micro-controllers are known for their low power-consumption. This example shows the different
Low Power Modes
and the use of a hardware interrupt for wake-up.
|
The assembler must be loaded before the e50 noForth program.
|
The sleep numbers indicate the low power mode.
SLEEP0 ( -- ) Test LPM mode 0 SLEEP2 ( -- ) Test LPM mode 2 SLEEP3 ( -- ) Test LPM mode 3 SLEEP4 ( -- ) Test LPM mode 4A lecture on Low Power Modes and about Launchpad power usage
This example shows the use of the watchdog interval-timer for wake-up.
MS# to zero.
MS ( ms -- ) Wait in LPM0
INTERVAL ( ms -- ) Use the LEDs
to show the interval
|
The assembler must be loaded before the e52 noForth program.
|
Current while full running!
SLEEP0 ( -- ) Test LPM mode 0 SLEEP2 ( -- ) Test LPM mode 2 SLEEP3 ( -- ) Test LPM mode 3
The assembler must be loaded before the e53 noForth program.
|
Obviously, for connections and an explanation see chapter 26.
This version uses only 1/6th of power compared to the original version.
But power-consumption could be even lower by using an infrared receiver with lower power-consumption, or by using more clever software tricks.
To misquote Clint Eastwood: 'You feel clever?... punk?...'
RC-POWER ( -- ) Control output P2.4 RC-TEST ( -- ) Display RC-5 commands on LEDs
|
The assembler must be loaded before the e54 noForth program.
|
SLEEP implemented at the beginning of the forth word ACCEPT (see source).
This allows for an even lower power-consumption while waiting for a KEY.
But the example also works for a standard noForth version.OK register (bit 3).
8 ADR OK **BIS \ set bit 3
8 ADR OK **BIC \ clear bit 3
If bit 3 of the OK register is cleared, noForth uses LPM0 while waiting for a key.
Most clocks keep running in LPM0, the result is that the CPU can wake almost instantaneously from this mode but less energy is saved.
LPM4 for SLEEP and LPM2 while waiting for a key.
This saves more energy, at the cost of a longer wake-up time which usually is of no consequence.
The word MS1 always uses LPM0.
WORDS.
DCO freq. LPM4-sleep LPM2 LPM0 1 MHz 0.0007mA 0.020mA/0.18mA 0.070mA/0.18mA 8 MHz 0.0007mA 0.025mA/0.50mA 0.346mA/0.50mA 16 MHz 0.0007mA 0.033mA/0.83mA 0.682mA/0.83mAPlease note that the actual power-consumption is dependent on the program running. If a program is not waiting, for instance during long calculations, low-power noForth consumes as much power as standard noForth. But in reality most programs wait most of the time.
1MHZ ( -- ) DCO on 1 MHz 16MHZ ( -- ) DCO on 16 MHz SLEEP-ON ( -- ) Install LPM version of noForth SLEEP-OFF ( -- ) Back to normal noForth version MS1 ( ms -- ) LPM version of MS SLEEP ( -- ) Go to LPM mode 4

Graphics & bold 8x14 characters
This example demonstrates the display of both text and pictures on a graphic display connected using the I2C protocol.
Note that, the I2C clock maybe set to 400 kHz, the default speed is 100 kHz!
Just add this line in the word SETUP-I2C and comment the other bitrate lines out:
dm 20 6A c! \ UCB0BR0 Bitrate 400 KHz with 8 MHz DCO
| Load the USCI I2C master before the e60 noForth programs.
The software for SSD1306 driver is based on it.
|
Connect VCC to VDD on the display, Ground to GND, P1.7 to SDA and P1.6 to SCL.
The display normally functions without external pull-up resistors. If not, add two 4K7 pull-up resistors to SDA and SCL.
Thin 7x16 charactersTHIN ( -- ) Show big thin 7x16 character set
Graphic character set design & hedgehog exampleGRAPHIC ( -- ) Show graphic and custom character set SHOW ( -- ) Animated view of the hedgehog

Generating a random number reliably is surprisingly difficult.
In this chapter we demonstrate 4 different random number generators.
Included are 3 generators well known in the Forth-world, and a modern routine.
Two of the more useful routines are also coded in assembly, and comma-code for easy inclusion in your own code.
The Brodie-generator
was included in the legendary book Starting Forth by Leo Brodie.
It is easy to implement and performs reasonably, but statistically two consecutive numbers are strongly related.
Donald Knuth solved the quality-problem of the Brodie-generator by using a 33 element table to
shuffle the numbers generated by the Brodie-routine. The resulting generator produces random numbers
with fair quality. The only disadvantages are the use of space for the table and the lower speed.
The noted
LFSR-generator has a very low quality.
But it is very fast so that for tasks like robot-control it might be a good fit.
The lower bits of a LFSR generator are highly predictable for consecutive numbers.
So reducing the output to a certain range should be done with a multiply and not with a MOD.
( see CHOOSE below )
Prof. Marsaglia is the developer of the diehard randomization test-suit.
A generator invented by him is the 4th generator in the list.
It generates normally distributed random numbers with low predictability.
On top of that, all bits are equally random.
As the method is simple and pretty fast, it is a true work-horse method.
CHOOSE takes an unsigned
number from stack, calls a random-generator and reduces the output to between 0 and the number 1.
So 6 CHOOSE will generate numbers between 0 and 5.
CHOOSE uses a multiply to reduce the range.
This is essential as some methods generate random numbers with predictable lower bits.
: DICE 6 choose 1+ . ;
To use it load any of the random generators from the source, load CHOOSE and the above code.
A more graphical way is shown at the end of this chapter.
RANDOM ( u ) u is a 16b pseudo random number CHOOSE ( u1 u2 ) 0 <= u2 < u1
| Brodie: | A faint diagonal pattern is visible on squinting your eyes |
| Knuth: | No pattern is visible |
| LFSR: | A very strong pattern is visible ? the generator is of low quality. |
| Marsaglia: | No pattern is visible |
GO ( -- ) Initializes the OLED-display
RANDOMTEST ( -- ) Show the pattern created by the random-
generator on the OLED-screen
GO, DICE and SHOW2 show a new number after each call.
DICE ( -- ) Throw a dice and show SHOW2 ( -- ) Throw a dice and show with some effects

Cut two small pieces from a tin can, each about 3x3 cm (not critical).
Solder a 20cm long lead to each of the pieces. Cover one of the pieces on both sides with duct tape,
put the second piece on top and fix it with a third piece of duct tape.
The two pieces of tin are now separated by a single layer of duct tape.
And that's it, you have constructed a capacitive switch!
It is important that the metal pieces do NOT touch each other directly.
Mechanically more stable capacitive switches can be made from PCB-material.
Size and form are not very critical.
Connect the switch as shown in the schematic, load program e80a and run TOUCH.
Than, as long as you touch the switch, the onboard-LEDs are toggled.
Please take a look at the source-code. It is pretty short and it contains a neat trick.
Normally a capacitive switch needs calibrating, but this software is self-calibrating.
In addition, it will also handle any drift of the capacity of the switch.
This functionality takes only a few line of noForth code and works so well that the
software functions with almost any reasonable switch.
Which is proof that beautiful things can happen when you mix the features of
the MSP430 with the power of noForth!
TOUCH? ( -- f ) True when the sensor is touched SHOW ( -- ) Shows the inner workings TOUCH ( -- ) Touch and switch LED example
Cut two oblong pieces of tin from a tin can, about 2x7cm.
Cut one of the pieces into 2 long triangles.
Solder 3 leads of ~20cm to the three pieces.
Cover both sides of the oblong piece with duct tape.
Add the 2 triangular pieces, making sure that non of the 3 pieces make contact,
and fix these also with duct tape.
Connect the leads according to the schematic
Load program e80b and run DIMMER. Then, if you touch the slider somewhere in the center of
its surface a LED on the board should be on. If you slide your finger to one of the de sides,
the LED should change brightness.
SLIDER% ( -- %|-1 ) Not touched=-1 or percentage DIMMER ( -- ) Adjust brightness of a led SHOW-SLIDER ( -- ) Show slider inner workings
TOUCH? ( pin -- f ) Flag is true when pin is touched TOUCH ( pin -- ) Switch led on pin touched TOUCH2 ( p1 p0 -- ) Toggle LEDs on pins p0 & p1 TOUCHTWO ( -- ) Switch two leds on pins touched SLIDER ( -- %+1|0 ) Not touched=0 or percentage+1 DIMMER ( -- ) Change PWM value on pin P1.0 .SLIDE ( -- ) Slider inner workings demo
Connect the switch as shown in the schematic, load program e80d and run TOUCH.
Than, as long as you touch the switch, the onboard-LEDs are toggled.
Please take a look at the source-code. This code is a little more advanced,
it uses the watchdog interval interrupt to sample timer-A3.
TOUCH? ( -- f ) True when sensor is touched SHOW ( -- ) Shows the inner workings TOUCH ( -- ) Touch switch LED example
Most MSP430FRxxxx MPUs contain a 12-bit analog-to-digital converter (ADC12).
This 12-bit resolution is 4 times more accurate than its 10-bit predecessor.
A stable reference-voltage is essential for the ADC12 to function accurately.
It is possible to use VCC or one of several internal reference-voltages.
The examples presented here show the use the VCC and the 2.5 V reference-voltage.
Connect the potentiometer to VCC, GND and the center wire to P3.0 (A12).
Connect the 6 LEDs to P1.0 to P1.5 and the 100 Ohm resistor to GND.
Finally load program 81a and run LEDS.
If you turn the potentiometer, the LEDs will show the output of the ADC12.
ADC-ON ( -- ) Activate ADC12 unit
ADC-REF ( ax -- +n ) Use VREF or VCC to convert input ax,
the result +n
LEDS ( -- ) Show the input from A12 binary
on the LEDs
Leave the potentiometer connected to P3.0 (A12),
Load program e81b on top of program e81a and run BATTERY1.
Then, as long as the voltage is higher than 2.8 Volt, the LEDs react,
as before, to the potentiometer.
But when the voltage drops below 2.8 Volt things are different.
The CPU saves energy by switching off the LEDs and by going to low power mode 3 (LPM3) in six steps.
Connect a multimeter and you can actually see what happens with the current in each step.
The word BATTERY2 does the same but goes to LPM4.
Word BATTERY3 uses only 5 steps to do the same, and with that shows that step 2 in the other code is in fact superfluous.
Together these words very nicely demonstrate the effect of the MSP430 low power features and the possibilities of the ADC12.
And all this functionality with no more than a few lines of noForth code.
BATTERY1 ( -- ) Show A12 on the LEDs, switch MPU to
LMP3 when the voltage is below 2.8 Volt.
BATTERY2 ( -- ) Idem BATTERY1 but to LPM4.
BATTERY3 ( -- ) Idem BATTERY2 but shorter.
Load program e81c on top of program e81a.
The internal calibration values handle the accuracy over the range of measurement.
But the user has to do a one-time calibration of the offset. This is easy.
Check with a reliable thermometer the difference between that thermometer
and the value returned by the MSP430.
And then change the calibration-value accordingly (see source-code e81c).
The calibration-value is in 10th of degree.
So if the MSP430 reports 2 degrees too low, raise the calibration value with 20.
If it is 1 degree to high, subtract 10 from the calibration-value.
Once the offset is set correctly, the device measures accurately.
The conversion formula:
INIT-THERMO ( -- ) Activate ADC as temperature sensor
THERMO ( -- temp ) Read temperature sensor
.THERMOMETER ( temp -- ) Print temp. in half degree
Celcius, Fahrenheit or Kelvin
C? ( -- x ) Value wich selects temperature
output style for .THERMOMETER
ALARM ( -- ) Signal when temp. is over 24 degrees
UNFILTERED ( -- ) Print raw temperature in half degree MOVING ( -- ) Temperature using moving average AVERAGE ( -- ) Temp. using average of 8 values
| 4 | 5 | 4 | 2 | 4 | 70 | 4 | 2 | 4 |
| 2 | 2 | 4 | 4 | 4 | 4 | 4 | 5 | 70 |
MEDIAN1 ( -- ) Temperature using median MEDIAN2 ( -- ) Temp. using fast semi-median

DATALOGGER
starts automatically after a reset.
The small walking robot has two legs, using four servos.
It is wireless controlled thru
bluetooth.
The code comes from the first eight chapters. The result is a cute walking robot.
Servo tester on Egel-kit
TESTER.
BIPED-ON ( -- ) - Activate Biped BIPED-OFF ( -- ) - Deactivate Biped WOBBLE ( u -- ) - Wobble u times WALK ( u -- ) - Walk forward u steps HELLO ( -- ) - Wave helloLiPo under voltage protection
Basic Biped Forth commands,
REST RIGHT-UP LEFT-UP RIGHT-FORW LEFT-FORW DOWN WAVE TOES RESTThese words can be used to build more complex functions. The code is kept very simple, so there is plenty room for improvement!
DEMO.
This starts the remote control DEMO and boots automatically after a reset.
|
| Load the assembler before the e102 noForth programs.
The program has three parts: a. 16MHz version of the RC-5 decoder b. WS2812 driver using USCI B0 c. User interface build around the SBCRP520 (photo) |
Forth command: WS2812 ( -- )

The small walking robot has two legs, using four servos.
It is wireless controlled thru Bluetooth.
The code comes from the first thirteen chapters.
The result is a cute autonomous walking robot.
The used sensor is a HC-SR04 ultrasonic distance meter.
When using a 7,4 Volt 900mAh Li-Po accu, a cheap
LM2596 buck power supply and build a
Li-Po undervoltage protection as shown in the schematic on the left.
The biped has plenty of power to play a very long time.
The Forth commands are:
BIPED-ON ( -- ) Activate Biped BIPED-OFF ( -- ) Deactivate Biped WOBBLE ( u -- ) Wobble u times WALK ( u -- ) Walk forward u steps LEFT ( u -- ) Turn left u steps RIGHT ( u -- ) Turn right u steps HELLO ( -- ) Wave hello DEMO ( -- ) Remote control demo
Some basic Biped (stack neutral) Forth commands:
REST RIGHT-UP LEFT-UP RIGHT-FORW LEFT-FORW DOWN WAVE TOES RESTThese words may be used to build more complex functions.
The main noForth word DEMO is a key interpreter,
that does handle one-touch commands, by means of a remote control.
It will start automatically after a reset.
More info about the built-in BSL in SLAU319L.PDF
Place an 20-pin ziff-socket on the Egel kit as shown on the photo on top.
Add a green and red LED connect them using the schematic. Then connect the
six wires for the programmer to the ziff socket. Finally connect a 32kHz
crystal to pin 18 & 19 of the ziff socket. Information about the built-in
capacitators see SLAU144J.PDF page 274 and beyond.
The programmer now is ready to clone itself to an other MSP430G2553.
![]() |
Load the assembler before the e111 noForth program,
there are several routines in assembler code.
|
The APP-vector is filled with the DCO restoration program.
The CLONE-program ends with a reset of the "clone". When the DCO
constants where erased, they are restored immediatly by executing the APP-vector.
EMPTY-PASS ( -- ) Set password to all $FF MODIFY-PASS ( a -- ) Set password, 'a' is reset vector CLONE ( -- ) Copy yourself to another MSP430G2553
| Load the noforth assembler before the e112 noForth programs.
Hexapod version 2 |
First load the assembler, then e112b to add extra RS232 routines.
After that connect an USB cable, then download the rest of the software at 38k4.
After this is done type: BLUETOOTH and FREEZE now the robot starts up,
using the Bluetooth connection at 9600 baud.
Hexapod controller schematicsREADY ( -- ) Startup the hexapod carefully WALK ( u -- ) Walk forward u steps BACKW ( u -- ) Walk backward u steps REST2 ( u -- ) Go to resting position 2
TESTER ( -- ) A servo tester using a potmeter at P1.7
Hexapod version 2
LSTEPS ( u -- ) Crawl forward
HSTEPS ( u -- ) Walk on hi heels
ANT ( -- ) Simulation of an ANT walking
Original program: Gerard Vriens