<< Chapter < Page | Chapter >> Page > |
In this lab we're going to use the MSP430's GPIO pins, combined with some external switches and an LED display, to build a basic I/O system for our board. Because of how things fit together on the board, it makes sense to use P1.0-P1.3 (the first three Port_1 GPIO Pins) to read the input switches and P1.4-P1.7 for the output signals.
&P1DIR
to "1", and then write the output to the upper four bits of
&P1OUT
. That means you'll have to shift your data left 4 positions before output, but you should already know a simple technique to do so!
&P1DIR
values only connects or disconnects the driving circuitry built into the MSP430. In advanced applications this can be used to analyze potential faults in the circuitry outside the chip.
As mentioned briefly in class, binary digital logic has two valid states, plus one third mystery state. That third state, "The High Impedance State," (High-Z) just means that the wire isn't connected to anything. You've already talked about using so called tri-state buffers to negotiate who can talk on a shared bus-- the listening components enter the high impedance state, allowing the transmitting component's signal to drive the bus with no conflicts.
In order to read useful input from your switches, you need them to be "0" in one state, and "1" in the other. Yet knowing what you know about the third state, the switch shown above will actually give a "0"/"1" (depending on what you connect it to) when closed and "High-Z" when open. Because there's nothing else driving the sensor input besides our switch, the input value will be random when the switch is open . In digital logic this is called floating, and it is a very very bad thing.
One simple solution is the Pull-Up (or Pull-Down) Resistor . Connecting the floating side of the switch to a logic level through a large resistor will tie down the floating input when the switch is open, but won't effect the read value much when the switch is closed.
&P1DIR
to "0")&P1REN
to "1")&P1OUT
to "1")P1OUT
. Because of the hardware implementation on the MSP430,
&P1OUT
controls the outputs as well as the connections to the pull up resistors.
You will need to ensure that every time you output a value, you KEEP the lower four bits "1" . The easiest way to do this is just by ORing your raw output with the constant
#0Fh
before you write to
P1OUT
. The MSP430 does not have a specific "or" instruction by name, but
bis
does the same thing. For more info on
bis
and its inverse
bic
, see
next week's lab. Your task is to code a simple input to output echo program for the MSP430. Your program should consist of:
All images drawn by Matt Johnson, Rice ECE
Notification Switch
Would you like to follow the 'Intro to computational engineering: elec 220 labs' conversation and receive update notifications?