ECE 2560 - Lecture 15 Digital I O

advertisement
ECE 2560
L15 – Digital I/O
Department of Electrical and
Computer Engineering
The Ohio State University
ECE 3561 - Lecture 1
1
Digital I/O on the 430

Digital input and output
The ports
 Port setup
 The control registers


Using a port
ECE 3561 - Lecture 1
2
The MSP 430
The MSP 430 is a microcontroller
intended for use in embedded systems.
 As such, it needs to be capable of being
connected with various input sensors
and generating signal with control
outputs.
 For a large number of these, digital I/O is
appropriate.

ECE 3561 - Lecture 1
3
Digital I/O overview

A MSP430 device may have up to 6 digital I/O
ports, P1 through P6.
 Each port has 8 I/O pins.
 Pins are configurable for input or output direction
and each I/O line can be individually read or
written to.
 Ports P1 and P2 have interrupt capability with
the interrupt for each I/O line individually
enabled and configured.


All P1 lines source a single interrupt vector
P2 lines source a single interrupt vector (different
than the vector for P1)
ECE 3561 - Lecture 1
4
Summary of features

Digital I/O features
Individually programmable I/Os
 Any combination of input or output
 Individually configurable P1 and P2
interrupts
 Independent input and output registers

ECE 3561 - Lecture 1
5
Digital I/O


Digital I/O is configured with user software
Done by setting the value in port control
registers.

Input register – a bit for each pin - PxIN



Bit = 0 – The input is low
Bit = 1 – The input is high
Output register – the value to be output on the
pin - PxOUT


Bit = 0 – Set output low
Bit = 1 – Set output high
ECE 3561 - Lecture 1
6
The control registers

Direction Register PxDIR




This register for a port sets the direction of
each pin of the input/output port
Bit = 0 – The port pin is set to input direction
Bit = 1 – The port pin is set to output direction
Function Select Register – PxSEL



The ports can also be used with other
peripheral devices according to the data sheet
of the device. Or it is a simple I/O port.
Bit = 0 – Set function to I/O
Bit = 1 – Set peripheral function mode.
ECE 3561 - Lecture 1
7
Interrupt Control Register (cont)

Interrupt Flag Registers P1IFG, P2IFG




Interrupt Edge Select Register P1IES, P2IES


For ports 1 and 2 these registers record if an
interrupt is present on the appropriate pin.
Bit = 0 – No interrupt is pending
Bit = 1 – Interrupt is pending
These registers select whether the interrupt occurs
on a rising edge or falling edge.
Interrupt Enable P1IE, P2IE

Each P1IE bit enables the associated PxIFG
interrupt flag. (1 = enabled, 0 = disabled)
ECE 3561 - Lecture 1
8
Unused Ports
What to do with the pins for unused
ports?
 Unused I/O pins should be configured as
I/O function, output direction and left
unconnected on the PC board.

ECE 3561 - Lecture 1
9
Register summary

Port P1









REGISTER
Input Register
Output Register
Direction Reg
Interrupt Flag
Intr Edge Select
Interrupt Enable
Port Select
Internal Resistor
Name Address
P1IN 020h
P1OUT 021h
P1DIR 022h
P1IFG 023h
P1IES 024h
P1IE
025h
P1SEL 026h
P1REN 027h
ECE 3561 - Lecture 1
Type
R
R/W
R/W
R/W
R/W
R/W
R/W
R/W
10
Register summary

Port P2








REGISTER
Input Register
Output Register
Direction Reg
Interrupt Flag
Intr Edge Select
Interrupt Enable
Port Select
Name
P2IN
P2OUT
P2DIR
P2IFG
P2IES
P2IE
P2SEL
Address
028h
029h
02Ah
02Bh
02Ch
02Dh
02Eh
ECE 3561 - Lecture 1
Type
R
R/W
R/W
R/W
R/W
R/W
R.W
11
Port 3 and 4

Port P3






REGISTER
Input Register
Output Register
Direction Reg
Port Select
Name Address
P3IN
018h
P3OUT 019h
P3DIR 01Ah
P3SEL 01Bh
Type
R
R/W
R/W
R/W
Name Address
P4IN
01Ch
P4OUT 01Dh
P4DIR 01Eh
P4SEL 01Fh
Type
R
R/W
R/W
R/W
Port P4





REGISTER
Input Register
Output Register
Direction Reg
Port Select
ECE 3561 - Lecture 1
12
Ports 5 and 6

Port P5






REGISTER
Input Register
Output Register
Direction Reg
Port Select
Name Address
P5IN
030h
P5OUT 031h
P5DIR 032h
P5SEL 033h
Type
R
R/W
R/W
R/W
Name Address
P6IN
034h
P6OUT 035h
P6DIR 036h
P6SEL 037h
Type
R
R/W
R/W
R/W
Port P6





REGISTER
Input Register
Output Register
Direction Reg
Port Select
ECE 3561 - Lecture 1
13
EXAMPLE OF use
On the launchpad there are 2 Light
Emitting Diodes on the PC board
 These are (according to the notation on
the board) at P1.0 and P1.6


Let’s turn then on and off
ECE 3561 - Lecture 1
14
The steps


Configure the port
Port 1






Configure the data direction register, P1DIR
Located at address 022h
Set value to 1 for output
Desire pins 0 and 6 of the port as output so
value to set is 1xxxxx1x or just set it to all 1s
Instruction mov.b #0x0FF,P1DIR
Configure the interrupt enables to disable

Mov.b
0x00,P1IE
ECE 3561 - Lecture 1
15
A note on code composer

As this MSP430 does have Port 1 the
pneumonic labels such as P1OUT are
defined in Code Composer. That is why
they are commented out in the sample
code.
ECE 3561 - Lecture 1
16
The code
; Set up the port

mov.b #0xFF,P1DIR ;set P1 to outputs

mov.b #0x00,P1IE ;disable interrupts

mov.b #0x00,P1SEL ;all pins are I/O

; move values to the port

mov.b #0x00,P1OUT

mov.b #0x0F,P1OUT

mov.b #0xF0,P1OUT

ECE 3561 - Lecture 1
17
A loop to toggle to output
mov #0xFFFF,R6 ;# times to wait
 tol dec
R6

jne
tol
;busy wait

mov.b P1OUT,R4

inv
R4

mov.b R4,P1OUT

jmp
tol

ECE 3561 - Lecture 1
18
Notes on code
Busy wait : a term applied to techniques
to insert a timed wait into a program that
performs no useful computation other
than to wait for time to elapse or an
event to occur.
 This toggles the leds based on time.
 The code to toggle them could be tuned
to take slightly less cycles but that this
not desired here.

ECE 3561 - Lecture 1
19
Summary - Assignment
Try out the code
 Add an inner loop to lengthen the time
for each individual light.


No new assignment.
ECE 3561 - Lecture 1
20
Download