Fong 7 segment LED function build 2013aug2301 notes

// ***********************************************************************
// Program  - Fong Seven Segment LED
// Function - Display 7 segment LED
// Author   - TL Fong
// Build    - 2013.08.23.01
// Date     - 2013aug23hkt1750
// Hardware - LPC1114/102, LPC1114/301
// Software - GCC ARM 4.7, CoIDE 1.7.4,  CoLinkEx 1.1, Flash Magic v7.51
// ***********************************************************************

// ***********************************************************************
// Functions
// ***********************************************************************

void BlinkExp();
void UartPrintExp();
void FongBlink02();
void FongBlink03();
void FongSevenSegmentLed01();

// ***********************************************************************
// Main Function
// ***********************************************************************

int main()
{
 // BlinkExp();
 // FongBlink011();
 // UartPrintExp();
 // FongBlink02(); // Blink WHUT Board PIO1_8 LED
 // UartPrintExp();
 // FongBlink02();
 // FongBlink03();

 FongSevenSegmentLed01();

  return 0;
}




// ***********************************************************************
// Program  - Fong Seven Segment LED
// Function - Display 7 segment LED
// Author   - TL Fong
// Build    - 2013.08.23.02
// Date     - 2013aug23hkt1750
// Hardware - LPC1114/301, LPC1114/102,
// Software - GCC ARM 4.7, CoIDE 1.7.4,  CoLinkEx 1.1, Flash Magic v7.51
// ***********************************************************************

#include "lpc11xx_syscon.h"
#include "lpc11xx_gpio.h"
#include "lpc11xx_iocon.h"
#include "lpc11xx_uart.h"

// ***********************************************************************
// Function List
// ***********************************************************************

void systemInitialization();
void delayTenthSecond(int count);
void setPio05Direction(int direction);
void setPio05OutputHigh();
void setPio05OutputLow();
void setPio18Output(int logicLevel);
void setPio18Direction(int direction);
void setPio18OutputHigh();
void setPio18OutputLow();
void setPio18Output(int logicLevel);
void setPio09Direction(int direction);
void setPio09OutputHigh();
void setPio09OutputLow();
void setPio09Output(int logicLevel);

// ***********************************************************************
// Preprocessor definitions
// ***********************************************************************

// ***Logic voltage level, IO direction ***

#define LOW 0
#define HIGH 1

#define LOW_LEVEL 0
#define HIGH_LEVEL 1

#define LOGIC_LOW_LEVEL 0
#define LOGIC_HIGH_LEVEL 1

#define INPUT_DIRECTION 0
#define OUTPUT_DIRECTION 1

// *** GPIO port number, pin number, port/pin number ***

#define PORT0 0
#define PORT1 1
#define PORT2 2
#define PORT3 3

#define PIN0 0
#define PIN1 1
#define PIN2 2
#define PIN3 3
#define PIN4 4
#define PIN5 5
#define PIN6 6
#define PIN7 7
#define PIN8 8
#define PIN9 9
#define PIN10 10
#define PIN11 11

typedef int portNumber;
portNumber Port0 = 0;
portNumber Port1 = 1;
portNumber Port2 = 2;
portNumber Port3 = 3;

typedef 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 const int portPinNumber;

portPinNumber Pio05  = 5;
portPinNumber Pio08  = 8;
portPinNumber Pio09  = 9;

portPinNumber Rpio11 = 11;
portPinNumber Rpio12 = 12;
portPinNumber Pio19  = 19;
portPinNumber Rpio18 = 18;
portPinNumber Pio110  = 110;

// *** system timer number, match register number ***

typedef const int timerNumber;
timerNumber Ct16b0 = 0;
timerNumber Ct16b1 = 1;
timerNumber Ct32b0 = 2;
timerNumber Ct32b1 = 3;

typedef const int matchRegisterNumber;
matchRegisterNumber MatchRegister0 = 0;
matchRegisterNumber MatchRegister1 = 1;
matchRegisterNumber MatchRegister2 = 2;

typedef const int deviceNumber;

