描述
本文来源电子发烧友社区,作者:黄宝亚, 帖子地址:https://bbs.elecfans.com/jishu_2289351_1_1.html
-
#include
-
#include
-
#include
-
#include
-
#include //define O_WRONLY and O_RDONLY
-
//芯片复位引脚: P1_16,用于控制蜂鸣器信号口
-
#define SYSFS_GPIO_EXPORT "/sys/class/gpio/export"
-
#define SYSFS_GPIO_RST_PIN_VAL "448"
-
#define SYSFS_GPIO_RST_DIR "/sys/class/gpio/gpio448/direction"
-
#define SYSFS_GPIO_RST_DIR_VAL "OUT"
-
#define SYSFS_GPIO_RST_VAL "/sys/class/gpio/gpio448/value"
-
#define SYSFS_GPIO_RST_VAL_H "1"
-
#define SYSFS_GPIO_RST_VAL_L "0"
-
int main()
-
{
-
int fd;
-
//打开端口/sys/class/gpio# echo 448 > export
-
fd = open(SYSFS_GPIO_EXPORT, O_WRONLY);
-
if(fd == -1)
-
{
-
printf("ERR: Radio hard reset pin open error.n");
-
return EXIT_FAILURE;
-
}
-
write(fd, SYSFS_GPIO_RST_PIN_VAL ,sizeof(SYSFS_GPIO_RST_PIN_VAL));
-
close(fd);
-
//设置端口方向/sys/class/gpio/gpio448# echo out > direction
-
fd = open(SYSFS_GPIO_RST_DIR, O_WRONLY);
-
if(fd == -1)
-
{
-
printf("ERR: Radio hard reset pin direction open error.n");
-
return EXIT_FAILURE;
-
}
-
write(fd, SYSFS_GPIO_RST_DIR_VAL, sizeof(SYSFS_GPIO_RST_DIR_VAL));
-
close(fd);
-
//输出复位信号: 拉高>100ns
-
fd = open(SYSFS_GPIO_RST_VAL, O_RDWR);
-
if(fd == -1)
-
{
-
printf("ERR: Radio hard reset pin value open error.n");
-
return EXIT_FAILURE;
-
}
-
while(1)
-
{
-
write(fd, SYSFS_GPIO_RST_VAL_H, sizeof(SYSFS_GPIO_RST_VAL_H));//响铃
-
usleep(1000000);//延时
-
}
-
close(fd);
-
printf("INFO: Radio hard reset pin value open error.n");
-
return 0;
-
}
复制代码
打开APP阅读更多精彩内容