stm32 rgb多彩led驱动
生活随笔
收集整理的這篇文章主要介紹了
stm32 rgb多彩led驱动
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
給大家分享下stm32的rgb多彩led驅(qū)動(dòng)
頭文件:
#ifndef _LED_H #define _LED_H#ifdef __cplusplusextern "C" { #endif#define RED 1 #define GREEN 2 #define BLUE 3 #define YELLOW 4 #define PURPLE 5 #define NAVY 6 #define WHITE 7typedef enum { false= 0, true = !false} bool; void led_init(void); void led_ctrl(u8 colour, bool state);#ifdef __cplusplus } #endif #endif 源文件: #include "led.h"void led_init(void) {GPIO_InitTypeDef GPIO_InitStructure;RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOA, &GPIO_InitStructure);// GPIO_ResetBits(GPIOA, GPIO_Pin_11); // GPIO_ResetBits(GPIOA, GPIO_Pin_12); // GPIO_ResetBits(GPIOA, GPIO_Pin_15);GPIO_SetBits(GPIOA, GPIO_Pin_11);GPIO_SetBits(GPIOA, GPIO_Pin_12);GPIO_SetBits(GPIOA, GPIO_Pin_15); }void led_ctrl(u8 colour, bool state) {switch(colour){case RED:if(state){GPIO_ResetBits(GPIOA, GPIO_Pin_11);}else {GPIO_SetBits(GPIOA, GPIO_Pin_11);}break;case GREEN:if(state){GPIO_ResetBits(GPIOA, GPIO_Pin_12);}else{GPIO_SetBits(GPIOA, GPIO_Pin_12);}break;case BLUE:if(state){GPIO_ResetBits(GPIOA, GPIO_Pin_15);}else {GPIO_SetBits(GPIOA, GPIO_Pin_15);}break;case YELLOW:if(state){GPIO_ResetBits(GPIOA, GPIO_Pin_11);GPIO_ResetBits(GPIOA, GPIO_Pin_12);}else{GPIO_SetBits(GPIOA, GPIO_Pin_11);GPIO_SetBits(GPIOA, GPIO_Pin_12);}break;case PURPLE:if(state){GPIO_ResetBits(GPIOA, GPIO_Pin_11);GPIO_ResetBits(GPIOA, GPIO_Pin_15);}else{GPIO_SetBits(GPIOA, GPIO_Pin_11);GPIO_SetBits(GPIOA, GPIO_Pin_15);}break;case NAVY:if(state){GPIO_ResetBits(GPIOA, GPIO_Pin_12);GPIO_ResetBits(GPIOA, GPIO_Pin_15);}else{GPIO_SetBits(GPIOA, GPIO_Pin_12);GPIO_SetBits(GPIOA, GPIO_Pin_15);}break;case WHITE:if(state){GPIO_ResetBits(GPIOA, GPIO_Pin_11);GPIO_ResetBits(GPIOA, GPIO_Pin_12);GPIO_ResetBits(GPIOA, GPIO_Pin_15);}else{GPIO_SetBits(GPIOA, GPIO_Pin_11);GPIO_SetBits(GPIOA, GPIO_Pin_12);GPIO_SetBits(GPIOA, GPIO_Pin_15);}break;default:break;} }總結(jié)
以上是生活随笔為你收集整理的stm32 rgb多彩led驱动的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 国内人工智能在教育教学的应用汇总
- 下一篇: 链表的中间结点算法