一、记录以下代码
准备电子设计大赛,浅浅的学习了MSP432的板载LED模块,记录如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| #ifndef _LED_H_ #define _LED_H_
#include "headfile.h"
#define LED_PORT GPIO_PORT_P1 #define LED_PIN GPIO_PIN0 #define LED_ON GPIO_setOutputHighOnPin(LED_PORT,LED_PIN) #define LED_OFF GPIO_setOutputLowOnPin(LED_PORT,LED_PIN) #define LED_TOGGLE GPIO_toggleOutputOnPin(LED_PORT,LED_PIN)
#define RGB_LED_PORT GPIO_PORT_P2 #define RGBLED_R_PIN GPIO_PIN0 #define RGBLED_G_PIN GPIO_PIN1 #define RGBLED_B_PIN GPIO_PIN2 #define RGBLED_R_ON GPIO_setOutputHighOnPin(RGB_LED_PORT,RGBLED_R_PIN) #define RGBLED_R_OFF GPIO_setOutputLowOnPin(RGB_LED_PORT,RGBLED_R_PIN) #define RGBLED_G_ON GPIO_setOutputHighOnPin(RGB_LED_PORT,RGBLED_G_PIN) #define RGBLED_G_OFF GPIO_setOutputLowOnPin(RGB_LED_PORT,RGBLED_G_PIN) #define RGBLED_B_ON GPIO_setOutputHighOnPin(RGB_LED_PORT,RGBLED_B_PIN) #define RGBLED_B_OFF GPIO_setOutputLowOnPin(RGB_LED_PORT,RGBLED_B_PIN)
#define RGBLED_RED 1 #define RGBLED_GREEN 2 #define RGBLED_BLUE 3 #define RGBLED_OFF 4
void LED_Init(void); void RGBLED_Init(void); void RGBLED(unsigned short color); void rgbled_test(void);
#endif
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#include "led.h"
void LED_Init(void) { GPIO_setAsOutputPin(LED_PORT,LED_PIN); LED_OFF; }
void RGBLED_Init(void) { GPIO_setAsOutputPin(RGB_LED_PORT,RGBLED_R_PIN); GPIO_setAsOutputPin(RGB_LED_PORT,RGBLED_G_PIN); GPIO_setAsOutputPin(RGB_LED_PORT,RGBLED_B_PIN); RGBLED_R_OFF; RGBLED_G_OFF; RGBLED_B_OFF; }
void RGBLED(unsigned short color) { switch (color) { case(RGBLED_RED): { RGBLED_R_ON; RGBLED_G_OFF; RGBLED_B_OFF; break; } case(RGBLED_GREEN): { RGBLED_R_OFF; RGBLED_G_ON; RGBLED_B_OFF; break; } case(RGBLED_BLUE): { RGBLED_R_OFF; RGBLED_G_OFF; RGBLED_B_ON; break; } case(RGBLED_OFF): { RGBLED_R_OFF; RGBLED_G_OFF; RGBLED_B_OFF; break; } } }
void rgbled_test(void) { short i = 0; while(1) { i ++; if(i == 5) i = 0; RGBLED(i); delay_ms(300); } }
|