C语言编写代码,配置GPIO0-12引脚为输出引脚,并将引脚电平拉高
时间: 2024-05-08 19:18:25 浏览: 106
下面是在C语言中配置GPIO0-12引脚为输出引脚,并将引脚电平拉高的示例代码:
```
#include <stdio.h>
#include <wiringPi.h>
int main(void)
{
if (wiringPiSetup() == -1) {
printf("Setup failed.\n");
return 1;
}
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
digitalWrite(0, HIGH);
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
return 0;
}
```
这段代码使用了WiringPi库来初始化GPIO引脚,并通过pinMode函数将所有引脚设置为输出模式。最后,通过digitalWrite函数将所有引脚的电平拉高。
阅读全文