新闻中心

EEPW首页>嵌入式系统>设计应用> GPIO输出---LED流水灯(EasyARM2131)

GPIO输出---LED流水灯(EasyARM2131)

作者: 时间:2016-11-10 来源:网络 收藏
/****************************************Copyright (c)*******************

**--------------File Info------------------------------------------------
** File name:main.c
** Last modified Date: 2011/04-09
** Last Version:1.0
** Descriptions:The main() function example template
**
**-----------------------------------------------------------------------
** Created by:lxliu
** Created date:2011-04-09
** Version:1.0
** Descriptions:The original version
*************************************************************************/
#include "config.h"

本文引用地址://m.amcfsurvey.com/article/201611/317406.htm

/*LED8~LED1 这8个LED分别由P1.25~P1.18控制*/

const uint32 LEDS8 = (0xFF<<18);

/*************************************************************************
** 函数名称:DelayNS()
** 函数功能:长软件延时
** 入口参数:dly延时控制值,值越大,延时越长
** 出口参数:无
*************************************************************************/

void DelayNS(uint32 dly)
{
uint32 i;
for(;dly>0;dly--)
for(i=0;i<50000;i++);
}

/*************************************************************************
** 函数名称:main()
** 函数功能:流水灯显示程序
** 调试说明:需将跳线JP12连接至LED8~LED1
*************************************************************************/

/*流水灯花样,低电平点亮,调用时使用了取反操作*/
const uint32 LED_TBL[] =
{
0x00,0xFF, //全部熄灭后再次点亮
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80, //依次逐个点亮
0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF, //依次逐个叠加
0xFF,0x7f,0x3F,0x1F,0x0F,0x07,0x03,0x01, //依次逐个递减
0x81,0x42,0x24,0x18,0x18,0x24,0x42,0x81, //两个靠拢后分开
0x81,0xC3,0xE7,0xFF,0xFF,0xE7,0xC3,0x81 //从两边叠加后递减
};

int main (void)
{
uint8 i;

PINSEL2 = PINSEL2 & (~0x08); //P1[25:16]为GPIO功能,PINSEL2的第三位设置为0
IO0DIR = LEDS8; //设置P1.25~P1.18为输出
while(1)
{
for (i=0;i<42;i++)
{
IO1SET = ~((LED_TBL[i])<<18);
DelayNS(50);
IO1CLR = ~((LED_TBL[i])<<18);
DelayNS(50);
}
}
return 0;
}
/*****************************************************************************
** End Of File
*****************************************************************************/



评论


技术专区

关闭