lpcware

Help with GPIO for new user

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by cthvx8@hotmail.com on Fri Feb 27 10:58:05 MST 2015
I am just starting out with microcontrollers and I need some help to get me going.  I attempted to write some basic code to turn on and off some LEDs which I connected to pins 0-7 on Port0.  I wanted to alternate them between 10101010 and 01010101 with a delay in between.  It doesn't seem to be working and I was hoping someone could have a look and tell me what I'm doing wrong.

#if defined (__USE_LPCOPEN)
#if defined(NO_BOARD_LIB)
#include "chip.h"
#else
#include "board.h"
#endif
#endif

#include <cr_section_macros.h>

// TODO: insert other include files here

// TODO: insert other definitions and declarations here

volatile uint32_t msTicks=0;

// Systick Handler which is called each ms
void SysTick_Handler(void)
{
    msTicks++;
}

// blocks for dlyTicks ms...
static void Delay(uint32_t dlyTicks)
{
    uint32_t curTicks;

    curTicks = msTicks;
    while ((msTicks - curTicks) < dlyTicks);
}
//------------------------------------------------------------------------------------
int main(void) {

#if defined (__USE_LPCOPEN)
#if !defined(NO_BOARD_LIB)
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();
    // Set up and initialize all required blocks and
    // functions related to the board hardware
    Board_Init();
    // Set the LED to the state of "On"
    Board_LED_Set(0, true);
#endif
#endif

    // TODO: insert code here

    //Initialize Port 0
Chip_GPIO_Init(LPC_GPIO_PORT);

//Set Port 0 pins 0-7 to output
Chip_GPIO_SetPortDIROutput(LPC_GPIO_PORT, 0, 0xFF);

Chip_GPIO_SetPortMask(LPC_GPIO_PORT, 0, 0xFF);

SysTick_Config(SystemCoreClock/1000);

while(1){

//Set Port 0 pins to 01010101
Chip_GPIO_SetMaskedPortValue(LPC_GPIO_PORT, 0, 0X55);
Board_LED_Set(0, true);

//Wait 1 second
Delay(1000);

//Set Port 0 pins to 10101010
Chip_GPIO_SetMaskedPortValue(LPC_GPIO_PORT, 0, 0XFF);

Board_LED_Set(0, false);
//Wait 1 second
Delay(1000);

}

    // Force the counter to be placed into memory
    volatile static int i = 0 ;
    // Enter an infinite loop, just incrementing a counter
    while(1) {
        i++ ;

    }
    return 0 ;
}

Outcomes