Created
August 8, 2018 20:21
-
-
Save totoroAKI/943eb3fd6c2168310791dbf902721173 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <msp430.h> //MSP430F2619TPM | |
/* | |
* main.c | |
*/ | |
// 端子設定 ///////////////////////////////////////////////////////// | |
#define test_LED 0b00000001 // P1.0 test_LED | |
#define RED_LED 0b00000001 // P6.0 RED_LED | |
#define BUTTON 0b00000010 // P6.1 BUTTON | |
#define BLUE_LED 0b00010000 // P6.4 BLUE_LED | |
#define GREEN_LED 0b10000000 // P6.7 GREEN_LED | |
// 初期設定 ///////////////////////////////////////////////////////// | |
void setup() { | |
WDTCTL = WDTPW + WDTHOLD; // Stop WathcDog Timer, | |
SVSCTL &= ~SVSFG; // 低電圧フラグを消去 Supply Voltage Supervisor | |
SVSCTL = 0x60 + PORON; // SVS POR enabled @ 2.5V 電圧低下検出.この電圧以下ではマイコンリセット. | |
while(!(SVSCTL & SVSON)); // 電圧監視機能がONになるまで待機 | |
DCOCTL = 0; // Select lowest DCOx and MODx settings | |
BCSCTL1 = CALBC1_8MHZ; // Set RSELx | |
DCOCTL = CALDCO_8MHZ; // Set DCOx and MODx | |
// 省力化のため、すべてのピンを初期化 | |
P1DIR = test_LED; // P1.0;OUT, the others;IN | |
P1REN = 0x00; // P1 set to Pullup/Pulldown Disable | |
P2DIR = 0x00; // P2 set to INPUT for unused Port pins | |
P2REN = 0x00; // P2 set to Pullup/Pulldown Disable | |
P3DIR = 0x00; // P3 set to INPUT for unused Port pins | |
P3REN = 0x00; // P3 set to Pullup/Pulldown Disable | |
P4DIR = 0x00; // P4 set to INPUT for unused Port pins | |
P4REN = 0x00; // P4 set to Pullup/Pulldown Disable | |
P5DIR = 0x00; // P5 set to INPUT for unused Port pins | |
P5REN = 0x00; // P5 set to Pullup/Pulldown Disable | |
P6DIR = RED_LED | BLUE_LED | GREEN_LED; // P6.0, P6.4, P6.7;OUT, the others;IN | |
P6REN = 0x00; // P6 set to Pullup/Pulldown Disable | |
} | |
int main(void) | |
{ | |
setup(); // システム初期設定.これ以前には何も処理をしないこと | |
int i = 0; // 汎用計算変数 | |
P1OUT = test_LED; // 初期設定 | |
P6OUT = GREEN_LED; // 初期設定 | |
while(1){ | |
if((P6IN & BUTTON) == BUTTON){ //P6.1のButton は押すとHIGHが入力される | |
if(i == 0){ P6OUT = RED_LED; } | |
else if(i == 1){ P6OUT = BLUE_LED; } | |
else if(i == 2){ P6OUT = GREEN_LED; } | |
i++; | |
if(i == 3){i = 0;} | |
while((P6IN & BUTTON) == BUTTON); //ボタンが離されるのを待つ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment