阅读 59

GPIO编程

  1. 查看s5pv210 用户手册,及实验板电路图,用uboot修改内存命令 mw 来实现 点亮实验板的一个led灯。(提示 uboot命令: mw addr value 表示向内存为addr处写数据value),写出正确的命令。(核心板电路图p5,p13)(选做)

#define		gph2con		*(volatile unsigned*)0xe0200c40
#define		gph2dat		*(volatile unsigned*)0xe0200c44
#define		gph2pud		*(volatile unsigned*)0xe0200c48

#define		gpj2con		*(volatile unsigned*)0xe0200280
#define		gpj2dat		*(volatile unsigned*)0xe0200284
#define		gpj2pud		*(volatile unsigned*)0xe0200288

int (*print)(char *,...)	=	(int (*)(char*,...)) 0x2fd17b18;
void delay( unsigned );
void _start( void )
{
	
	unsigned i;
	gph2con		=	gph2con & ~0xffff; //0~3口,配置成输入
	gph2pud		=	gph2pud & ~0xff | 0xaa; //0-3 接上拉电阻,不接也不影响,接了驱动能力更强一点

	gpj2con		=	gpj2con & ~0xffff | 0x1111; //0-3引脚 配置成输出功能
	gpj2pud		=	gpj2pud & ~0xff | 0x55;// 接上下拉电阻,不接也没影响
	gpj2dat		|=	0xf;//初始化为 输出高电平,4个led灯为熄灭状态
	while(1)
	{
		if((gph2dat & 0xf)<0xf)//判断是否有按键按下
		{
			for( i=0;((gph2dat>>i) & 0x1)!=0;i++);//找出哪个键按下		
			print("NO.%u pressed!\n",i);
		}
		gpj2dat		=	gpj2dat & ~0xf | (gph2dat & 0xf); //点亮对应的灯
		delay( 500000 ); //延时
	}

}

void delay( unsigned u )
{
	for( ; u--; );
}
复制代码
  1. 查看s5pv210 用户手册,及实验板电路图,编写c程序 2c.c 实现轮流点亮实验板上4个led灯.
#define		gpj2con		*(unsigned*)0xe0200280
#define		gpj2dat		*(unsigned*)0xe0200284
#define		gpj2pud		*(unsigned*)0xe0200288
void delay(int);
void _start( void )
{
	int led = 0xf;
	int i=0;
	gpj2con		=	0x1111;
	gpj2pud		=	0xaa;
	gpj2dat		=	led;
	
	while( 1 )
	{
		gpj2dat		=	led & ~( 1 << i );
		i		=	++i%4;
		delay(500000);
	}
}

void delay(int i)
{
	for(;i--;);
}

复制代码
  1. 编写c旅程2c.c,实现:按一次键(按下松开)点亮对应的LED,再按一次,关闭对应的LED….。(实现4个按键即可)
#define		gph2con		*(volatile unsigned*)0xe0200c40
#define		gph2dat		*(volatile unsigned*)0xe0200c44
#define		gph2pud		*(volatile unsigned*)0xe0200c48

#define		gpj2con		*(volatile unsigned*)0xe0200280
#define		gpj2dat		*(volatile unsigned*)0xe0200284
#define		gpj2pud		*(volatile unsigned*)0xe0200288


void delay( unsigned );
void _start( void )
{
	unsigned i;
	unsigned ledon[4]={0};
	unsigned tmp;
	gph2con		=	gph2con & ~0xffff;
	gph2pud		=	gph2pud & ~0xff | 0xaa;

	gpj2con		=	gpj2con & ~0xffff | 0x1111;
	gpj2pud		=	gpj2pud & ~0xff | 0x55;
	gpj2dat		|=	0xf;

	while(1)
	{
		if( (gph2dat & 0xf) < 0xf)
		{	
			tmp			=	gph2dat;
			while( ( gph2dat & 0xf ) != 0xf );  //消除按键抖动
			for(i=0; ((tmp>>i) & 0x1) != 0; i++); //找出哪个键按下
				
			gpj2dat		=	(gpj2dat & ~(0x1 << i))|(ledon[i]<<i);
			ledon[i]	=	ledon[i]^0x1;	
		
		}
		
		delay(100000);
		
	}

}

void delay( unsigned u )
{
	for( ; u--; );
}

复制代码
文章分类
代码人生
文章标签