p9
22-Nov-10
expandIO-USB
HW148-18
www.firmwarefactory.com
The interrupts should be configured as high priority, as
they are by default.
Example using interrupt-on-change:
98 81 00 00
Command: Read Port B (Clears any
mismatch condition – refer to base
microcontroller data sheet)
98 81 3F 00 Response: Port B is 0x3F
9B F2 00 00
Command: Clear RBIF
9B F2 00 00 Response: Cleared RBIF
9B F2 03 01
Command: Set RBIE
9B F2 03 01 Response: Set RBIE
95 00 00 00 Response – An interrupt occurred
9B F2 00 00
Command: Clear RBIF
9B F2 00 00 Response: Cleared RBIF
9B F2 03 01
Command: Re-Set RBIE
9B F2 03 01 Response: Re-Set RBIE
95 00 00 00 Response – An interrupt occurred
Wait
The identifier WAIT (0xA9) waits until a register bit
changes or a timeout occurs.
Byte 1 indicates the
register and byte 2 bits 0-2 indicates the bit (0-7). Byte
2 bit 7 is 0 for wait until clear or 1 for wait until set. Byte
3 is the timeout in milliseconds. Actual timeout might
take slightly more time than specified, but never less.
In the response, byte 3 will be the number of
milliseconds remaining before the timeout would have
occurred, or 0 if it did occur. The timeout is required, as
USB commands are not processed during wait periods.
Example:
A9 81 83 FF
Command – wait for Port B bit 3 to set
or 255ms to elapse
A9 81 83 00 Response – timed out
Matrix Scan
The identifier SCANMATRIX (0xAA) configures a
keyboard matrix scan on two ports. Byte 1 bits 4-7
indicates the scan port and byte 1 bits 0-3 indicate the
data port (Disable=0000, A=0001, B=0010… for both).
Byte 2 is a mask which indicates which bits to enable on
the scan port. Byte 3 is a mask which indicates which
bits to enable on the data port. Only one scan operation
be in progress at any one time.
Once this command is sent, all enabled pins on the first
port are tri-stated. When expandIO-USB is idle, it will
scan these outputs by setting them one by one to a high
output state and observing the state of the input port. If
the state of the input port (for a given scan line on the
output port) has changed since the last scan, a
SCANMATRIX response will be generated unprompted.
Byte 1 will indicate the output port bit and byte 2 will
indicate the input port value.
AA 23 07 FF
Command – Set Port B bits 0-3 out,
all of Port C in
AA 23 07 FF Response – Confirm command
AA 03 7B 00 Response – Port C changed to 7B
when Port B bit 3 high
AA 03 73 00 Response – Port C changed to 73
when Port B bit 3 high
AA 00 00 00
Command – Stop scanning
AA 00 00 00 Response – Confirm command
A typical matrix scan circuit is shown in figure 6. If it is
necessary to correctly detect if more than one key is
pressed at a time, line isolation diodes as shown in
figure 7 will be required. To avoid the need for switch
de-bouncing, scans are only made every 25 ms.
Figure 6
Scan lines
.
Input
lines
22k
Vss
.
Figure 7
Scan lines
Input
lines
.
22k
Vss
.
Multiplex Output
The
identifier
CAMULTIPLEX
(0xAB)
and
CCMULTIPLEX (0xAE) configure a display multiplex on
two ports. Byte 1 bits 4-7 indicates the scan port and
byte 1 bits 0-3 indicate the data port (Disable=0000,
A=0001, B=0010… for both). Byte 2 is a mask which
indicates which bits to enable on the scan port. Byte 3
is a mask which indicates which bits to enable on the
data port.
The identifier MPXDATA (0xAC) specifies the data to
output on the data port for each scan state. Byte 1
indicates which scan bit (0-7) the data is for and byte 2
indicates the value to output on the data port when that
scan bit is active. Inactive bits on both ports are tri-state.
Byte 3 is the brightness, expressed as a duty cycle from
00 (off) to 255 (fully on). When setting brightness levels,
bear in mind that perceived brightness is logarithmic.
If the CAMULTIPLEX command is specified, the scan bit
is active high and the data bits are active low, suitable
for common anode displays.
If the CCMULTIPLEX
command is specified, the scan bit is active low and the
data bits are active high, suitable for common cathode
displays. Only one multiplex operation be in progress at
any one time.
Once this command is sent, the scan port pins will be
activated for exactly equal periods (~1ms) and at the
same time the data output port will output the data
specified by the MPXDATA commands. Timer0 is used
to implement the multiplex function
AC 02 45 FF
Command – When scan bit 2 high,
Output 45 on Port C’s
data pits, full brightness