Blinky() version 0.48 notes

Blinky() was good.  So I refactored it to Blink01().  The new version does not work.  So I went back to the old version.  But even the once working old version now is not working.  I must have made a careless mistake somewhere.

Anyway, I call it a day.

// ***********************************************************************
// Program - Blinky
// Description - Blink LED
// Author - TL Fong
// Version - 0.48
// Date - 2013jul13hkt2232
// 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 header files
// ***********************************************************************
#include <stdio.h>
#include "LPC11xx.h"
#include "timer.h"

// ***********************************************************************
// Global constants and variables
// ***********************************************************************

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

typedef const int portNumber;
portNumber Port0 = 0;
portNumber Port1 = 1;
portNumber Port2 = 2;
portNumber Port3 = 3;
portNumber Port4 = 4;
portNumber Port5 = 5;
portNumber Port6 = 6;
portNumber Port7 = 7;

typedef const int pinNumber;
pinNumber Pin0 = 0;
pinNumber Pin1 = 1;
pinNumber Pin2 = 2;
pinNumber Pin3 = 3;
pinNumber Pin4 = 4;
pinNumber Pin5 = 5;
pinNumber Pin6 = 6;
pinNumber Pin7 = 7;
pinNumber Pin8 = 8;
pinNumber Pin9 = 9;
pinNumber Pin10 = 10;
pinNumber Pin11 = 11;

typedef int ledNumber;
ledNumber Led0 = 0;
ledNumber Led1 = 1;

typedef int tenthSecond;
tenthSecond HalfSecond = 5;
tenthSecond OneSecond = 10;

typedef int repeatCount;
repeatCount FourTimes = 4;
repeatCount TwentyTimes = 20;

typedef int ledPortPinArrayArray[4][2];
ledPortPinArrayArray Lppaa = {{Port1, Pin8},{Port1, Pin8}, {Port1, Pin8}, {Port1, Pin8}};

// ***********************************************************************
// GPIO Functions
// ***********************************************************************

portNumber getLedPortNumber(ledNumber ledNumber, ledPortPinArrayArray lppaa)
{
  int portNumber;
  portNumber = lppaa [ledNumber][0];
  return portNumber;
}

pinNumber getLedPinNumber(ledNumber ledNumber, ledPortPinArrayArray lppaa)
{
  int ledPinNumber;
  ledPinNumber = lppaa [ledNumber][1];
  return ledPinNumber;
}

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);    
}

// ***********************************************************************
// Time Delay Functions
// ***********************************************************************
void delayTenthSecond(int count)
  {
int i, j, k;
for (i = 0; i < count; i++)
    {
for (j = 0; j < 0x4; j++)
 {
        for (k = 0; k < 0x000BB00; k++)
          {
       }
}
     }
}
  
// ***********************************************************************
// Blinky
// ***********************************************************************

void blinky(ledNumber 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);
  }  
}

// ***********************************************************************
// Blinky01
// ***********************************************************************

void blinky01(ledNumber ledNumber, int onTime, int offTime, int blinkCount)
{
  int count;
  int portNumber;
  int pinNumber;
  
  portNumber = getLedPortNumber(ledNumber, Lppaa);
  pinNumber = getLedPinNumber(ledNumber, Lppaa);
  
setPortPinOutput(portNumber, pinNumber);
  
for (count = 0; count < blinkCount; count--)
{
    setPortPinHigh(ledNumber, pinNumber);
    delayTenthSecond(onTime);    
    setPortPinLow(ledNumber, pinNumber);
    delayTenthSecond(offTime);
  }  
}

// ***********************************************************************
// Test Tunctions
// ***********************************************************************

void testBlinky()
{
  blinky(Port0, Pin8, HalfSecond, OneSecond, TwentyTimes); 
}  

void testBlinky01()
{
  blinky(Led0, Pin8, HalfSecond, OneSecond, FourTimes); 
}  

int main()
{
  testBlinky();
  //testBlinky01();
}

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

.END

No comments:

Post a Comment