#define LED1 1
#define LED2 2
#define LED3 3
#define LED4 4
#define LED5 5

#define MAX_DEVICE_NUMBER 2
#define MAX_LED_NUMBER    5
#define MAX_KEY_NUMBER    2
#define MAX_PWM_NUMBER    2

deviceNumber Device1 = 1;
deviceNumber Device2 = 2;
deviceNumber Device3 = 3;
deviceNumber Device4 = 4;
deviceNumber Device5 = 5;
deviceNumber Device6 = 6;

deviceNumber Led1 = 1;
deviceNumber Led2 = 2;
deviceNumber Led3 = 3;
deviceNumber Led4 = 4;
deviceNumber Led5 = 5;

deviceNumber Key1 = 1;
deviceNumber Key2 = 2;
deviceNumber Key3 = 3;
deviceNumber Key4 = 4;
deviceNumber Key5 = 5;

deviceNumber Pwm1 = 1;
deviceNumber Pwm2 = 2;
deviceNumber Pwm3 = 3;
deviceNumber Pwm4 = 4;
deviceNumber Pwm5 = 5;

// *** Port pin array typedef and declaration ***

// ***********************************************************************
// typedef portPinArray[]
// Description - this array denotes a GPIO port pin.  It has two elements,
//   portNumber and pinNumber
// **********************************************************************

typedef int portPinArray[2];

typedef int portPinArrayIndex;
portPinArrayIndex PortIndex = 0;
portPinArrayIndex PinIndex  = 1;

// ***********************************************************************
// WHUT LP!1114 Evaluation Board configuration
// ***********************************************************************

const int MaxBoardDeviceNumber =  5;
const int MaxBoardLedNumber = 5;
const int MaxBoardKeyNumber = 3;
const int MaxBoardPwmNumber = 5;

portPinArray WhutBoardLedPortPinArray1 = {PORT1, PIN8};  // LED D1
portPinArray WhutBoardLedPortPinArray2 = {PORT1, PIN9};  // LED D2
portPinArray WhutBoardLedPortPinArray3 = {PORT1, PIN10}; // LED D3
portPinArray WhutBoardLedPortPinArray4 = {PORT1, PIN11}; // LED D4
portPinArray WhutBoardLedPortPinArray5 = {PORT0, PIN9};  // JTAG pin13

#define SCLK_INDEX 0
#define DIN_INDEX 1
#define LATCH_INDEX 2

portPinArray WhutBoardSevenSegmentLedPinArray1 = {PORT2, PIN1}; // Serial Clock
portPinArray WhutBoardSevenSegmentLedPinArray2 = {PORT2, PIN3}; // Data in
portPinArray WhutBoardSevenSegmentLedPinArray3 = {PORT2, PIN0}; // Latch


// ***********************************************************************
// Ding LPC1114 bare bone configuration
// ************************************************************************

/*
portPinArray DingBoardPortPinArray1 = {Port0, Pin5};
portPinArray DingBoardLedPortPinArray2 = {Port0, Pin6};
portPinArray DingBoardLedPortPinArray3 = {Port0, Pin3};
portPinArray DingBoardLedPortPinArray4 = {Port0, Pin4};
portPinArray DingBoardLedPortPinArray5 = {Port0, Pin7};

portPinArray DingBoardKeyPortPinArray1 = {Port1, Pin0};
portPinArray DingBoardKeyPortPinArray2 = {Port1, Pin5};
portPinArray DingBoardKeyPortPinArray3 = {Port1, Pin8};

portPinArray DingBoardPwmPortPinArray1 = {Port0, Pin8};
portPinArray DingBoardPwmPortPinArray2 = {Port0, Pin9};
portPinArray DingBoardPwmPortPinArray3 = {Port1, Pin1};
portPinArray DingBoardPwmPortPinArray4 = {Port1, Pin2};
portPinArray DingBoardPwmPortPinArray5 = {Port1, Pin9};
portPinArray DingBoardPwmPortPinArray6 = {Port1, Pin10};
*/

// ***********************************************************************
// typedef portPinArrayPointerArray
// Description - Array pointers to pin array
// **********************************************************************

