CSE421: Microprocessors and Microcontrollers
2012-2013 Spring Semester
Experiment 4:
GPIO and Interrupts
Important Notice: There will be a quiz at the beginning of this Lab work. In the quiz you will beasked a 10 min question from previous lab and Chapter 2: System Resets, Interrupts and Operating Modes of the MSP430 Users’ Guide. The quiz will be closed books and notes. Also, for every Lab, students are expected to get prepared for topic of the lab. In this lab, we will use the new LAB BOARD and expected to write a interrupt subroutine with several input /output exercises. In order to make yourself familirize with the interrupt subroutines see example.
After this LAB work you should know:
1. How to configure the GPIO ports for input and output.
2. How to control 7 segment displays for monitoring.
2. How to enable/disable interrupts of MSP430.
3. How to configure the GPIO ports for falling edge and rising edge interrupt sources.
4. How to write interrupt subroutines.
List of Tasks that Each Student has to complete in the Lab:
Exercise 1:
1. Configure the pins of PORT3 as input. The pins of PORT3 is connected to a DIP SWITCH so that you can give logic HIGH or logic LOW just by adjusting the position of the switch positions. In IAR Embedded Workbench put break point for the line that reads the input from the PORT3 and verify if you really get what you have configured from the board.
2. Configure the pins of the PORT6 as output. The pins of PORT6 is connected to the LEDS. You can turn the LEDS ON (OFF) by setting the correspoding pin as logic LOW (HIGH). Set the pins of the PORT6 for various logic levels and observe if the LEDS turned ON or OFF in the way they should.
3. Write and infinite loop that reads the PORT3 and turns the LEDS connected the PORT6 if the same pin ON (OFF) PORT3 is logic HIGH (LOW).
Exercise 2:
4. Now write a program that counts from 0 to F and show the result on 7-Segment displays on PORT4 or PORT5
Exercise 3:
Use the below example C code to:
5. Enable all interrupts.
6. Configure the pin 1 of PORT2 for interrupt for falling edge
7. In the interrupt subroutine of PORT2 toggle one of the LEDS that are connected to the pins of PORT6, for example P6.1.
Exercise 4:
8. As a final step, write an interrupt subroutine for PORT2 that turn one of LEDS that are connected to pins of PORT6 in cyclec manner. In other words, if LEDn is turned on, at next the LED(n+1) has to be turned on till n+1=7, with interrupt occurs the direction of the shining LED turns backward and LED(n-1) has to be turned ON till n-1=0.
9. In the lab students should spend as much time as possible to learn how the Digital I/O of MSP430 works
and how the interrupts of MSP430 works.
An Example code that you can use in the LAB:
#include <msp430x41x.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
FLL_CTL0 |= XCAP18PF; // Set load cap for 32k xtal
P2DIR = 0x00; // Set the PORT2 as input
P2IE =0x02; // Enable interrupt for pin 1 of PORT2 (P2.1)
P2IES =0x02; // Set the interrupt for falling edge
P6DIR |= 0xFF; // Set PORT6 as output
_BIS_SR(GIE); // Enable global interrupts
while (1);
}
// PORT2 Interrupt Service Routine
#pragma vector=PORT2_VECTOR
__interrupt void gpio_port2_isr(void)
{
P2IFG =0x00; //Clear the interrupt flag
P6OUT ^ = 0xFF; // Toggle PORT6
}
Helpfull Documents and Hints for the LAB:
1. MSP-FET430 Users Guide.pdf,
2. MSP430 IAR Embedded Workbench IDE User’s Guide (EW430 UserGuide.pdf), the.
3. Sample codes from TI (slac017f)