08 2011 Ting
08 2011 Ting
C. H. Ting
August 27, 2011
SVFIG
Summary
eForth 1 Implementations
eForth 2 Implementations
ATmega328P
AmForth
328eForth v2.1
AVR Studio 4 Tool Suite
HyperTerminal
Bill Ragsdale’s Applications
eForth Tutorials
Conclusion
Interrupts on ATmega328P
Interrupt 1 at 0, Reset
Interrupt 2 at 2, External INT0
Interrupt 3 at 4, External INT1
…
Interrupt 19 at $24, UART RX receive
…
Interrupt 26 at $32, SPM Ready
Interrupts on ATmega328P
Global Interrupt Enable, bit 7 in SREG at $5F
Each interrupting device has an interrupt
enable bit in its status register.
An interrupt cause a CALL to its interrupt
service routine, and global interrupt is
disabled.
At the end of the interrupt service routine, a
RETI instruction re-enables global interrupt.
328eForth Provisions for
Interrupts
Flash memory 0-$7F is reserved for
reset and interrupts
Subroutine threading allows interrupt
service routines to be written in Forth.
Only a few more commands are
necessary to write interrupt service
routines.
Interrupt.txt
INIT-VECTORS
INTERRUPT ( addr # -- )
RETI,
SEI,
CLI,
NOP,
PUSH-SREG
POP-SREG
A Trivial Example
Interrupt_1.txt
Use External Interrupt INT0 at PD2 on
Pin 4
On interrupt, increment a variable CNT
Interrupt on changes at PD2
PD2 can be changed by writing to
PIND2
Demo
Download 328eForth v.2.20
Load interrupt.txt
Load interrupt_1.txt
Type:
ENABLE
ENABLE-INT0
CNT ?
FLIP CNT ?
FLIP CNT ?
…
A Non-Trivial Example
328eForth v.2.20 polls UART receiver
for KEY.
328eForth v2.21 is driven by UART
receiver interrupts.
eForth runs in the background by
receiver interrupts.
Application runs in the foreground task.
328eForth220 Interpreter
: QUIT
Initialize stacks
Initialize terminal input buffer
BEGIN QUERY EVAL AGAIN
;