typedef portPinArray *portPinArrayPointerArray[MAX_DEVICE_NUMBER];

#define WHUT_MAX_LED_PIN_NUMBER 5

portPinArrayPointerArray WhutBoardLedPortPinArrayPointerArray[WHUT_MAX_LED_PIN_NUMBER] = \
{&WhutBoardLedPortPinArray1, &WhutBoardLedPortPinArray2, \
&WhutBoardLedPortPinArray3, &WhutBoardLedPortPinArray4, \
&WhutBoardLedPortPinArray5};

#define WHUT_MAX_7_SEG_LED_PIN_NUMBER 3

portPinArrayPointerArray WhutBoardSevenSegmentLedPortPinArrayPointerArray[WHUT_MAX_7_SEG_LED_PIN_NUMBER] = \
{&WhutBoardLedPortPinArray1, &WhutBoardLedPortPinArray2, \
&WhutBoardLedPortPinArray3};

/* *** Key and PWM to be tested later ***

portPinArrayPointerArray DingBoardKeyList1[MaxFongBoardKeyNumber] =
{
&DingBoardKeyPortPinArray1, &DingBoardKeyPortPinArray2, &FongKeyPortPinArray3
};

portPinArrayPointerArray FongPwmList1[MaxFongBoardPwmNumber] =
{
&DingBoardPwmPortPinArray1,
&DingBoardPwmPortPinArray2,
&DingBoardPwmPortPinArray3,
&DingBoardPwmPortPinArray4,
&DingBoardPwmPortPinArray5,
&DingBoardPwmPortPinArray6
};
*/

// ***********************************************************************
// typedef mcuBoardStruct (To test later)
// Description - MCU Board struct with LEDs, Keys, and PWMs
// **********************************************************************

typedef struct
{
portPinArrayPointerArray *LedPortPinArrayPointerArray;
portPinArrayPointerArray *KeyPortPinArrayPointerArray;
portPinArrayPointerArray *PwmPortPinArrayPointerArray;
} mcuBoardStruct;


mcuBoardStruct *CreateDingBoardBoardStruct() // To be tested
{
mcuBoardStruct *FongBoardStruct;

// DingBoardStruct->LedPortPinArrayPointerArray = FongBoardLedList1;
// DingBoardStruct->KeyPortPinArrayPointerArray = FongBoardKeyList1;
// DingBoardStruct->PwmPortPinArrayPointerArray = FongBoardPwmList1;

return FongBoardStruct;
}

// ***********************************************************************
// ***********************************************************************
// ***********************************************************************
// ***********************************************************************
// Main functions
// ***********************************************************************
// ***********************************************************************
// ***********************************************************************
// ***********************************************************************

void FongBlink02() // Blink One LED (PIO0_5, PIO1_8, or PIO0_9)
{
systemInitialization();
// setPio05Direction(OUTPUT_DIRECTION);
// setPio18Direction(OUTPUT_DIRECTION);
setPio09Direction(OUTPUT_DIRECTION);

while(1)
{
//setPio05Output(LOW_LEVEL);
// setPio18Output(LOW_LEVEL);
setPio09Output(LOW_LEVEL);

delayTenthSecond(2);

// setPio05Output(HIGH_LEVEL);
// setPio18Output(HIGH_LEVEL);
setPio09Output(HIGH_LEVEL);

delayTenthSecond(10);
}
}

void FongBlink03()
{
systemInitialization();

testBlinkAllLeds();
}

void FongSevenSegmentLed01()
{
systemInitialization();

testSevenSegmentLed();
}

// ***********************************************************************
// ***********************************************************************
// ***********************************************************************
// ***********************************************************************
// End of main functions
// ***********************************************************************
// ***********************************************************************
// ***********************************************************************
// ***********************************************************************

// ***********************************************************************
// Delay functions
// ***********************************************************************
// ***********************************************************************
// Name   - delayTenthSecond()
// Input  - tenth second count
// Output - none
// ***********************************************************************

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++)
        {
        }
    }
}
}

#define ONE_FIFTH_SECOND 2
#define ONE_HALF_SECOND 5
#define ONE_SECOND 10

#define ON_ONE_FIFTH_SECOND 2
#define OFF_ONE_FIFTH_SECOND 2
#define ON_ONE_HALF_SECOND 5
#define OFF_ONE_HALF_SECOND 5
#define ON_ONE_SECOND 10
#define OFF_ONE_SECOND 10

// *** Loop constants ***

#define REPEAT_1_TIME 1
#define REPEAT_2_TIMES 2
#define REPEAT_3_TIMES 3
#define REPEAT_4_TIMES 4
#define REPEAT_5_TIMES 5
#define REPEAT_6_TIMES 6
#define REPEAT_8_TIMES 8
#define REPEAT_10_TIMES 10
#define REPEAT_20_TIMES 20

typedef int repeatCount;
repeatCount OneTime     =  1;
repeatCount TwoTimes    =  2;
repeatCount ThreeTimes  =  3;
repeatCount FourTimes   =  4;
repeatCount FiveTimes   =  5;
repeatCount SixTimes    =  6;
repeatCount EightTimes  =  8;
repeatCount TenTimes    = 10;
repeatCount TwentyTimes = 20;

// ***********************************************************************
// System initialization functions
// ***********************************************************************

void systemInitialization() // CooCox code
{
/* Enable GPIO block clock */
SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_GPIO, ENABLE);
}

// ***********************************************************************
// GPIO functions
// ***********************************************************************

// * typedefs of logic level and IO direction *

#define PORT_INDEX 0
#define PIN_INDEX 1

typedef int logicLevelValue;

logicLevelValue LogicLevelLow = 0;
logicLevelValue LogicLevelHigh = 1;

typedef int directionValue;

directionValue InputDirection = 0;
directionValue OutputDirection = 1;


// ***********************************************************************
// typedef GPIO_TypeDef *gpioStructPointerArray[4];
// Description - CMSIS declares 4 struct pointers LPC_GPIO0, LPC_GPIO1,
// LPC_GPIO2, LPC_GPIO3 for the 4 structs each of which controls
// one port of up to 11 pins.
// ***********************************************************************

typedef GPIO_TypeDef *gpioStructPointerArray[4];
gpioStructPointerArray CmsisGpioStructPointerArray = {LPC_GPIO0, LPC_GPIO1, LPC_GPIO2, LPC_GPIO3};

// ***********************************************************************
// Name   - getGpioStructPointer()
// Input  - port number
// Output - pointer to the struct of the port
// ***********************************************************************

GPIO_TypeDef *getGpioStructPointer(int portNumber)
{
GPIO_TypeDef *gpioStructPointer;
gpioStructPointer =  CmsisGpioStructPointerArray[portNumber];
return gpioStructPointer;
}

// ***********************************************************************
// typedef gpioPortStructPinStruct;
// Description - this struct has 2 members: *GpioStructPointer and pin
//   pin number. This struct is not yet being used.
//
// 1 port of up to 11 pins.
// ***********************************************************************

typedef struct
{
GPIO_TypeDef *GpioStructPointer;
int PinNumber;
} gpioPortStructPinStruct;

// ***********************************************************************
// Name   - getGpioPortStructPinStructPointer() // To be tested
// Input  - port number, pin number
// Output - pointer to gpioPortStructPinStruct
// ***********************************************************************

gpioPortStructPinStruct *getGpioPortStructPinStructPointer(portNumber portNumber, pinNumber pinNumber)
  {
gpioPortStructPinStruct *gpioPortStructPinStruct;
gpioPortStructPinStruct->GpioStructPointer = getGpioStructPointer(portNumber);
gpioPortStructPinStruct->PinNumber = pinNumber;
return gpioPortStructPinStruct;
  }

// ***********************************************************************
// GPIO functions
// ***********************************************************************

// ***********************************************************************
// Name   - setGpioDataPinInput()
// Input  - gpio_struct_ptr, pin number
// Output - none
// ***********************************************************************

void setGpioDataPinInput(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
gpio_struct_ptr->DIR  &= ~(1 << pinNumber);
}

// ***********************************************************************
// Name   - setGpioDataPinOutput
// Input  - port control structure, pin number
// Output - set pin as output
// ***********************************************************************

void setGpioDataPinOutput(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
gpio_struct_ptr->DIR |= (1 << pinNumber);
}

// ***********************************************************************
// Name   - setGpioDataPinLow
// Input  - port control structure, pin number
// Output - none
// ***********************************************************************

void setGpioDataPinLow(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
gpio_struct_ptr->DATA &= ~(1 << pinNumber);
}

// ***********************************************************************
// Name   - setGpioDataPinHigh
// Input  - port control structure, pin number
// Output - set pin as output
// ***********************************************************************

void setGpioDataPinHigh(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
gpio_struct_ptr->DATA |= (1 << pinNumber);
}

// ***********************************************************************
// Name   - setGpioDataPinDirection
// Input  - port control structure, pin number, direction value
// Output - set pin as input or output
// ***********************************************************************

void setGpioPinDirection(GPIO_TypeDef *gpio_struct_ptr, int pinNumber, directionValue directionValue)
{
if (directionValue == INPUT_DIRECTION)
setGpioDataPinInput(gpio_struct_ptr, pinNumber);
else
setGpioDataPinOutput(gpio_struct_ptr, pinNumber);
}

// ***********************************************************************
// Name   - setGpioDataRegister
// Input  - port control structure, pin number, data value
// Output - none
// ***********************************************************************

void setGpioDataPin(GPIO_TypeDef *gpio_struct_ptr, int pinNumber, logicLevelValue logicLevelValue)
{
if (logicLevelValue == LOGIC_LOW_LEVEL)
setGpioDataPinLow(gpio_struct_ptr, pinNumber);
else
setGpioDataPinHigh(gpio_struct_ptr, pinNumber);
}

// ***********************************************************************
// Function - getGpioDataPinValue
// Input    - GPIO structure pointer, pin number
// Output   - Gpio data pin value
// ***********************************************************************

logicLevelValue getGpioDataPinValue(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
logicLevelValue logicLevelValue;

int GpioDataPinMask = (1 << pinNumber);

if ((gpio_struct_ptr->DATA  &= GpioDataPinMask) == GpioDataPinMask)
logicLevelValue = HIGH;
else
logicLevelValue = LOW;

return logicLevelValue;
}

// ***********************************************************************
// Name   - get port number of portPinArray
// Input  - port pin array
// Output - portNumber
// ***********************************************************************

portNumber getPortNumber(portPinArray portPinArray)
{
int portNumber;
portNumber = portPinArray[PORT_INDEX];
return portNumber;
}

// ***********************************************************************
// Name   - get port number from portPinArrayPointerArray
// Input  - portPinPointerArray, deviceNumber
// Output - portNumber
// ***********************************************************************

portNumber getPortNumber01(portPinArrayPointerArray portPinArrayPointerArray, deviceNumber deviceNumber)
{
int portNumber;
portNumber = getPortNumber(*portPinArrayPointerArray[deviceNumber - 1]);
return portNumber;
}

// ***********************************************************************
// Name   - get pin number of portPinArray
// Input  - port pin array
// Output - pinNumber
// ***********************************************************************

pinNumber getPinNumber(portPinArray portPinArray)
{
int pinNumber;
pinNumber = portPinArray[PIN_INDEX];
return pinNumber;
}

// ***********************************************************************
// Name   - get pin number from portPinArrayPointerArray and index
// Input  - portPinPointerArray, index
// Output - pinNumber
// ***********************************************************************

pinNumber getPinNumber01(portPinArrayPointerArray portPinArrayPointerArray, deviceNumber deviceNumber)
{
int pinNumber;
pinNumber = getPinNumber(*portPinArrayPointerArray[deviceNumber - 1]);
return pinNumber;
}

// ***********************************************************************
// LED Functions
// ***********************************************************************

