Exam 1 – Intro to MicroComputers
Illustration 1
Illustration 2
Illustration 3
Exam 1 – Intro to MicroComputers
Illustration 4
Interrupts & Memory Map
Illustration 5
Illustration 6
Exam 1 – Intro to MicroComputers
Illustration 7
Illustration 8
Illustration 9
Illustration 11
Illustration 10
Exam 1 – Intro to MicroComputers
Illustration 12
Exam 1 – Intro to MicroComputers
1. /*Single Sentence: Blink the LED with an Interrupt created by pressing a Button
2. */
3.
4. /*
5. * P2.3 Push button SW1 so button is BIT3 on Port 2
6. * All of these operations are 8 bit (byte) writes
7. * P3DIR &= ~BIT3; // BIT3 off, dir is input
8. * P3REN |= BIT3; // BIT3 on, Enable internal pull-up register
9. * P3OUT |= BIT3; // BIT3 on, set outbit to pull-up
10. *
11. * P3IES |= BIT3; // BIT3 on, trigger edge rise/fall
12. * P3IFG &= ~BIT3; // BIT3 off,clear interrupt flag
13. * P3IE |= BIT3; // BIT3 on, set interrupt enable
14. */
15. #include <msp430.h>
16.
17.
18. // P1.0 Red LED
19. // P2.3 SW1
20.
21.
22. int main(void)
23. {
24. WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
25.
26. // Disable the GPIO power-on default high-impedance mode
27. // to activate previously configured port settings
28. PM5CTL0 &= ~LOCKLPM5; //off
29.
30. // set LED output bit
31. P1DIR |= BIT0; // on, Set P1.0 to output direction
32. // start with LED off
33. P1OUT &= ~BIT0; // P1.0 off (LED OFF)
34.
35. // P2.3 input switch (all writes are 8 bits)
36. P2DIR &= ~BIT3; // set P2.3 as input bit (input default power-up)
37. P2OUT |= BIT3; // BIT3 on, set outbit to pull-up
38. P2REN |= BIT3; // BIT3 on, Enable internal pull up register
39.
40. P2IES |= BIT3; // One is Falling edge
41.
42. P2IE |= BIT3; // BIT3 on, P2.3 interrupt enabled
43. P2IFG &= ~BIT3; // BIT3 off, P2.3 IFG cleared
44.
45. // LPM4 - shut down - 0.49uA - OFF Section 6.3 SLASE59B
46. __bis_SR_register(LPM4_bits + GIE ); // LPM4 with interrupts enabled
47.
48. }
49.
50.
51. // Port 2 interrupt service routine
52. #pragma vector=PORT2_VECTOR
53. __interrupt void Port_2(void)
54. {
55. P1OUT ^= BIT0; // P1.0 = toggle (xor)
56. P2IFG &= ~BIT3; // P2.3 IFG off (cleared)
57.
58. // P2IES ^= BIT3; // toggle (xor) the interrupt edge,
59. // the interrupt vector will be called
60. // when P2.3 goes from HitoLow as well as LowtoHigh
61. }
Illustration 13