// 如果PB0接按键、PB1接LED,则可以通过按键控制LED亮灭
#include "hw_types.h" #include "hw_memmap.h" #include "hw_sysctl.h" #include "hw_gpio.h" #include "src/sysctl.h" #include "src/gpio.h"
// 将较长的标识符定义成较短的形式 #define SysCtlPeriphEn SysCtlPeripheralEnable #define GPIOPinTypeIn GPIOPinTypeGPIOInput #define GPIOPinTypeOut GPIOPinTypeGPIOOutput
#define PB0 GPIO_PORTB_BASE, GPIO_PIN_0 #define PB1 GPIO_PORTB_BASE, GPIO_PIN_1
void timeDelay (unsigned long ulVal) { do { } while ( --ulVal != 0 ); }
int main (void) { unsigned char ucVal;
timeDelay(1500000L); // 开机延迟
SysCtlPeriphEn(SYSCTL_PERIPH_GPIOB); // 使能GPIOB模块 GPIOPinTypeIn(PB0); // 设置PB0为输入模式 GPIOPinTypeOut(PB1); // 设置PB1为输出模式
for (;;) { ucVal = GPIOPinRead(PB0); // 读取PB0的状态 GPIOPinWrite(PB1, (ucVal << 1)); // 将PB0的状态写入PB1 timeDelay(300); } } |