标签:
//example
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
int main(int argc, char * argv)
{
int i, n, fd;
char num;
int ret;
fd = open("/dev/kio", O_RDWR); //打开设备
if (fd < 0)
{
printf("can‘t open /dev/kio!\n");
exit(1);
}
sleep(1);
ioctl(fd, 1, GPIO_TO_PIN(1,22)); //设置gpio1-22为输出(user:led3)
ioctl(fd, 0, GPIO_TO_PIN(2, 1)); //设置gpio2-1 为输入(p8-18)
while (1)
{
num = 1;
ret = write(fd,"1",GPIO_TO_PIN(1,22));
if(ret < 0)
{
perror("write");
return -1;
}
sleep(1);
ret = write(fd,"0",GPIO_TO_PIN(1,22));
if(ret < 0)
{
perror("write");
return -1;
}
}
}
标签:
原文地址:http://www.cnblogs.com/zym0805/p/4276205.html