//通过PWM呼吸灯实验-A12连接一个LED,?A12接长脚,短脚接GND
//,by?txwtech
//通过PWM呼吸灯实验-A12连接一个LED, A12接长脚,短脚接GND
//,by txwtech
#include <stdio.h>
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "iot_gpio.h"
#include "hi_io.h"
#include "iot_pwm.h"
#include "hi_pwm.h"
#include "hi_time.h"
static void GpioTask(void *arg)
{
(void) arg;
hi_gpio_init();
hi_io_set_func(HI_IO_NAME_GPIO_12,HI_IO_FUNC_GPIO_12_PWM3_OUT);
//
hi_pwm_init(HI_PWM_PORT_PWM3);
hi_pwm_set_clock(PWM_CLK_160M);
while(1)
{
IotGpioValue val=IOT_GPIO_VALUE0;
IoTGpioGetOutputVal(HI_IO_NAME_GPIO_12,&val);
printf("execute pwm,value: %d\n",val);
for(int i=10;i<200;i++)
{
hi_pwm_start(HI_PWM_PORT_PWM3,i,200);
osDelay(1);
}
for(int i=200;i>10;i--)
{
hi_pwm_start(HI_PWM_PORT_PWM3,i,200);
osDelay(1);
}
}
}
static void GpioEntry(void)
{
osThreadAttr_t attr={0};
attr.name="GpioTask";
attr.stack_size=4096;
attr.priority=osPriorityNormal;
if(osThreadNew(GpioTask,NULL,&attr)==NULL)
{
printf("[GpioEntry] create GpioTask failed!\n");
}
}
SYS_RUN(GpioTask);
//SYS_RUN(GpioEntry);
?https://blog.csdn.net/YangHxuan/article/details/118911199?其他资料参考
|