blinky 0.47

// ****************************************************************************
// Program - Blinky
// Description - Blink LED
// Author - TL Fong
// Version - 0.47
// Date - 2013jul13hkt1304
// Hardware - Somy ARM Cortex M0 LPC1114/301 Learning Board 
// Software - Keil uVision 4.71.2.0 ARM CC
// Somy Configuration -
//   LED1 - P1.8
// Function structure
//   main()
//     blinky()
//       setPortPinOutput()
//       setPortPinLow()
//       setPortPinHigh()
//       delayTenthSecond()
// ****************************************************************************

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

typedef const int logicLevel;
logicLevel LogicLevelLow = 0;
logicLevel LogicLevelHigh = 1;


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

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

void setPortPinInput(int gpioPortNumber, int pinNumber)
{
  LPC_GPIO_TypeDef *gpioStructPointer;
  gpioStructPointer = getGpioStructPointer(gpioPortNumber);
  gpioStructPointer->DIR &= ~(1 << pinNumber);
}

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

void setPortPinLow(int gpioPortNumber, int pinNumber)
{
  LPC_GPIO_TypeDef *gpioStructPointer;
  gpioStructPointer = getGpioStructPointer(gpioPortNumber);  
  gpioStructPointer->DATA &= ~(1 << pinNumber);    
}  

void setPortPinHigh(int gpioPortNumber, int pinNumber)
{
  LPC_GPIO_TypeDef *gpioStructPointer;
  gpioStructPointer = getGpioStructPointer(gpioPortNumber);  
  gpioStructPointer->DATA |= (1 << pinNumber);    
}
  
void blinky(int ledNumber, int pinNumber, int onTime, int offTime, int blinkCount)
{
  int count;
setPortPinOutput(ledNumber, pinNumber);
for (count = 0; count < blinkCount; count--)
{
    setPortPinHigh(ledNumber, pinNumber);
    delayTenthSecond(onTime);    
    setPortPinLow(ledNumber, pinNumber);
    delayTenthSecond(offTime);
  }  
}

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

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

No comments:

Post a Comment