?? 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 + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -