Digital I/O Wildcard User Guide
<< Previous |
Forth Code to control the Digital I/O Wildcard
HEX
1 | CONSTANT OUTPUT_HIGH |
0 | CONSTANT OUTPUT_LOW |
|
C000
| CONSTANT NIBBLE_0_ADDR
| \ Lines 0-3. |
C001
| CONSTANT NIBBLE_1_ADDR
| \ Lines 4-7. |
C002
| CONSTANT NIBBLE_2_ADDR
| \ Lines 8-11. |
C003
| CONSTANT NIBBLE_3_ADDR
| \ Lines 12-15. |
C004
| CONSTANT NIBBLE_4_ADDR
| \ Lines 16-19. Inputs only. |
1 | CONSTANT LINE_0 |
2 | CONSTANT LINE_1 |
4 | CONSTANT LINE_2 |
8 | CONSTANT LINE_3 |
1 | CONSTANT LINE_4 |
2 | CONSTANT LINE_5 |
4 | CONSTANT LINE_6 |
8 | CONSTANT LINE_7 |
1 | CONSTANT LINE_8 |
2 | CONSTANT LINE_9 |
4 | CONSTANT LINE_10 |
8 | CONSTANT LINE_11 |
1 | CONSTANT LINE_12 |
2 | CONSTANT LINE_13 |
4 | CONSTANT LINE_14 |
8 | CONSTANT LINE_15 |
: Control_DIO ( byte1\u\byte2\byte3 -- ) |
\ Sets I/O line of specified nibble to the appropriate state (high or low). |
\ byte1 = module number, u = nibble address, byte2 = line, byte3 = state. |
\ Valid module numbers are 0-7. |
\ Valid nibble addresses are NIBBLE_0_ADDR to NIBBLE_3_ADDR. |
\ Valid lines are LINE_0 to LINE_15 |
\ Valid states are OUTPUT_HIGH or OUTPUT_LOW |
locals{ &state &line &nibble_addr &module } |
&state |
IF | \ set line high |
&line &nibble_addr &module SET.BITS
ELSE | \ set line low |
&line &nibble_addr &module CLEAR.BITS |
ENDIF |
; |
: Read_Nibble ( byte1\u –- byte2 | byte1 = module number, u = nibble addr )
\ Reads the current state of the Digital I/O nibble.
\ Valid module numbers are 0-7.
\ Valid nibble addresses are NIBBLE_0_ADDR to NIBBLE_4_ADDR.
\ Returns an unsigned character whose least significant nibble represents
\ the four I/O lines. For example, if nibble 1 is read and a 1 is returned
\ (0001 in binary), then line 4 is high and lines 5-7 are low. If 12 is
\ returned (1100 in binary) after reading nibble 3, then lines 12 and 13 are
\ low and lines 14 and 15 are high. The four most significant bits of the
\ returned byte do not matter.
locals{ &nibble_addr &module }
&nibble_addr &module C@
;
| | | | | | | | | | | | | | |
Conclusion
Now you are ready to start using your Digital I/O Wildcard. All of the software routines listed in this document are also on the distribution CD that accompanies each Wildcard.
<< Previous |
|