Presentation is loading. Please wait.

Presentation is loading. Please wait.

UNIT 10 GPIO Test 로봇 SW 교육원 조용수.

Similar presentations


Presentation on theme: "UNIT 10 GPIO Test 로봇 SW 교육원 조용수."— Presentation transcript:

1 UNIT 10 GPIO Test 로봇 SW 교육원 조용수

2 학습 목표 GPIO Config GPIO Output Test GPIO Input Test

3 GPIO Config Target Board 에 맞게 GPIO 를 설정하는 단계 설정 포트 LED 4 : Output
Button Input 1 : Input

4 GPIO Examples CMSIS 라이브러리를 이용하여 Empty Project 구성 void PortInit() { }
int main() PortInit();

5 GPIO Output Examples MPF Config void PortInit() {
// GPIO Port 2-1, 2-2, 2-3, 2-4 -> OUTPUT // MPF Config // SYS->P2_MFP // Default GPIO Mode } int main() PortInit();

6 GPIO Output Examples GPIO Out Config void PortInit() {
// GPIO Port 2-1, 2-2, 2-3, 2-4 -> OUTPUT // MPF Config // SYS->P2_MFP // Default GPIO Mode // GPIO In/Out Control P2->PMD &= ~((0x3 << 2) | (0x3 << 4) | (0x3 << 6) | (0x3 << 8) ); P2->PMD |= (0x1 << 2) | (0x1 << 4) | (0x1 << 6) | (0x1 << 8) ; } int main() PortInit();

7 GPIO Output Examples main void PortInit() {
// GPIO Port 2-1, 2-2, 2-3, 2-4 -> OUTPUT } int main() PortInit(); P2->DOUT = 0xFF;

8 GPIO Output Examples main void PortInit() {
// GPIO Port 2-1, 2-2, 2-3, 2-4 -> OUTPUT } int main() PortInit(); P2->DOUT = 0x00;

9 GPIO Input Examples GPIO Input Config void PortInit() { …
// GPIO Port 3-2 -> INPUT // SYS->P3_MFP // Default GPIO Mode P3->PMD &= ~(0x3 << 4); } int main() PortInit(); while(1) { if(P3->PIN & 0x4) { P2->DOUT = 0xFF; } else { P2->DOUT = 0x00;

10 GPIO Output Examples GPIO Input [00] -> Tri state void PortInit() {
// GPIO Port 3-2 -> INPUT // SYS->P3_MFP // Default GPIO Mode P3->PMD &= ~(0x3 << 4); } int main() PortInit(); while(1) { if(P3->PIN & 0x4) { P2->DOUT = 0xFF; } else { P2->DOUT = 0x00;

11 GPIO Output Examples GPIO Input [00] -> Tri state void PortInit() {
// GPIO Port 3-2 -> INPUT // SYS->P3_MFP // Default GPIO Mode //P3->PMD &= ~(0x3 << 4); P3->PMD |= (0x3 << 4); } int main() PortInit(); while(1) { if(P3->PIN & 0x4) { P2->DOUT = 0xFF; } else { P2->DOUT = 0x00;

12 GPIO 를 이용한 게임 만들기 러시안 룰렛 게임 만들기 난수를 발생하여 저장
저장된 난수만큼의 버튼이 눌리는 경우 LED ON! #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include "M051Series.h" void PortInit() { // GPIO Port 2-1, 2-2, 2-3, 2-4 -> OUTPUT // MPF Config // SYS->P2_MFP // Default GPIO Mode // GPIO In/Out Control P2->PMD &= ~((0x3 << 2) | (0x3 << 4) | (0x3 << 6) | (0x3 << 8) ); P2->PMD |= (0x1 << 2) | (0x1 << 4) | (0x1 << 6) | (0x1 << 8) ; // GPIO Port 3-2 -> INPUT // SYS->P3_MFP // Default GPIO Mode //P3->PMD = (P3->PMD & ~(0x3 << 6)); //P3->PMD |= (0x10 << 6); //P3->PMD &= ~(0x3 << 4); P3->PMD |= (0x3 << 4); }

13 GPIO 를 이용한 게임 만들기 int main() {
int result = rand() % 6; // 0~5 까지의 난수 발생 int isStart = -1; int isContinue = -1; //GPIO_SetMode(P3, BIT6, GPIO_PMD_INPUT); PortInit(); while(1) { if(isStart < 0) { result = rand() % 6; } if(P3->PIN & 0x4) { if(isContinue > 0) { isContinue = -1; result --; if(result <= 0) { P2->DOUT = 0x00; isStart = -1; } else { if(isContinue < 0 ) { P2->DOUT = 0xFF; isContinue = 1; isStart = 1; // Start Game


Download ppt "UNIT 10 GPIO Test 로봇 SW 교육원 조용수."

Similar presentations


Ads by Google