使用AB32VG1在RT-Thread Studio 进行编写。
#include <rtthread.h>
#include "board.h"
int main(void)
{
uint8_t green = rt_pin_get("PE.4"); //定义绿色LED灯的引脚,uint8_t为数据类型
uint8_t key = rt_pin_get("PF.1"); //定义按键引脚
rt_pin_mode(green, PIN_MODE_OUTPUT); //定义LED为输出
rt_pin_mode(key, PIN_MODE_INPUT_PULLUP ); //定义按键为输入
rt_pin_write(green, PIN_HIGH); //将LED置为高电平
while(1){
if(rt_pin_read(key) == 1)
{
rt_pin_write(green, PIN_LOW);
}
if(rt_pin_read(key) == 0)
{
rt_pin_write(green, PIN_HIGH);
}//while循环要有,使程序一直运行
}
}