微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > LM3S9B96 GPIO的读写

LM3S9B96 GPIO的读写

时间:11-11 来源:互联网 点击:
GPIO:general purpose input output,无非设置成输入模式和输出模式。

下面主函数中LED部分是将GPIO设置成输出模式的例子,KEY部分是将GPIO设置成输入模式的例子。

#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"

/* 寄存器地址 ---------------------------------------------------------------*/
#define GPIO_PORTF_APB_DIR_R 0x40025400
#define GPIO_PORTF_APB_DEN_R 0x4002551C

/* 用于调试 PF1 <-> LED -----------------------------------------------------*/
#define LED_PERIPH SYSCTL_PERIPH_GPIOF
#define LED_PORT GPIO_PORTF_BASE
#define LED_PIN GPIO_PIN_1
#define LED_OFF 1 < 1
#define LED_ON ~(1 < 1) // 低电平点亮LED

void Delay(volatile signed long nCount)
{
for(; nCount != 0; nCount--);
}

long test;
long clk;

int main(void)
{
// Set the clocking to run directly from the crystal.
/*SysCtlClockSet(SYSCTL_SYSdiv_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
clk = SysCtlClockGet();

// LED------------------------------------------------------------------------------
SysCtlPeripheralEnable(LED_PERIPH); // 使能LED所在的GPIO端口
GPIOPinTypeGPIOOutput(LED_PORT, LED_PIN); // 设置LED所在管脚为输出

while (1)
{
GPIOPinWrite(LED_PORT, LED_PIN, LED_ON); //点亮LED
Delay(0xfffff);
GPIOPinWrite(LED_PORT, LED_PIN, LED_OFF); //熄灭LED
Delay(0xfffff);
}*/

// Set the clocking to run directly from the crystal.
SysCtlClockSet(SYSCTL_SYSdiv_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

// Key------------------------------------------------------------------------------
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); // 使能GPIOJ端口
GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_7);
GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_7, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

while (1)
{
if (test = GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_7))
{
Delay(0xfffff);
}
}
}


Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top