bb black gpio点灯

1.安装交叉编译工具链,选择TI官网镜像对应的工具链

2.解压后添加环境变量sudo vi /etc/bash.bashrc 最后添加路径

export PATH=$PATH:/home/linux/toolchain/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/bin

3. source /etc/bash.bashrc 使环境变量生效

4.编译.c文件arm-linux-gnueabihf-gcc -c hello.c -o bhellob

5.传文件到板子,在板子上修改权限777,后 ./ 可以执行

6.通过echo命令控制led

bb black gpio点灯_第1张图片

7.用C语言写循环100次

#include
#include
#include
#include
int main(void)
{
 FILE *p=NULL;
 int i=0;
 p = fopen("/sys/class/gpio/export","w");
 fprintf(p,"%d",44);
 fclose(p);
 p = fopen("/sys/class/gpio/gpio44/direction","w");
 fprintf(p,"out");
 fclose(p);
 for(i=0;i<100;i++)
 {
  p = fopen("/sys/class/gpio/gpio44/value","w");
  fprintf(p,"%d",1);
  sleep(1);
  fclose(p);
  p = fopen("/sys/class/gpio/gpio44/value","w");
  fprintf(p,"%d",0);
  sleep(1);
  fclose(p);
 }
 p = fopen("/sys/class/gpio/unexport","w");
 fprintf(p,"%d",44);
 fclose(p);
 return 0;
}


你可能感兴趣的:(嵌入式linux)