Hi, i tried to using the switch on tiva to control an external air pump. The code below is to create a 100ms delay for the air pump (port D pin 3). Can anyone help to check the code please? Thank you so much.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
bool bSw1_Level;
//uint32_t INT_PORTD;
int main(void){
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);//configure system clock
SysCtlDelay(2000000);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);//enable port F
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);//enable port D
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_4);//configure PortF pin 4 as input
GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_3);//configure portD pin3 as output
// GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_3,0x08);
// GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_3,0x00);
// bSw1_Level = GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0);
GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_4,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
//GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4 , GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
//GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_3,0x08);
//SysCtlDelay(1000000);
bSw1_Level = GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0);
while(1)
{ if (bSw1_Level==1)
{
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_3,0x00);
}else
{
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_3,0x08);
SysCtlDelay(1000000);}
}
}
