1 / 20

L15 – Digital I/O

ECE 2560. L15 – Digital I/O. Department of Electrical and Computer Engineering The Ohio State University. Digital I/O on the 430. Digital input and output The ports Port setup The control registers Using a port. The MSP 430.

didier
Download Presentation

L15 – Digital I/O

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ECE 2560 L15 – Digital I/O Department of Electrical and Computer Engineering The Ohio State University ECE 3561 - Lecture 1

  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

  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

  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

  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

  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

  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

  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

  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

  10. Register summary • Port P1 • REGISTER Name Address Type • Input Register P1IN020h R • Output Register P1OUT 021h R/W • Direction Reg P1DIR 022h R/W • Interrupt Flag P1IFG 023h R/W • Intr Edge Select P1IES 024h R/W • Interrupt Enable P1IE 025h R/W • Port Select P1SEL 026h R/W • Internal Resistor P1REN 027h R/W ECE 3561 - Lecture 1

  11. Register summary • Port P2 • REGISTER Name Address Type • Input Register P2IN028h R • Output Register P2OUT 029h R/W • Direction Reg P2DIR 02Ah R/W • Interrupt Flag P2IFG 02Bh R/W • Intr Edge Select P2IES 02Ch R/W • Interrupt Enable P2IE 02Dh R/W • Port Select P2SEL 02Eh R.W ECE 3561 - Lecture 1

  12. Port 3 and 4 • Port P3 • REGISTER Name Address Type • Input Register P3IN 018h R • Output Register P3OUT 019h R/W • Direction Reg P3DIR 01Ah R/W • Port Select P3SEL 01Bh R/W • Port P4 • REGISTER Name Address Type • Input Register P4IN 01Ch R • Output Register P4OUT 01Dh R/W • Direction Reg P4DIR 01Eh R/W • Port Select P4SEL 01Fh R/W ECE 3561 - Lecture 1

  13. Ports 5 and 6 • Port P5 • REGISTER Name Address Type • Input Register P5IN 030h R • Output Register P5OUT 031h R/W • Direction Reg P5DIR 032h R/W • Port Select P5SEL 033h R/W • Port P6 • REGISTER Name Address Type • Input Register P6IN 034h R • Output Register P6OUT 035h R/W • Direction Reg P6DIR 036h R/W • Port Select P6SEL 037h R/W ECE 3561 - Lecture 1

  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

  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

  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

  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

  18. 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

  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

  20. 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

More Related