LPC2131的GPIO輸出
原理圖:
本文引用地址:http://m.butianyuan.cn/article/201611/317410.htm程序清單:
/****************************************Copyright (c)**************************************************
*
**--------------File Info-------------------------------------------------------------------------------
** File name:main.c
** Last modified Date: 2011-04-27
** Last Version:1.0
** Descriptions:The main() function example template
**------------------------------------------------------------------------------------------------------
** Created by:lxliu
** Created date:2011-04-27
** Version:1.0
** Descriptions:The original version
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include "config.h"
void DelayNS(uint32 dly)
{
uint32 i;
for(;dly>0;dly--)
for(i=0;i<50000;i++);
}
int main (void)
{
uint32 i; //循環(huán)變量
uint32 LED = (1<<18); //P1[25:18]控制LED,初值指向LED1
uint32 BEEP = (1<<7); //P0.7控制蜂鳴器,低電平蜂鳴器蜂鳴
PINSEL2 = PINSEL2 & (~0x08); //P1[25:16]設(shè)置為GPIO功能
PINSEL0 = 0x00000000; //P0[15:0]設(shè)置為GPIO功能
IO0DIR = BEEP; //設(shè)置BEEP控制口為輸出
IO0SET = BEEP; //蜂鳴器停止蜂鳴
while(1)
{
for(i=0;i<8;i++) //8個LED
{
IO1DIR = LED; //當(dāng)前的LED設(shè)置為輸出
IO1SET = LED; //當(dāng)前的LED熄滅
DelayNS(100); //延時
IO1CLR = LED; //當(dāng)前的LED點亮
DelayNS(100); //延時
IO1SET = LED; //當(dāng)前的LED熄滅
LED =(LED<<1); //左移一位,
}
IO0CLR = BEEP; //8個LED點亮一遍后,蜂鳴器蜂鳴
DelayNS(100); //延時
IO0SET = BEEP; //蜂鳴器停止蜂鳴
DelayNS(500); //延時
LED = (1<<18);//為LED賦初值
}
return 0;
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
評論