【复旦微FM33LC046N评测】+ LED和KEY
[复制链接]
本帖最后由 chrisrh 于 2021-2-8 22:24 编辑
临近年关,被接连出现的问题,给把原定的时间安排都打乱了···❤态坚强···
简单使用了一下led和key,后续继续···
DEMO上面自带了四个LED灯,调用库函数完成点亮LED,库函数使用类似ST的库;
其中:
LED1----->PC0
LED2----->PC1
LED3----->PB10(J42跳冒短接使用)
LED4----->PB9(J43跳冒短接使用)
先简单的用key调用IO点亮led灯
led.h
#ifndef __LED_H__
#define __LED_H__
#include "main.h"
#define LED1_GPIO GPIOC
#define LED1_PIN FL_GPIO_PIN_0
#define LED1_ON() FL_GPIO_ResetOutputPin(LED1_GPIO, LED1_PIN)
#define LED1_OFF() FL_GPIO_SetOutputPin(LED1_GPIO, LED1_PIN)
#define LED1_TOG() FL_GPIO_ToggleOutputPin(LED1_GPIO, LED1_PIN)
#define LED2_GPIO GPIOC
#define LED2_PIN FL_GPIO_PIN_1
#define LED2_ON() FL_GPIO_ResetOutputPin(LED2_GPIO, LED2_PIN)
#define LED2_OFF() FL_GPIO_SetOutputPin(LED2_GPIO, LED2_PIN)
#define LED2_TOG() FL_GPIO_ToggleOutputPin(LED2_GPIO, LED2_PIN)
#define LED3_GPIO GPIOB
#define LED3_PIN FL_GPIO_PIN_10
#define LED3_ON() FL_GPIO_ResetOutputPin(LED3_GPIO, LED3_PIN)
#define LED3_OFF() FL_GPIO_SetOutputPin(LED3_GPIO, LED3_PIN)
#define LED3_TOG() FL_GPIO_ToggleOutputPin(LED3_GPIO, LED3_PIN)
#define LED4_GPIO GPIOB
#define LED4_PIN FL_GPIO_PIN_9
#define LED4_ON() FL_GPIO_ResetOutputPin(LED4_GPIO, LED4_PIN)
#define LED4_OFF() FL_GPIO_SetOutputPin(LED4_GPIO, LED4_PIN)
#define LED4_TOG() FL_GPIO_ToggleOutputPin(LED4_GPIO, LED4_PIN)
void My_LEDInit(void);
void LED_Blink(uint8_t BlinkNum,uint16_t BlinkTime);
#endif
led.c
#include "led.h"
#include "user_init.h"
void My_LEDInit(void)
{
uint8_t count = 5;
FL_GPIO_InitTypeDef GPIO_InitStruct;// = {0};
FL_GPIO_ResetOutputPin(LED1_GPIO, LED1_PIN);
FL_GPIO_ResetOutputPin(LED2_GPIO, LED2_PIN);
GPIO_InitStruct.pin = LED1_PIN|LED2_PIN;
GPIO_InitStruct.mode = FL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.pull = DISABLE;
FL_GPIO_Init(LED1_GPIO, &GPIO_InitStruct);
FL_GPIO_Init(LED2_GPIO, &GPIO_InitStruct);
FL_GPIO_ResetOutputPin(LED3_GPIO, LED3_PIN);
FL_GPIO_ResetOutputPin(LED4_GPIO, LED4_PIN);
GPIO_InitStruct.pin = LED3_PIN|LED4_PIN;
GPIO_InitStruct.mode = FL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.pull = DISABLE;
FL_GPIO_Init(LED3_GPIO, &GPIO_InitStruct);
FL_GPIO_Init(LED4_GPIO, &GPIO_InitStruct);
while (count--)
{
LED1_ON();LED2_ON();
DelayMs(100);
LED1_OFF();LED2_OFF();
DelayMs(100);
LED3_TOG();LED4_TOG();
DelayMs(100);
}
}
void LED_Blink(uint8_t BlinkNum,uint16_t BlinkTime)
{
uint8_t count = BlinkNum;
uint16_t time = BlinkTime;
while(count--)
{
LED1_ON();LED2_OFF();
DelayMs(time);
LED1_OFF();LED2_ON();
DelayMs(time);
}
FL_GPIO_SetOutputPin(LED1_GPIO, LED1_PIN);
FL_GPIO_SetOutputPin(LED2_GPIO, LED2_PIN);
}
按键1和按键4与MCU直连,2、3短接使用
KEY1----->PA10
KEY2----->PB12(J40跳冒短接使用)
KEY3----->PD11(J41跳冒短接使用)
KEY4----->PC6
key.h
#ifndef __KEY_H__
#define __KEY_H__
#include "main.h"
#define KEY1_GPIO GPIOA
#define KEY1_PIN FL_GPIO_PIN_10
#define KEY2_GPIO GPIOB
#define KEY2_PIN FL_GPIO_PIN_12
#define KEY3_GPIO GPIOD
#define KEY3_PIN FL_GPIO_PIN_11
#define KEY4_GPIO GPIOC
#define KEY4_PIN FL_GPIO_PIN_6
#define KEY1_State FL_GPIO_GetInputPin(KEY1_GPIO,KEY1_PIN)
#define KEY2_State FL_GPIO_GetInputPin(KEY2_GPIO,KEY2_PIN)
#define KEY3_State FL_GPIO_GetInputPin(KEY3_GPIO,KEY3_PIN)
#define KEY4_State FL_GPIO_GetInputPin(KEY4_GPIO,KEY4_PIN)
#define KEY1_PRES 1 //KEY1按下
#define KEY2_PRES 2 //KEY2按下
#define KEY3_PRES 3 //KEY3按下
#define KEY4_PRES 4 //KEY4按下
void KEY_Init(void);
uint8_t KEY_Scan(uint8_t);
#endif
key.c
#include "key.h"
#include "user_init.h"
void KEY_Init(void)
{
FL_GPIO_InitTypeDef GPIO_InitStruct;// = {0};
FL_GPIO_SetOutputPin(GPIOA, FL_GPIO_PIN_10);
FL_GPIO_SetOutputPin(GPIOC, FL_GPIO_PIN_6);
GPIO_InitStruct.pin = KEY1_PIN|KEY4_PIN;
GPIO_InitStruct.mode = FL_GPIO_MODE_INPUT;
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.pull = DISABLE;
GPIO_InitStruct.remapPin = DISABLE;
FL_GPIO_Init(KEY1_GPIO, &GPIO_InitStruct);
FL_GPIO_Init(KEY4_GPIO, &GPIO_InitStruct);
}
uint8_t KEY_Scan(uint8_t mode)
{
if((KEY1_State==0||KEY4_State==0))
{
DelayMs(100);
if(KEY1_State==0)return KEY1_PRES;
else if(KEY4_State==0)return KEY4_PRES;
}
return 0;
}
main.c
#include "main.h"
#include "adc.h"
#include "led.h"
#include "key.h"
float GetT;
int main(void)
{
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
uint8_t key=0;
/* SHOULD BE KEPT!!! */
MF_Clock_Init();
/* Configure the system clock */
/* SHOULD BE KEPT!!! */
MF_SystemClock_Config();
/* user init */
UserInit();
/* Initialize all configured peripherals */
/* SHOULD BE KEPT!!! */
MF_Config_Init();
My_LEDInit();
DelayMs(1000);
//LED_Blink(5,500);
KEY_Init(); //初始化按键
while(1)
{
key=KEY_Scan(1); //得到键值
if(key)
{
switch(key)
{
case KEY1_PRES: //控制key1
LED1_ON();LED2_ON();break;
case KEY4_PRES: //控制key4
LED1_OFF();LED2_OFF();LED3_TOG();LED4_TOG();break;
};
}
DelayMs(10);
}
}
个人使用的一些感觉:
1.感觉FM应该正在建自己的库函数和相关的库函数使用手册,那样用户上手会更容易,期待手册早日发布;
2.下版demo可以考虑把5V的供电口换个常用的USB口,供电会更方便点,像现在这样,不焊接留用也行,到时候可以自己加上;
3.板子很不错,未完待续···
|