📄 fio.c
字号:
/*****************************************************************************
* fio.c: Fast I/O module file for NXP LPC24xx Family Microprocessors
*
* Copyright(C) 2006, NXP Semiconductor
* All rights reserved.
*
* History
* 2006.07.13 ver 1.00 Prelimnary version, first Release
*
******************************************************************************/
#include "LPC2468.h" /* LPC24xx definitions */
#include "type.h"
#include "irq.h"
#include "timer.h"
#include "fio.h"
/*****************************************************************************
** Function name: GPIOInit
**
** Descriptions: initialize GPIO port
**
** parameters: port number and port type, Fast I/O or
** regular GPIO, direction
** Returned value: None
**
*****************************************************************************/
void GPIOInit( DWORD PortNum, DWORD PortType, DWORD PortDir )
{
if ( (PortType == REGULAR_PORT) && ((PortNum == 0) || (PortNum == 1)) )
{
SCS &= ~GPIOM; /* set GPIOx to use regular I/O */
if ( PortDir == DIR_OUT )
{
(*(volatile unsigned long *)(REGULAR_PORT_DIR_BASE
+ PortNum * REGULAR_PORT_DIR_INDEX)) = 0xFFFFFFFF;
}
else
{
(*(volatile unsigned long *)(REGULAR_PORT_DIR_BASE
+ PortNum * REGULAR_PORT_DIR_INDEX)) = 0x00000000;
}
}
else if ( PortType == FAST_PORT )
{
if ( (PortNum == 0) || (PortNum == 1) )
{
SCS |= GPIOM; /* set GPIOx to use Fast I/O */
}
if ( PortDir == DIR_OUT )
{
(*(volatile unsigned long *)(HS_PORT_DIR_BASE
+ PortNum * HS_PORT_DIR_INDEX)) = 0xFFFFFFFF;
}
else
{
(*(volatile unsigned long *)(HS_PORT_DIR_BASE
+ PortNum * HS_PORT_DIR_INDEX)) = 0x00000000;
}
}
return;
}
void LedsInit(void) // 初始化led端口
{
FIO3CLR = 0x0f000000; // P3.24~P3.27
}
void LedOn(unsigned int n) // 点亮第n个led
{
unsigned long LEDData=0x01000000;
n = n % 4; // 总共4个灯
LEDData = LEDData << n; // 移到对应位
FIO3SET = LEDData; // 置1点亮
}
void LedOff(unsigned int n) // 熄灭第n个led
{
unsigned long LEDData=0x01000000;
n = n % 4;
LEDData = LEDData << n;
FIO3CLR = LEDData; // 置0熄灭
}
/*********************************************************************************
** End Of File
*********************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -