Download presentation
Presentation is loading. Please wait.
Published bySamantha Harmon Modified over 9 years ago
1
ECE 3561 - Lecture 1 1 L15 – Digital I/O Department of Electrical and Computer Engineering The Ohio State University ECE 2560
2
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
3
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
4
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
5
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
6
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
7
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
8
Interrupt Control Register (cont) Interrupt Flag Registers P1IFG, P2IFG 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 Interrupt Edge Select Register P1IES, P2IES 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
9
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
10
Register summary Port P1 REGISTER Name AddressType Input Register P1IN020hR Output Register P1OUT 021hR/W Direction Reg P1DIR022hR/W Interrupt Flag P1IFG023hR/W Intr Edge Select P1IES024hR/W Interrupt Enable P1IE025hR/W Port Select P1SEL026hR/W Internal Resistor P1REN 027hR/W ECE 3561 - Lecture 1 10
11
Register summary Port P2 REGISTER Name AddressType Input Register P2IN028hR Output Register P2OUT 029hR/W Direction Reg P2DIR02AhR/W Interrupt Flag P2IFG02BhR/W Intr Edge Select P2IES02ChR/W Interrupt Enable P2IE02DhR/W Port Select P2SEL02EhR.W ECE 3561 - Lecture 1 11
12
Port 3 and 4 Port P3 REGISTER Name AddressType Input Register P3IN 018hR Output Register P3OUT 019hR/W Direction Reg P3DIR 01AhR/W Port Select P3SEL 01BhR/W Port P4 REGISTER Name AddressType Input Register P4IN 01ChR Output Register P4OUT 01DhR/W Direction Reg P4DIR 01EhR/W Port Select P4SEL 01FhR/W ECE 3561 - Lecture 1 12
13
Ports 5 and 6 Port P5 REGISTER Name AddressType Input Register P5IN 030hR Output Register P5OUT 031hR/W Direction Reg P5DIR 032hR/W Port Select P5SEL 033hR/W Port P6 REGISTER Name AddressType Input Register P6IN 034hR Output Register P6OUT 035hR/W Direction Reg P6DIR 036hR/W Port Select P6SEL 037hR/W ECE 3561 - Lecture 1 13
14
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
15
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
16
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
17
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
18
A loop to toggle to output mov #0xFFFF,R6 ;# times to wait toldec R6 jne tol;busy wait mov.b P1OUT,R4 inv R4 mov.b R4,P1OUT jmp tol ECE 3561 - Lecture 1 18
19
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
20
ECE 3561 - Lecture 1 20 Summary - Assignment Try out the code Add an inner loop to lengthen the time for each individual light. No new assignment.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.