// ***********************************************************************
// Name   - initialize LED port pin
// Input  - portPinPointerArray, index
// Output - none
// ***********************************************************************

void initializeLedPin(portPinArrayPointerArray portPinArrayPointerArray, deviceNumber ledNumber)
{
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;

portNumber = getPortNumber01(portPinArrayPointerArray, ledNumber);
pinNumber = getPinNumber01(portPinArrayPointerArray, ledNumber);
gpioStructPointer = getGpioStructPointer(portNumber);

// *** the 3 lines below are not working, don't know why - tlfong01 2013aug17 ***
// gpioPortStructPinStruct *gpioPortStructPinStructPointer;
// gpioPortStructPinStructPointer = getGpioPortStructPinStructPointer(portNumber, pinNumber);
// gpioStructPointer = gpioPortStructPinStructPointer -> GpioStructPointer;

setGpioDataPinOutput(gpioStructPointer, pinNumber);
setGpioDataPinLow (gpioStructPointer, pinNumber);
  }

// ***********************************************************************
// Function - initialize all LED port pins
// Input    - ledPortPinArrayPointerArray
// Output   - none
// ***********************************************************************

void initializeAllLedPins(portPinArrayPointerArray ledPortPinArrayPointerArray, int maxLedNumber)
{
  int ledNumber;

  for (ledNumber = 1; ledNumber < (maxLedNumber + 1); ledNumber++) // Caution!!! ledNumber starts 1, not 0 !!!
  {
   initializeLedPin(ledPortPinArrayPointerArray, ledNumber);
  }
}

// ***********************************************************************
// Blink LED functions
// ***********************************************************************

// ***********************************************************************
// Function - Blink 1 LED
// Input    - PortPinArrayPointerArray, device number, on time, off time,
//            blink repetition times
// Output   - none
// ***********************************************************************

void blinkOneLed(portPinArrayPointerArray portPinArrayPointerArray, \
deviceNumber ledNumber, int onTime, int offTime, int blinkCount)
{
int count = 0;
int portNumber = 0;
int pinNumber = 0;
GPIO_TypeDef *gpio_struct_ptr;
portPinArray *portPinArrayPointer;

portPinArrayPointer = portPinArrayPointerArray[ledNumber - 1];

  portNumber = getPortNumber(*portPinArrayPointer);
  pinNumber = getPinNumber(*portPinArrayPointer);
  gpio_struct_ptr = getGpioStructPointer(portNumber);

  // delayMilliSecond(100);
  delayTenthSecond(10);

  for (count = 0; count < blinkCount; count++)
  {
  setGpioDataPinHigh(gpio_struct_ptr, pinNumber);
  // delayMilliSecond(onTime);
  delayTenthSecond(onTime);
  setGpioDataPinLow(gpio_struct_ptr, pinNumber);
  // delayMilliSecond(offTime);
  delayTenthSecond(offTime);
  }
}

// ***********************************************************************
// Function - Test Blink 1 LED
// Input    - PortPinArrayPointerArray, device number, on time, off time,
//            blink repetition times
// Output   - none
// ***********************************************************************

void testBlinkOneLed()
{
initializeAllLedPins(WhutBoardLedPortPinArrayPointerArray, MAX_LED_NUMBER);
blinkOneLed(WhutBoardLedPortPinArrayPointerArray, LED1, \
ON_ONE_FIFTH_SECOND, OFF_ONE_HALF_SECOND, REPEAT_4_TIMES);
blinkOneLed(WhutBoardLedPortPinArrayPointerArray, LED2, \
ON_ONE_FIFTH_SECOND, OFF_ONE_FIFTH_SECOND, REPEAT_8_TIMES);
}

void testBlinkAllLeds()
{
int ledNumber;

initializeAllLedPins(WhutBoardLedPortPinArrayPointerArray, MAX_LED_NUMBER);

    for (ledNumber = 1; ledNumber < (MAX_LED_NUMBER + 1); ledNumber++ )
    {
    blinkOneLed(WhutBoardLedPortPinArrayPointerArray, ledNumber, \
ON_ONE_FIFTH_SECOND, OFF_ONE_FIFTH_SECOND, REPEAT_4_TIMES);
    }
}


