📄 main.c
字号:
/****************************************************
*名 称: GPIO测试文件 *
*功 能: 测试GPIO输出,测试流水灯 *
*备 注: 2011.1.8 *
贞明电子:http://shop58972409.taobao.com * *
*****************************************************/
/**************** 头文件调用&&宏定义 ****************/
#include "LPC11xx.h"
#include "GPIO.H"
/******************* 全局变量定义 *******************/
/********************** 函数声明 ********************/
__inline void delay_ms(uint32_t a);
/********************** 主函数 **********************/
int main(void)
{
SystemInit(); //系统初始化,包括使能时钟
GPIOInit(); //GPIO初始化,使能GPIO模块时钟
GPIOSetDir(PORT2,8,1); //设置P2.8为输出,LED1
GPIOSetDir(PORT2,9,1); //设置P2.9为输出,LED2
GPIOSetDir(PORT3,4,1); //设置P3.4为输出,LED3
//调用头文件中函数输出方法
GPIOSetValue(PORT2,8,0); //设置P2.8输出0,点亮LED1
GPIOSetValue(PORT2,9,0); //设置P2.9输出0,点亮LED2
GPIOSetValue(PORT3,4,0); //设置P3.4输出0,点亮LED3
delay_ms(500);
//直接使用寄存器
LPC_GPIO2->DATA|=(((1<<8)|(1<<9))); //P2.8,P2.9输出1,LED1,LED2灭
LPC_GPIO3->DATA|=(1<<4); //LED3灭
delay_ms(500);
while(1)
{
GPIOSetValue(PORT2,8,0); //设置P2.8输出0,LED1亮
GPIOSetValue(PORT2,9,1); //设置P2.9输出1,LED2灭
GPIOSetValue(PORT3,4,1); //设置P3.4输出1,LED3灭
delay_ms(500);
GPIOSetValue(PORT2,8,1); //设置P2.8输出1,LED1灭
GPIOSetValue(PORT2,9,0); //设置P2.9输出0,LED2亮
GPIOSetValue(PORT3,4,1); //设置P3.4输出1,LED3灭
delay_ms(500);
GPIOSetValue(PORT2,8,1); //设置P2.8输出1,LED1灭
GPIOSetValue(PORT2,9,1); //设置P2.9输出1,LED2灭
GPIOSetValue(PORT3,4,0); //设置P3.4输出0,LED3亮
delay_ms(500);
}
}
/********************** 函数定义 ********************/
/****************************************************
*名 称: 延时函数 *
*参 数: 延时时间 *
*备 注: 内联函数 *
*****************************************************/
__inline void delay_ms(uint32_t a) //1ms延时函数
{
uint32_t i;
while( --a != 0){
for(i = 0; i<5500; i++);
}
}
/****************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -