Blinky 0.45

// ****************************************************************************
// Program - Blinky
// Description - Blink LED
// Author - TL Fong
// Version - 0.45
// Date - 2013jul13hkt1200
// Hardware - Somy ARM Cortex M0 LPC1114/301 Learning Board 
// Software - Keil uVision 4.71.2.0 ARM CC
// Somy Configuration -
//   LED1 - P1.8
// ****************************************************************************

#include <stdio.h>
#include "LPC11xx.h"
#include "timer.h"

LPC_GPIO_TypeDef *getGpioStructPointer(int gpioNumber)
{
  LPC_GPIO_TypeDef *gpioStructPointer;

  switch(gpioNumber)
    {
    case 0:
      gpioStructPointer = LPC_GPIO0;
break;
    case 1:
      gpioStructPointer = LPC_GPIO1;
break;    
default:
 break;
 }
return gpioStructPointer;
}

void setPortPinDirection03(int gpioNumber, int pinNumber)
  {
  LPC_GPIO_TypeDef *gpioStructPointer;
  gpioStructPointer = getGpioStructPointer(gpioNumber);
  gpioStructPointer->DIR |= (1 << pinNumber);
  }

void setPortPinValue(int portNumber, int pinNumber, int pinValue)
{
switch( portNumber )
{
case 1:
 if (pinValue == 1)
 LPC_GPIO1->DATA &= ~(1 << pinNumber);        
else
 LPC_GPIO1->DATA |= (1 << pinNumber);
break;
    case 2:
      ;
 break;    
default:
 break;
}
}

void blinky(int ledNumber, int pinNumber, int onTime, int offTime, int blinkCount)
{
  int count;
setPortPinDirection03(ledNumber, pinNumber);

for (count = 0; count < blinkCount; count--)
{
    setPortPinValue(ledNumber, pinNumber, 0);
    delayTenthSecond(onTime);    
    setPortPinValue(ledNumber, pinNumber, 1);
    delayTenthSecond(offTime);
  }  
}

int main()
  {
setPortPinDirection03(1, 8); // LED 1 = gpioStructure 1, pin 8
blinky(1, 8, 5, 10, 20); // LED off 0.5 sec, on 1 sec, 20 times
  }

// ****************************************************************************
// End of Program
// ****************************************************************************

No comments:

Post a Comment