// ***********************************************************************
// 7 Segment LED Functions
// ***********************************************************************

// ***********************************************************************
// Name   - initialize 7 segment LED port pin
// ***********************************************************************

// WHUT LPC1114 EvaluationBoard 7 segment LED configuration
// HC595 serial in, 8 bit parallel tristate out shift register with latch
// HC573 Input
// SCLK = P2.1/SCK1
// DIN  = P2.3/MOSI
// LATCH = P2.0/SSEL1
// SQH = P2.2/MISO (not used)
// HC573 Output
// QA to QH = segment A to G - DP

// ***********************************************************************
// Function - initialize all 7 segment LED pins
// Input    - ledPortPinArrayPointerArray
// Output   - none
// ***********************************************************************

void initializeAllSevenSegmentLedPins(portPinArrayPointerArray ledPortPinArrayPointerArray, int maxLedNumber)
{
  int ledNumber;

  for (ledNumber = 1; ledNumber < (maxLedNumber + 1); ledNumber++) // Caution!!! ledNumber starts 1, not 0 !!!
  {
   initializeLedPin(ledPortPinArrayPointerArray, ledNumber);
  }
}

// ***********************************************************************
// Function - setAllSevenSegmentsOn()
// Input    -
// Output   -
// ***********************************************************************

void testSevenSegmentLed01()
{
int segmentPattern[] = {0b11000000, 0b11111001, 0b10100100, 0b10110000, 0b10011001,\
0b10010010,0b10000011,0b11111000,0b10000000,0b10011000 };

int digit = 0;

for (digit = 0; digit < 10; digit++)
  {
// Disable parallel register latch
setGpioDataPinLow(WhutBoardSevenSegmentLedPortPinArrayPointerArray, LATCH_INDEX);

// shift out the bits:
// shiftOut(dataPin, clockPin, MSBFIRST, dec_digits[digit]);*** To be written!!! ***

//Enable parallel register latch
setGpioDataPinHigh(WhutBoardSevenSegmentLedPortPinArrayPointerArray, LATCH_INDEX);

        // pause half second each digit
delayTenthSecond(ONE_HALF_SECOND);
  }
}

void testSevenSegmentLed()
{
initializeAllSevenSegmentLedPins(WhutBoardSevenSegmentLedPortPinArrayPointerArray, WHUT_MAX_7_SEG_LED_PIN_NUMBER);
testSevenSegmentLed01();
}

// ***********************************************************************
// ***********************************************************************
// ***********************************************************************
// ***********************************************************************
// ***********************************************************************

/*
void testBlinkxx(portPinArrayPointerArray portPinArrayPointerArray, int maxLedNumber, int onTime, int offTime, int blinkCount)
{
int i;
initializeAllLedPortPin06(portPinArrayPointerArray, maxLedNumber);

for (i = 1; i < maxLedNumber + 1; i++)
{
blinkLed06(portPinArrayPointerArray, i, onTime, offTime, blinkCount);
}
}

void blinkFongLedList1()
{
  testBlinkLed06(*FongBoardLedList1, 5, 100, 200, 2);
}

void blink5Leds()
{
blinkFongLedList1();
}

// ***********************************************************************
// Blink Leds using FongBoardStruct - not working !!!
// ***********************************************************************

void testBlinkLed063() // using mcuBoardStruct, not working !!!
{
  portPinArrayPointerArray *fongLedPortPinArrayPointerArray;

  mcuBoardStruct *FongBoardStruct;
  FongBoardStruct->LedPortPinArrayPointerArray = FongLedList1;
  FongBoardStruct->KeyPortPinArrayPointerArray = FongKeyList1;
  FongBoardStruct->PwmPortPinArrayPointerArray = FongPwmList1;

  fongLedPortPinArrayPointerArray = FongBoardStruct->LedPortPinArrayPointerArray;

  testBlinkLed06(*fongLedPortPinArrayPointerArray, 4, 100, 200, 3);
}
*/

