From: Matthias T. <mt...@we...> - 2011-04-10 08:16:34
|
Hi Hannu, >>> 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 > Just to make sure that I understood this correctly, we define main > word which has loop and executes led-on word, puts 1000 to stack, > waits one second turns led off waits and reads from serial port. The > key? word puts true if there is input. Second line makes main > executed with turnkey word which is like autoexec.bat :) Exactly. One side effect should be noted however: You loose the command prompt. Moreover: if you send a character and the loop exits, the system will continue with QUIT. And QUIT is basically the forth interpreter, which will operate on a not-working terminal IO (no interrupts enabled, to usart line settings etc). May look like a crash. So the following definition is much better (note the port-init and the again instead of the key? until). : main ( -- ) port-init begin led-on 1000 ms led-off 1000 ms again ; port-init has to setup the atemga ports for output. >> >> 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. > > True that. I need to check exsamples and study more. Right now I have > questions in my mind. 1) Which registers I can use with ASM without > pushing and popping them from stack. You are save with all registers labeled tempx in the sources (r14 - r21). Others should be saved with push/pop. For some registers it may not strictly nessecairy, but I'd recommend it. > 2) How do I create variable so > that for exsample ISR can increment counter and I can use it in > forth. Just declare it as a variable. variable counter If you call counter afterwards, you get the RAM address of it and can use with the assembler. Keep in mind that counter is 2 bytes, low byte first. > 3) How to add portions of ASM and specify words for it. you may want to examine the assembler-test.frt file and (probably more interesting) the file keyboard.frt in http://amforth.svn.sourceforge.net/viewvc/amforth/applications/lcd-ps2/blocks/ regarding the timer: this is one of the special cases which can be implemented in forth without assembler. I have no idea what the int0 part should do, but the timer part is fine in pure forth. the file interrupt-test.frt is a (poorly documented) example > > Last of my questions is there way to see how some word has been > defined? You have all the sources. Nothing is hidden. And almost every word has its own source file. Why do you need SEE ?? > > And last I like to share this idea. in avr-libc documentation there > is a the simple demo project. It is interrupt driven and makes PWM. Work is in progress to write something beyond the user guide and some example solutions. Maybe the author can be argued to reveal its progress (no, its not me ;) > But now I think I'll stop writing mail and start trying on that > dimmer what I know about forth. ATMega88 is the victim this time. Pick up an atmega168 or bigger, amforth is actually beyond the 8KB flash size limits of that device... (some early versions will work however, they are smaller in code size) Matthias |