New port pin direction setting function written OK

Now I have written and tested ok a new set port pin direction function with gpio structure pointer as parameter.

void setPortPinDirection01(LPC_GPIO_TypeDef *gpio_struct_ptr, int pinNumber)

.END

// ****************************************************************************
// Program - Blinky
// Description - Blink LED
// Author - TL Fong
// Version - 0.42
// Date - 2013jul12hkt2144
// License - Free
// Hardware - Somy ARM Cortex M0 LPC1114/301 Learning Board 
// Software - Keil uVision 4.71.2.0 ARM CC
// Method - Incremental testing
// Hardware configuration notes
//   1. LED1 is connected to PIO1-8 
// ****************************************************************************

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

void setPortPinDirection(int portNumber, int pinNumber)
  {
   LPC_GPIO_TypeDef *gpio_struct_ptr;
   gpio_struct_ptr = LPC_GPIO1;

    switch( portNumber )
    {
    case 1:

 // The following 4 statements do the same thing.
      // LPC_GPIO1->DIR |= (1 << pinNumber);    
      // (*LPC_GPIO1).DIR |= (1 << pinNumber);
      // (*gpio_struct_ptr).DIR |= (1 << pinNumber);
      // gpio_struct_ptr->DIR |= (1 << pinNumber);

 gpio_struct_ptr->DIR |= (1 << pinNumber);

break;
    case 2:
LPC_GPIO2->DIR |= (1 << pinNumber);
 break;    
default:
 break;
 }
}

void setPortPinDirection01(LPC_GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
  {
  gpio_struct_ptr->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 blinkLed(int ledNumber, int onTime, int offTime, int blinkCount)
{
int count;

switch( ledNumber )
{
case 1:
setPortPinDirection(1, 8);
 
 for (count = 0; count < blinkCount; count--)
 {
 setPortPinValue(1, 8, 0);
        delayTenthSecond(onTime);    
   setPortPinValue(1, 8, 1);
        delayTenthSecond(offTime);
 }
      break;
    case 2:
      ;
 break;    
default:
 break;
}
}

int main()
  {
setPortPinDirection01(LPC_GPIO1, 8);
blinkLed(1, 5, 10, 20); // Led 1, off 0.5 sec, on 1 sec, blink 20 times

  }

// ****************************************************************************
// End of Program
// ****************************************************************************
.END

No comments:

Post a Comment