GPIO輸出---LED流水燈(EasyARM2131)
**--------------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"
/*LED8~LED1 這8個(gè)LED分別由P1.25~P1.18控制*/
const uint32 LEDS8 = (0xFF<<18);
/*************************************************************************
** 函數(shù)名稱:DelayNS()
** 函數(shù)功能:長(zhǎng)軟件延時(shí)
** 入口參數(shù):dly延時(shí)控制值,值越大,延時(shí)越長(zhǎng)
** 出口參數(shù):無(wú)
*************************************************************************/
void DelayNS(uint32 dly)
{
uint32 i;
for(;dly>0;dly--)
for(i=0;i<50000;i++);
}
/*************************************************************************
** 函數(shù)名稱:main()
** 函數(shù)功能:流水燈顯示程序
** 調(diào)試說(shuō)明:需將跳線JP12連接至LED8~LED1
*************************************************************************/
/*流水燈花樣,低電平點(diǎn)亮,調(diào)用時(shí)使用了取反操作*/
const uint32 LED_TBL[] =
{
0x00,0xFF, //全部熄滅后再次點(diǎn)亮
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80, //依次逐個(gè)點(diǎn)亮
0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF, //依次逐個(gè)疊加
0xFF,0x7f,0x3F,0x1F,0x0F,0x07,0x03,0x01, //依次逐個(gè)遞減
0x81,0x42,0x24,0x18,0x18,0x24,0x42,0x81, //兩個(gè)靠攏后分開(kāi)
0x81,0xC3,0xE7,0xFF,0xFF,0xE7,0xC3,0x81 //從兩邊疊加后遞減
};
int main (void)
{
uint8 i;
PINSEL2 = PINSEL2 & (~0x08); //P1[25:16]為GPIO功能,PINSEL2的第三位設(shè)置為0
IO0DIR = LEDS8; //設(shè)置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
*****************************************************************************/
評(píng)論