// ***********************************************************************
// Function - setupUART()
// Input    - none
// Output   - none
// ***********************************************************************

void sendUart(char *sendString) // CooCox code
{

UART_CFG_Type cfg;
UART_FIFO_CFG_Type UARTFIFOConfigStruct;

/* Assign UART Pins */
UART_PinsInit();

cfg.Baud_rate = 115200;
cfg.Parity = UART_PARITY_NONE;
cfg.Databits = UART_DATABIT_8;
cfg.Stopbits = UART_STOPBIT_1;
UART_FIFOConfigStructInit(&UARTFIFOConfigStruct);

UART_Init(LPC_UART, &cfg);
UART_FIFOConfig(LPC_UART, &UARTFIFOConfigStruct);

/* Enable Transmit */
UART_TxCmd(LPC_UART,ENABLE);

// UART_Send(LPC_UART, (uint8_t *)"BlinkLed 07 ", \
// sizeof("BlinkLed 07 ") - 1, NONE_BLOCKING);

UART_Send(LPC_UART, sendString, \
12, NONE_BLOCKING);
}

void testSendUart()
{
sendUart("0123456789\n");
}


// ***********************************************************************
// BlinkLed02 functions
// ***********************************************************************

// *** PIO0_5 ***

void setPio05Direction(int direction)
{
/* Set pin to GPIO */
IOCON_SetPinFunc(IOCON_PIO0_5, PIO0_5_FUN_PIO);

/* Set pin direction */
if (direction == OUTPUT_DIRECTION)
GPIO_SetDir(PORT0, GPIO_Pin_5, 1);
else
GPIO_SetDir(PORT0, GPIO_Pin_5, 0);
}

void setPio05OutputHigh()
{
GPIO_SetBits(PORT0, GPIO_Pin_5);
}

void setPio05OutputLow()
{
GPIO_ResetBits(PORT0, GPIO_Pin_5);
}

void setPio05Output(int logicLevel)
{
if (logicLevel == HIGH_LEVEL)
GPIO_SetBits(PORT0, GPIO_Pin_5);
else
GPIO_ResetBits(PORT0, GPIO_Pin_5);
}

// *** PIO1_8 ***

void setPio18Direction(int direction)
{
/* Set pin to GPIO */
IOCON_SetPinFunc(IOCON_PIO1_8, PIO1_8_FUN_PIO);

/* Set pin direction */
if (direction == OUTPUT_DIRECTION)
GPIO_SetDir(PORT1, GPIO_Pin_8, 1);
else
GPIO_SetDir(PORT1, GPIO_Pin_8, 0);
}

void setPio18OutputHigh()
{
GPIO_SetBits(PORT1, GPIO_Pin_8);
}

void setPio18OutputLow()
{
GPIO_ResetBits(PORT1, GPIO_Pin_8);
}

void setPio18Output(int logicLevel)
{
if (logicLevel == HIGH_LEVEL)
GPIO_SetBits(PORT1, GPIO_Pin_8);
else
GPIO_ResetBits(PORT1, GPIO_Pin_8);
}

// *** PIO9_9 ***

void setPio09Direction(int direction)
{
/* Set pin to GPIO */
IOCON_SetPinFunc(IOCON_PIO0_9, PIO0_9_FUN_PIO);

/* Set pin direction */
if (direction == OUTPUT_DIRECTION)
GPIO_SetDir(PORT0, GPIO_Pin_9, 1);
else
GPIO_SetDir(PORT0, GPIO_Pin_9, 0);
}

void setPio09OutputHigh()
{
GPIO_SetBits(PORT0, GPIO_Pin_9);
}

void setPio09OutputLow()
{
GPIO_ResetBits(PORT0, GPIO_Pin_9);
}

void setPio09Output(int logicLevel)
{
if (logicLevel == HIGH_LEVEL)
GPIO_SetBits(PORT0, GPIO_Pin_9);
else
GPIO_ResetBits(PORT0, GPIO_Pin_9);
}

// ***********************************************************************
// End
// ***********************************************************************

No comments:

Post a Comment