blinky 0.46

// ****************************************************************************
// Program - Blinky
// Description - Blink LED
// Author - TL Fong
// Version - 0.46
// Date - 2013jul13hkt1214
// 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 setPortPinValue03(int gpioNumber, int pinNumber, int pinValue)
{
  LPC_GPIO_TypeDef *gpioStructPointer;
  gpioStructPointer = getGpioStructPointer(gpioNumber);  
  if (pinValue == 1)
      gpioStructPointer->DATA &= ~(1 << pinNumber);        
  else
      gpioStructPointer->DATA |= (1 << pinNumber);  
}

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

for (count = 0; count < blinkCount; count--)
{
    setPortPinValue03(ledNumber, pinNumber, 0);
    delayTenthSecond(onTime);    
    setPortPinValue03(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