LPC1766 GPIO输入和输出
今天入手了LPC1766,完全的寄存器操作和比较了STM32,LPC比较合适直接寄存器操作。今天学习成果如下(基于周立功LPC1766板):
/****************************************Copyright (c)****************************************************
** Guangzhou ZLGMCU Development Co., LTD
**--------------File Info---------------------------------------------------------------------------------
** File name: main.c
** Last modified Date: 2010-09-28
** Last Version: V1.0
** Descriptions: The main() function example template
**
**--------------------------------------------------------------------------------------------------------
** Created by: Lan wuqiang
** Created date: 2010-09-28
** Version: V1.00
** Descriptions: 整理模板,添加用户应用程序
**
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
** Rechecked by:
*********************************************************************************************************/
#include "LPC17xx.h" /* LPC17xx外设寄存器 */
/*********************************************************************************************************
变量与宏定义
*********************************************************************************************************/
#define BEEP (1 < 11) /* P0.11连接蜂鸣器 */
#define KEY1 (LPC_GPIO2->FIOPIN & (1 < 10)) /* P2.10连接KEY1 */
#define KEY2 (LPC_GPIO2->FIOPIN & (1 < 11)) /* P2.11连接KEY2 */
#define KEY3 (LPC_GPIO2->FIOPIN & (1 < 12)) /* P2.12连接KEY3 */
#define KEY4 (LPC_GPIO2->FIOPIN & (1 < 13)) /* P2.13连接KEY4 */
#define BEEPOFF() LPC_GPIO0->FIODIR |= BEEP;LPC_GPIO0->FIOSET |= BEEP /* 蜂鸣器关 */
#define BEEPON() LPC_GPIO0->FIODIR |= BEEP;LPC_GPIO0->FIOCLR |= BEEP /*蜂鸣器开 */
#define LED1 (1 < 0) /* P2.0连接LED1 */
#define LED2 (1 < 1) /* P2.1连接LED2 */
#define LED3 (1 < 2) /* P2.2连接LED3 */
#define LED4 (1 < 3) /* P2.3连接LED4 */
#define LED1OFF() LPC_GPIO2->FIODIR |= LED1;LPC_GPIO2->FIOSET |= LED1 /* LED1关 */
#define LED1ON() LPC_GPIO2->FIODIR |= LED1;LPC_GPIO2->FIOCLR |= LED1 /* LED1开 */
#define LED2OFF() LPC_GPIO2->FIODIR |= LED2;LPC_GPIO2->FIOSET |= LED2 /* LED2关 */
#define LED2ON() LPC_GPIO2->FIODIR |= LED2;LPC_GPIO2->FIOCLR |= LED2 /* LED2开 */
#define LED3OFF() LPC_GPIO2->FIODIR |= LED3;LPC_GPIO2->FIOSET |= LED3 /* LED1关 */
#define LED3ON() LPC_GPIO2->FIODIR |= LED3;LPC_GPIO2->FIOCLR |= LED3 /* LED1开 */
#define LED4OFF() LPC_GPIO2->FIODIR |= LED4;LPC_GPIO2->FIOSET |= LED4 /* LED2关 */
#define LED4ON() LPC_GPIO2->FIODIR |= LED4;LPC_GPIO2->FIOCLR |= LED4 /* LED2开 */
/*********************************************************************************************************
** Function name: GPIOInit
** Descriptions: GPIO初始化
** input parameters: 无
** output parameters: 无
** Returned value: 无
*********************************************************************************************************/
void GPIOInit (void)
{
LPC_PINCON->PINSEL0 &= ~(0x03 < 22); /* 配置P0.11为GPIO */
LPC_PINCON->PINSEL4 &= 0XF00FFF00; /* 配置P2.0~P2.3和P2.10~P2.13为GPIO*/
LPC_GPIO0->FIODIR |= BEEP; /* 配置P0.11即BEEP为输出 1 */
LPC_GPIO2->FIODIR |= 0X000000FF; /* 配置P2.0~P2.3为输出 1 */
LPC_GPIO2->FIODIR &= 0XFFC3FFFF; /* 配置P2.10~P2.13为输入 0 */
LPC1766GPIO输入和输 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)