$100A
, but this will only work if digital input devices
are connected to the port.
There are actually sixteen analog inputs (eight of them useful), of which we can read up to four at a time. Two control/status registers are used to set it up, and four data registers are used to read the data.
$1039
)
ADPU |
CSEL |
IRQE |
DLY |
CME |
|
CR1 |
CR0 |
ADPU
bit. This must be set to 1 in order to
use the A/D subsystem. This works like our lds #STACK
instruction
in order to use the stack for subroutine calls.
$1030
)
CCF |
|
SCAN |
MULT |
CD |
CC |
CB |
CA |
CCF
(status)
SCAN
(control)
MULT
(control)
CD
-CA
(control)
CD
and CC
only is read;
a value of 00 selects the lower four channels (0-3), and a value of 01
selects the upper four channels (4-7).
The four data registers are located at addresses $1031
through $1034
and are called ADR1, ADR2, ADR3, and ADR4.
These are result, or data registers, and are the values that you get
as input. When an analog value is read, it is
placed in one of these four data registers; you can obtain it from
there by reading it just like any other memory location.
OPTION
register to turn on the
system. Then, you need to configure the analog port using the
ADCTL
register. Third, you need
to wait until you're getting valid data (it takes 128 cycles to input
and convert the four channels, ADR1 - ADR4, whether it be a single bit
four times or four bits one time), by waiting for the CCF flag
to become true. This can be done with a busy-wait loop which would look
like the following code:
ADCTL equ $1030
CCF equ $80
.
.
.
ldx #ADCTL
wait brclr 0,x CCF wait
Finally, you can read the data. If you're in
SCAN
mode, you only need to set it up once, and you can
read it over and over again.