DSP 之GPIO编程

废话少说-直接领略流水灯的乐趣吧!

/******************************************************************************/
/*  Copyright 2004 by SEED Electronic Technology LTD.                         */
/*  All rights reserved. SEED Electronic Technology LTD.                      */
/*  Restricted rights to use, duplicate or disclose this code are             */
/*  granted through contract.                                                 */
/*                                                                            */
/*                                                                            */
/******************************************************************************/



#include <csl.h>
#include <csl_pll.h>
#include <csl_chip.h>
#include <csl_gpio.h>



#include <stdio.h>

void delay();




	

/*锁相环的设置*/
PLL_Config  myConfig      = {
  0,    //IAI: the PLL locks using the same process that was underway 
                //before the idle mode was entered
  1,    //IOB: If the PLL indicates a break in the phase lock, 
                //it switches to its bypass mode and restarts the PLL phase-locking                //sequence
  24,    //PLL multiply value; multiply 24 times
  1             //Divide by 2 PLL divide value; it can be either PLL divide value 
                //(when PLL is enabled), or Bypass-mode divide value
                //(PLL in bypass mode, if PLL multiply value is set to 1)
};



void UserGpio(void)
{
	int val;
	
	/* Enable a pin as GPIO pin */
	GPIO_pinEnable (GPIO_PIN1);
	
	/* Write a value to a GPIO pin */
	GPIO_pinWrite(GPIO_PIN1, 2);
	
	/* Reads the value in a general purpose input pin */
	val = GPIO_pinRead(GPIO_PIN1);
	printf("Read GPIO_GPIO_PIN1 value = %d\n", val);
	//printf("GPIO register address %d\n", GPIO_ADDR(val));
	
	/* reads IOO and IO7 pin values */
	val=GPIO_pinRead (GPIO_PIN0| GPIO_PIN1);

	/* DiEnable a GPIO */
	GPIO_pinDisable (GPIO_PIN1);
	
	/* Writes value to non-parallel registers using GPIO_config */
	//GPIO_config( myConfig);
	
	
	
}



main()
{
	int i = 10;
	
	/*初始化CSL库*/	
    CSL_init();
    
    /*设置系统的运行速度为144MHz*/
    PLL_config(&myConfig);
    /*确定方向为输出*/
    GPIO_RSET(IODIR,0xFF);
    
    for(i = 0;i<0x0a;i++)
    {
    	 /*全亮*/
    	GPIO_RSET(IODATA,0xff);
    	delay();
   		/*全灭*/
   		GPIO_RSET(IODATA,0x0);
   		delay();
    }
	/*循环闪烁*/   
   	for(i = 10; i >= 0; i--)
   	{
   		GPIO_RSET(IODATA,0x1);
   		delay();
		delay();
   		GPIO_RSET(IODATA,0x2);
   		delay();
		delay();
   		GPIO_RSET(IODATA,0x4);
   		delay();
		delay();
   		GPIO_RSET(IODATA,0x8);
   		delay();
		delay();
   		GPIO_RSET(IODATA,0x10);
   		delay();
		delay();
   		GPIO_RSET(IODATA,0x40);
   		delay();
		delay();
   		GPIO_RSET(IODATA,0x80);
   		delay();
   		delay();	
   	}
   	
   	UserGpio();			  
}

// 延时函数
void delay()
{
	Uint32 j = 0,k = 0;
	for(j = 0;j<0x0c;j++)
	{
		for(k= 0;k<0xffff;k++)
		{}
	}
}





 

让生命中的每一份执着都像流水灯一样,允不停息的闪烁下去吧!

 

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值