gpio test unit 10 로봇 sw 교육원 조용수. 학습 목표 gpio config gpio output test gpio...
TRANSCRIPT
GPIO TestUNIT
10
로봇 SW 교육원조용수
2학습 목표
• GPIO Config• GPIO Output Test• GPIO Input Test• GPIO 를 이용한 간단한 게임 작성
3GPIO Config
• Target Board 에 맞게 GPIO 를 설정하는 단계• 설정 포트
– LED 4 : Output – Button Input 1 : Input
4GPIO Examples
• CMSIS 라이브러리를 이용하여 Empty Project 구성
void PortInit() {}
int main() {
PortInit();}
5GPIO 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();}
6GPIO 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 ControlP2->PMD &= ~((0x3 << 2) | (0x3 << 4) | (0x3 << 6) | (0x3 << 8) );P2->PMD |= (0x1 << 2) | (0x1 << 4) | (0x1 << 6) | (0x1 << 8) ;
}
int main() {
PortInit();}
7GPIO Output Examples
• main
void PortInit() {
// GPIO Port 2-1, 2-2, 2-3, 2-4 -> OUTPUT…
}
int main() {
PortInit();P2->DOUT = 0xFF;
}
8GPIO Output Examples
• main
void PortInit() {
// GPIO Port 2-1, 2-2, 2-3, 2-4 -> OUTPUT…
}
int main() {
PortInit();P2->DOUT = 0x00;
}
9GPIO Input Examples
• GPIO Input Config
void PortInit() {
…// GPIO Port 3-2 -> INPUT// SYS->P3_MFP // Default GPIO ModeP3->PMD &= ~(0x3 << 4);
}
int main() {
PortInit();while(1) {
if(P3->PIN & 0x4) {P2->DOUT = 0xFF;
} else {P2->DOUT = 0x00;
}}
}
10GPIO Output Examples
• GPIO Input [00] -> Tri state
void PortInit() {
…// GPIO Port 3-2 -> INPUT// SYS->P3_MFP // Default GPIO ModeP3->PMD &= ~(0x3 << 4);
}
int main() {
PortInit();while(1) {
if(P3->PIN & 0x4) {P2->DOUT = 0xFF;
} else {P2->DOUT = 0x00;
}}
}
11GPIO 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;
}}
}
12GPIO 를 이용한 게임 만들기
• 러시안 룰렛 게임 만들기1. 난수를 발생하여 저장2. 저장된 난수만큼의 버튼이 눌리는 경우 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 ControlP2->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);}
13GPIO 를 이용한 게임 만들기
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 }
}}
}