新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > GPIO輸出---LED流水燈(EasyARM2131)

GPIO輸出---LED流水燈(EasyARM2131)

作者: 時間:2016-11-10 來源:網(wǎng)絡 收藏
/****************************************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"

本文引用地址:http://2s4d.com/article/201611/317406.htm

/*LED8~LED1 這8個LED分別由P1.25~P1.18控制*/

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

/*************************************************************************
** 函數(shù)名稱:DelayNS()
** 函數(shù)功能:長軟件延時
** 入口參數(shù):dly延時控制值,值越大,延時越長
** 出口參數(shù):無
*************************************************************************/

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

/*************************************************************************
** 函數(shù)名稱:main()
** 函數(shù)功能:流水燈顯示程序
** 調(diào)試說明:需將跳線JP12連接至LED8~LED1
*************************************************************************/

/*流水燈花樣,低電平點亮,調(diào)用時使用了取反操作*/
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
*****************************************************************************/



評論


技術專區(qū)

關閉