CS 273: HC11 Digital Inputs

Address and Wiring

The HC11's digital input port is located at address $1003. Freescale refers to this as "Port C"; if you look at the miniboard schematic diagram, you can see how this is wired to a connector on the left side of the board:

Miniboard Port C wiring

Each of the inputs in the connector corresponds to one bit of the word at $1003: input bit 0 is bit 0 of the word, and so forth. Each of the bits also has a resistor connecting it to +5V. This resistor is called a "pull-up": the idea is, if the connector has nothing connected to it, the pin is "pulled up" to +5, while we can use a switch to "pull it down" to 0V. If we read the port, +5V is read as a 1, and 0V is read as a 0.

On the board, these inputs are on a header strip. There are three pieces of header strip running in parallel, like this:

Input Header Wiring

What we can do with this is wire up a switch, that goes from the digital input to the ground. Now, when we run into something the switch closes: we've got a touch sensor! Here's what the connector looks like:

Switch Wiring

(this information is also in the lab manual)

Programming

The main thing, of course, is that you want to read the port, and look at the bits corresponding to bumpers. Some instructions that are handy for this are:

The and instruction
Suppose you've defined symbols
LBUMP   equ  %00000001
DIGITAL equ  $1003

and you've wired the digital input port so that the left bumper switch is on bit 0. Then the sequence

ldaa #LBUMP   * put mask in A accumulator
anda DIGITAL  * check bumper
beq  hitleft  * branch if bumper is touching

will check the status of a bumper, and branch accordingly (of course, bne would also be a useful instruction depending on what you were doing)

The brset and brclr instructions
These two instructions are also very handy for this situation: with them, you can define your symbols as
LBUMP   equ %00000001
DIGITAL equ $03
IO      equ $1003

and use the instructions

ldx  IO
brclr DIGITAL,x #LBUMP label

to branch if the bit is 0 (so you've run into something), or

ldx  IO
brset DIGITAL,x #LBUMP label

to branch if you haven't.


Last modified: Mon Oct 19 10:17:27 MDT 2009

Valid HTML 4.01 Transitional