参加芯来科技早春营的小试验Longan nano开发板GPIO输入控制led灯, 开发环境(lubuntu18.04 + vscode + platformIO + 示例 longan-nano-blink)
我买了两个longan nano, 其中一个使用参照http://longan.sipeed.com/zh/get_started/rv-link.html烧录成
RV-LINK,参照http://longan.sipeed.com/zh/get_started/blink.html制作Blink 闪灯程序,选择示例时选择longan-nano-blink
设置A4( GPIO_PIN_4)引脚为下拉(GPIO_MODE_IPD)输入,试验时接通3.3V时点亮red_led
视频链接
下边为修改的两个文件
platformio.ini
; PlatformIO Project Configuration File
; Build options: build flags, source filter, extra scripting
; Upload options: custom port, speed and extra flags
; Library options: dependencies, extra library storages
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html
[env:sipeed-longan-nano]platform = gd32v
framework = gd32vf103-sdk
board = sipeed-longan-nano
monitor_speed = 115200
upload_protocol = rv-link
debug_tool = rv-link
debug_port = COM2
main.c
#include "gd32vf103.h"
#include "systick.h"
#include
void longan_led_init()
{
rcu_periph_clock_enable(RCU_GPIOC);
rcu_periph_clock_enable(RCU_GPIOA);
gpio_init(GPIOC, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_13);
gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_2);
gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_1);
gpio_init(GPIOA, GPIO_MODE_IPD , GPIO_OSPEED_50MHZ, GPIO_PIN_4);
}
void longan_red_on()
{
gpio_bit_reset(GPIOC, GPIO_PIN_13);
}
void longan_red_off()
{
gpio_bit_set(GPIOC, GPIO_PIN_13);
}
void longan_blue_on()
{
gpio_bit_reset(GPIOA, GPIO_PIN_2);
}
void longan_blue_off()
{
gpio_bit_set(GPIOA, GPIO_PIN_2);
}
void longan_green_on()
{
gpio_bit_reset(GPIOA, GPIO_PIN_1);
}
void longan_green_off()
{
gpio_bit_set(GPIOA, GPIO_PIN_1);
}
int main(void)
{
longan_led_init();
while(1){
longan_blue_on();
delay_1ms(1000);
longan_blue_off();
delay_1ms(1000);
longan_green_on();
delay_1ms(1000);
longan_green_off();
delay_1ms(1000);
if(gpio_input_bit_get(GPIOA, GPIO_PIN_4)){
longan_red_on();
delay_1ms(10000);
longan_red_off();
}
}
}