gpio_test

/* 
 * \file        gpio_test.c 
 * LIS3LV02DQ 
 * 
 * \version     1.0.0 
 * \date        2014年03月10日 
 * \author      jiangdou  <jiangdouu88@126.com> 
 * 
 * Copyright (c) 2014 jiangdou. All Rights Reserved. 
 * 
 *
dou@ubuntu:~/a10/linshi_chenxu$ /home/dou/a10/a20/A20-420-V12/lichee/out/linux/common/buildroot/external-toolchain/bin/arm-linux-gnueabi-gcc -o gpio gpio_test.c -static

*/
 

#include <stdio.h>    
#include <linux/types.h>    
#include <fcntl.h>    
#include <unistd.h>    
#include <stdlib.h>    
#include <sys/types.h>    
#include <sys/ioctl.h>    
#include <errno.h>    
#include <assert.h>    
#include <string.h>    



static const char *dev_data = "/sys/class/gpio_sw/PH19/data";		//raed write data
static const char *dev_mul_sel = "/sys/class/gpio_sw/PH19/mul_sel";	//0 is in,and 1 is out
static const char *dev_pull = "/sys/class/gpio_sw/PH19/pull";		//GPIO的内置电阻状态 0代表高阻,1代表上拉,2代表下拉
static const char *dev_drv_level = "/sys/class/gpio_sw/PH19/drv_level";	//*GPIO的驱动能力 有0到3四个等级


int gpio_init(void)
{
	//int fd1,fd2;
	int ret = 0;
	FILE *fd1 = fopen(dev_mul_sel, "w");
	if (fd1 < 0)
		printf("can't open device\n\r");
	
	fprintf(fd1,"0");					//设置为输入,6为中断模式
	fclose(fd1);
	FILE *fd2 = fopen(dev_pull, "w");
	if (fd2 < 0)
		printf("can't open device\n\r");
	
	fprintf(fd2,"1");			//端口上拉
	fclose(fd2);
	
	return 0;
}


int main(void)
{
	printf("mcp2515 in\n\r");
	
	int ret = 0;
	int value;
	unsigned char temp = 0;
	int a;
	gpio_init();
	
#if 0
	printf("gpio init  OK\n\r");
	int fd3 = open(dev_data, O_RDWR);
	if (fd3 < 0)
		printf("can't open device\n\r");
		
		
	char valueStr[32];
	memset(valueStr, 0,sizeof(valueStr));
	read(fd3, (void*)valueStr, sizeof(valueStr)-1);
	char *end;
	value =strtol(valueStr, &end, 0);
	
	if(end == valueStr){
		printf("Fail inconvert string %s to number.", valueStr);
		
		close(fd3);
	return -1;
	}

	
	printf("temp is %d\n\r",value);
	
#endif
	char valueStr[32];
	while(1)
	{	
	
		int fd3 = open(dev_data, O_RDWR);
		if (fd3 < 0)
		printf("can't open device\n\r");
		
		
		//char valueStr[32];
		memset(valueStr, 0,sizeof(valueStr));
		read(fd3, (void*)valueStr, sizeof(valueStr)-1);
		char *end;
		value =strtol(valueStr, &end, 0);
	
		if(end == valueStr){
			printf("Fail inconvert string %s to number.", valueStr);
		
			close(fd3);
			return -1;
		}

	
		printf("temp 2 is %d\n\r",value);
		a = atoi(value);
		printf("a 2 is %d\n\r",a);
		if(a = 0)
		{	
			printf("temp is 3 %d\n\r",value);
			usleep(1000);
			if(a = 0)
			{
				printf("temp is  4 %d\n\r",value);
			}
		}
			
	usleep(80000);
	
	}


return 0;

}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值