본문 바로가기
Embedded System

[Lab 10]

by Hangii 2022. 12. 5.
//Exercise 7
//Goal: Write a program that turns on P2 RED LED at the initial state.
//When the S1 button is pressed, turn P2 GREEN LED, and when the S2 button is pressed,
//turn BLUE LED

#include "msp.h"

void PORT1_IRQHandler(void) {
	//S1 Button
	if (P1->IFG & BIT1) {
		P2->OUT = 0x02;  //change output color to green
		P1->IFG &= ~BIT1; //reset: P1의 BIT1번을 disable 하면 interrupt signal이 clear되면서 해당 코드가 다시 실행되지 않게 됨.
	}
	//S2 Button
	if (P1->IFG & BIT4) {
		P2->OUT = 0x04;  //change output color to blue
		P1->IFG &= ~BIT4;  //reset: P1의 BIT4번을 disable 하면 interrupt signal이 clear되면서 해당 코드가 다시 실행되지 않게 됨.
	}
}

void main(void) {
	//Button enable and use as pull-up
	P1->DIR = ~(uint8_t)(BIT1 | BIT4);
	P1->OUT = (BIT1 | BIT4);
	P1->REN = (BIT1 | BIT4);
	
	//Interrupt Enable(S1 and S2)
	P1->IES = (BIT1 | BIT4);
	P1->IFG = 0;
	P1->IE = (BIT1 | BIT4);

	//use RGB as output
	P2->DIR |= (1 << 2 | 1 << 1 | 1 << 0);
	P2->OUT = 0x01;

	NVIC->ISER[1] = 1 << ((PORT1_IRQn) & 31);
	while (1) {

	}
}

'Embedded System' 카테고리의 다른 글

[Lecture 12] Joystick  (0) 2022.12.06
[Lecture 11] LCD  (1) 2022.12.05

댓글