From: Kalus M. <mic...@on...> - 2011-04-08 19:40:12
|
Hi Hannu. Am 08.04.2011 um 06:41 schrieb Hannu Vuolasaho: > Q: Is somewhere simple LED blinker example? > A: saw examples directory and studying those programs. But the > workflow from forth code to standalone program is missing \ example: : main ( -- ) begin led-on 1000 ms led-off 1000 ms key? until ; ' main is turnkey Mathias made a vector in eeprom called TURNKEY that holds the execution token of the forth word to start with after booting amforth on a device. Mathias: maybe its a god idea to put it in faq. > Q: How do I store the forth program to MCU so that when it starts I > don't need use serial port to upload it? > A: Well This is same question as previous. 1. flash amforth into device 2. develop your forth code on the device. Since it is in flash, is permanent. 3. set turnkey, Since it is in eeprom its permanent too. 4. turn off power of device. Turn power on, it will run your application. Step 2 can be very strenuous. amforth is very simple, it is for tiny devices. I use gforth or some other "big" forth systems to develop most of the forth code before it goes down the device and runs on amforth. Since amforth is standard forth, this works nice. You have to simulate features of the device. Fine tuning then is done interactive on the device itself. So its kind of iteration using gforth, test it in amforth on the device, continue this loop modifying code until it does the job. Usually it takes a lot of re-flashing amforth till everything is works well. > > Q: If my program get's into infinite loop is there any other way > except reset to return to prompt? > A: No. So define the main loop abortion condition first, then add its task. Common constructs are: : main ( -- ) begin ... key? until ; \ test for any key : main ( -- ) begin ." ." 1000 ms key? dup if drop key $03 = then until ; \ test ctrl-c > Q: Register read and write? > A: 1 PIN_NUMBER lshift REGISTER_NAME or! to set one bit. Are > registers normally included? ( in C #include "avr/io.h" is needed) No. (as far as I know) > Q: How interrupts are used? > A: First there has to be word for interrupt and it has to be told > to sytem so that it knows what to run on interrupt and then > registers are written to enable that interrupt. Religious content ;-) My opinion: Never use (highlevel) forth on a embedded device to serve an interrupt. Use the method that comes with the device. On atmega: place a jump to code fragment that will set a variable. If service may be slow, serve that variable in your forth task later. > Q: sleepmodes and multitasking? > A: After reading technical manual which is nice document I was left > little uncertain about multitasking. It is co-operative and pause > causes context change. By default pause was defined as nop? I'm > interested this since I noticed from archives that this was used to > save power. There is a nice multitasker wordset, I myself did not use it. To all: Would a simple ' sleep is pause work to put device into powersave mode? > Q: Can Amforth used as calculator? > A: Instead of using dc to calculate time to next coffee break forth > prompt over serial cable could be used for that. Or can it? You will have to set up a real time clock in your device first I guess, using a timer interrupt to count down the seconds, minutes, hours. Michael |