Other Parts Discussed in Thread: C2000WARE
Tool/software:
Hi iam working on TMS320F280025C launchpad ,iam trying to use one gpio pin as button and trying to control the LED using this GPIO pin which i have taken as an input.But iam not getting any expected result.Below is my code please suggest any changes to make .
#include "driverlib.h"
#include "device.h"
#include "board.h"
#include "c2000ware_libraries.h"
//
// Main
//
#define LED_GPIO 31 // Onboard LED (GPIO0)
#define BUTTON_GPIO 42 // Use GPIO24 for custom button (J1.14 header pin)
void main(void)
{
//
//
Device_init();
//
// Disable pin locks and enable internal pull-ups.
//
Device_initGPIO();
//
// Initialize PIE and clear PIE registers. Disables CPU interrupts.
//
Interrupt_initModule();
//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
//
Interrupt_initVectorTable();
//
// PinMux and Peripheral Initialization
//
Board_init();
//
// C2000Ware Library initialization
//
C2000Ware_libraries_init();
;
EINT;
ERTM;
GPIO_setPadConfig(LED_GPIO, GPIO_PIN_TYPE_STD);
GPIO_setDirectionMode(LED_GPIO, GPIO_DIR_MODE_OUT);
// GPIO_writePin(LED_GPIO, 1); // Start with LED ON
// Configure BUTTON_GPIO as input with pull-up
GPIO_setPadConfig(BUTTON_GPIO, GPIO_PIN_TYPE_PULLUP);
GPIO_setDirectionMode(BUTTON_GPIO, GPIO_DIR_MODE_IN);
GPIO_setQualificationMode(BUTTON_GPIO, GPIO_QUAL_SYNC);
while(1)
{
// Read current button state (0 = pressed, 1 = released)
bool buttonState = GPIO_readPin(BUTTON_GPIO);
// If jumper connected (LOW), turn LED off
if(buttonState == 0)
{
GPIO_writePin(LED_GPIO, 1);
}
else // Jumper not connected (HIGH)
{
DEVICE_DELAY_US(5000);
GPIO_writePin(LED_GPIO, 0);
}
DEVICE_DELAY_US(5000);
}
}