[RaspberryPi]bcm2835
2021/10
25
17:10
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.70.tar.gz
tar -xf bcm2835-1.70.tar.gz
cd bcm2835-1.70/
./configure
make
sudo make check
sudo make install
-------------------------------------------
vim test.c
-------------------------------------------
#include <bcm2835.h>
#define LEDA_PIN RPI_GPIO_P1_16 /* LED灯A使用P1上的16引脚 */
#define LEDB_PIN RPI_GPIO_P1_18 /* LED灯A使用P1上的18引脚 */
int main(int argc, char **argv)
{
if (!bcm2835_init())
return 1;
/* 初始化GPIO端口 */
bcm2835_gpio_fsel(LEDA_PIN, BCM2835_GPIO_FSEL_OUTP);//初始化LEDA为输出模式
bcm2835_gpio_write(LEDA_PIN, LOW);//拉低
bcm2835_gpio_fsel(LEDB_PIN, BCM2835_GPIO_FSEL_OUTP);//初始化LEDB为输出模式
bcm2835_gpio_write(LEDB_PIN, LOW);//拉低
while (1) {
bcm2835_gpio_write(LEDA_PIN, HIGH);//LEDA点亮
bcm2835_gpio_write(LEDB_PIN, LOW); //LEDB灭掉
bcm2835_delay(250);//延迟
bcm2835_gpio_write(LEDA_PIN, LOW); //LEDA灭掉
bcm2835_gpio_write(LEDB_PIN, HIGH);//LEDB点亮
bcm2835_delay(250);
}
return 0;
}
gcc -Wall -o test.out test.c -lbcm2835
./test.out
CopyRights: The Post by BY-NC-SA For Authorization,Original If Not Noted,Reprint Please Indicate From 老刘@开发笔记
Post Link: [RaspberryPi]bcm2835
Post Link: [RaspberryPi]bcm2835