P17
PWM的API
查看LED对应的GPIO引脚
输出PWM改变LED亮度
PWM扩展实验
static void PWMTask(void)
{
unsigned int i;
//初始化GPIO
GpioInit();
//设置GPIO_2引脚复用功能为PWM
IoSetFunc(WIFI_IOT_IO_NAME_GPIO_2, WIFI_IOT_IO_FUNC_GPIO_2_PWM2_OUT);
//设置GPIO_2引脚为输出模式
GpioSetDir(WIFI_IOT_GPIO_IDX_2, WIFI_IOT_GPIO_DIR_OUT);
//初始化PWM2端口
PwmInit(WIFI_IOT_PWM_PORT_PWM2);
uint8_t j = 0;
while (1)
{
for (i = 0; i < 40000; i += 100)
{
//输出不同占空比的PWM波
PwmStart(WIFI_IOT_PWM_PORT_PWM2, i, 40000);
//PwmStop(WIFI_IOT_PWM_PORT_PWM2);
usleep(10);
}
i = 0;
j++;
if(j == 5)
{
PwmDeinit(WIFI_IOT_PWM_PORT_PWM2);
}
}
}
P20
UART API介绍
查看UART1对应的GPIO引脚
static void UART_Task(void)
{
uint8_t uart_buff[UART_BUFF_SIZE] = {0};
uint8_t *uart_buff_ptr = uart_buff;
uint32_t ret;
WifiIotUartAttribute uart_attr = {
//baud_rate: 9600
.baudRate = 9600,
//data_bits: 8bits
.dataBits = 8,
.stopBits = 1,
.parity = 0,
};
//Initialize uart driver
ret = UartInit(WIFI_IOT_UART_IDX_1, &uart_attr, NULL);
if (ret != WIFI_IOT_SUCCESS)
{
printf("Failed to init uart! Err code = %d\n", ret);
return;
}
printf("UART Test Start\n");
while (1)
{
printf("=======================================\r\n");
printf("*************UART_example**************\r\n");
printf("=======================================\r\n");
//通过串口1发送数据
UartWrite(WIFI_IOT_UART_IDX_1, (unsigned char *)data, strlen(data));
//通过串口1接收数据
UartRead(WIFI_IOT_UART_IDX_1, uart_buff_ptr, UART_BUFF_SIZE);
printf("Uart1 read data:%s", uart_buff_ptr);
usleep(1000000);
}
}
结果
在这里插入图片描述
版权声明:本文为CSDN博主「Lumos。」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/whale_1901/article/details/122832310
P17
PWM的API
查看LED对应的GPIO引脚
输出PWM改变LED亮度
PWM扩展实验
static void PWMTask(void)
{
unsigned int i;
//初始化GPIO
GpioInit();
//设置GPIO_2引脚复用功能为PWM
IoSetFunc(WIFI_IOT_IO_NAME_GPIO_2, WIFI_IOT_IO_FUNC_GPIO_2_PWM2_OUT);
//设置GPIO_2引脚为输出模式
GpioSetDir(WIFI_IOT_GPIO_IDX_2, WIFI_IOT_GPIO_DIR_OUT);
//初始化PWM2端口
PwmInit(WIFI_IOT_PWM_PORT_PWM2);
uint8_t j = 0;
while (1)
{
for (i = 0; i < 40000; i += 100)
{
//输出不同占空比的PWM波
PwmStart(WIFI_IOT_PWM_PORT_PWM2, i, 40000);
//PwmStop(WIFI_IOT_PWM_PORT_PWM2);
usleep(10);
}
i = 0;
j++;
if(j == 5)
{
PwmDeinit(WIFI_IOT_PWM_PORT_PWM2);
}
}
}
P20
UART API介绍
查看UART1对应的GPIO引脚
static void UART_Task(void)
{
uint8_t uart_buff[UART_BUFF_SIZE] = {0};
uint8_t *uart_buff_ptr = uart_buff;
uint32_t ret;
WifiIotUartAttribute uart_attr = {
//baud_rate: 9600
.baudRate = 9600,
//data_bits: 8bits
.dataBits = 8,
.stopBits = 1,
.parity = 0,
};
//Initialize uart driver
ret = UartInit(WIFI_IOT_UART_IDX_1, &uart_attr, NULL);
if (ret != WIFI_IOT_SUCCESS)
{
printf("Failed to init uart! Err code = %d\n", ret);
return;
}
printf("UART Test Start\n");
while (1)
{
printf("=======================================\r\n");
printf("*************UART_example**************\r\n");
printf("=======================================\r\n");
//通过串口1发送数据
UartWrite(WIFI_IOT_UART_IDX_1, (unsigned char *)data, strlen(data));
//通过串口1接收数据
UartRead(WIFI_IOT_UART_IDX_1, uart_buff_ptr, UART_BUFF_SIZE);
printf("Uart1 read data:%s", uart_buff_ptr);
usleep(1000000);
}
}
结果
在这里插入图片描述
版权声明:本文为CSDN博主「Lumos。」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/whale_1901/article/details/122832310
暂无评论