ARM裸机篇GPIO流水灯

终于谈到流水灯了,先看看电路图吧,

上拉电阻部分

图1

图1中所示的电路图是Led外接部分,上拉电阻方式连接,然后采用灌电流方式点亮LED灯,主要是看它怎么和我们主控芯片S3C2440相连接。

CPU部分

图2

图2所示就是LED的负极和S3C2440芯片相连接的部分图了,用到的GPIO脚是GPB7、GPB8、GPB5、GPB6。

然后再查DATASHEET即可查到GPB的控制寄存器:

GPB控制寄存器数据上拉方向

图3 GPB配置寄存器、数据寄存器、上拉使能寄存器

上图3就是GPB这组IO口的寄存器说明部分了,有各自的地址和说明和复位的初始值,还有为这组IO口保留的寄存器地址。当然我们只用到了GPB、5、6、7、8这4个GPIO口,下面继续看这三个寄存器的详细说明:

GPBCON控制寄存器

这样写下去还是没啥意思,讲下方法就行了,关于一些GPIO口的相关寄存器配置只要查DATASHEET就行了,我们把需要的那几个脚设置成输出,上拉就不用了,当然默认是存在上拉,也没关系,这样就是针对三个寄存器配置了如下:

GPBCON,GPBDAT,GPBUP

GPBCON:0x15400

GPBCON控制寄存器的值

GPBDAT=0X00;先让它们全部点亮吧。

主程序如下:

/***************************************************************************************
*	File Name					:	Main.c
*	Copyright					:	2011-2011 ecjtu Corporation,All Rights Reserved
*	Module Name					:	主函数
*
*	CPU							:	S3C2440
*	RTOS						:	NONE
*	Create Date					:	2011/12/10
*	Author/Corporation			:	涛行天下
*
*	Abstract Description		:	Place some description here
*---------------------------Revision History--------------------------------
*	Revision History
*	No.		Version		Date		       Revised by				Item		Description
*	1		V0.95		11.12.10 	涛行天下			...			....
***************************************************************************************/
//***************************************************
#include "def.h"
#include "option.h"
#include "2440addr.h"     
#include "2440lib.h"
#include "2440slib.h"      
//================================

/***************************************************************************************
*	Function Name				:	delay_led
*	Create Date					:	2011/12/10
*	Author/Corporation			:	涛行天下
*
*	Description					:	Find a proper thread in thread array
*
*	Param						:	U32 tt
*
*
*	Return Code					:	NONE
*	Global Variable				:	DISP_wuiSegmentAppID
*	File Static Variable		:	naucThreadNo
*	Function Static Variable	:	None
*	
*----------------------------------------------------
*	Revision History
*	No.		Date		Revised by			Item		Description
*	V0.0	2011/12/02	涛行天下			...			....
***************************************************************************************/
void delay_led(U32 tt)//延时子程序
{
   U32 i;
   for(;tt>0;tt--)
   {
     for(i=0;i<10000;i++)
	 {}
   }
}
   
/***************************************************************************************
*	Function Name				:	Main
*	Create Date					:	2011/12/10
*	Author/Corporation			:	涛行天下/华东交通大学
*
*	Description					:	主函数
*
*	Param						:	ThreadNo : someParam description
									ThreadStaus : someParam description
*
*
*	Return Code					:	Return Code description
									eg:
									ERROR_Fail : not find a thread
									ERROR_SUCCEED : found
*	Global Variable				:	DISP_wuiSegmentAppID
*	File Static Variable		:	naucThreadNo
*	Function Static Variable	:	None
*	
*----------------------------------------------------
*	Revision History
*	No.		Date		Revised by			Item		Description
*	V0.0	2011/12/02	涛行天下			...			....
***************************************************************************************/
int Main(int argc, char **argv)
{
	int i;
	U8 key;//定义键值
	U32 mpll_val=0;//定义
	int data;
  //M=92  P=1  S=1 
	mpll_val = (92<<12)|(1<<4)|(1);
	//////////////////////////////////////////////////////////
	//101 1100 0000 0000 0000
	// 			            1 0000
	//	             	                     1  
 	//101 1100 0000 0001 0001
	//////////////////////////////////////////////////////////
	//init FCLK=400M, so change MPLL first
	ChangeMPllValue((mpll_val>>12)&0xff, (mpll_val>>4)&0x3f, mpll_val&3);
	ChangeClockDivider(key, 12);    

	//ChangeClockDivider(1,1);    // 1:2:4    FCLK:HCLK:PCLK
    // rCLKDIVN=0x4;    //  1:4:4
    //ChangeMPllValue(82,2,1);     //FCLK=135.0Mhz     
	//ChangeMPllValue(82,1,1);     //FCLK=180.0Mhz     
    //ChangeMPllValue(161,3,1);    //FCLK=202.8Mhz 
    //ChangeMPllValue(117,1,1);    //FCLK=250.0Mhz 
    //ChangeMPllValue(122,1,1);    //FCLK=260.0Mhz 
    //ChangeMPllValue(125,1,1);    //FCLK=266.0Mhz 
    //ChangeMPllValue(127,1,1);    //FCLK=270.0Mhz  
    
    //MMU_EnableICache();
    //MMU_EnableDCache();
    
    MMU_DisableICache();
    MMU_DisableDCache();


    rGPBCON = 0x15400;
   
   
   	data = 0x06;//0000 0110
   	//0000 0110
   	//0000 0110
   	while(1)
   	{		
		rGPBDAT=0X00;
	}
   
   return 0;
}
原文地址:https://www.cnblogs.com/tao560532/p/2283568.html