2013-10-11

7 segment LED function - refreshing memory notes

// ***********************************************************************
// config031.h - 2013oct11hkt1535
// ***********************************************************************

...

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

// *** Seven segment LED data and control signals ***

portPinArray WhutBoardSevenSegmentLedPortPinArraySclk = {PORT2, PIN1}; // Serial Clock
portPinArray WhutBoardSevenSegmentLedPortPinArrayDin = {PORT2, PIN3}; // Data in
portPinArray WhutBoardSevenSegmentLedPortPinArrayLatch = {PORT2, PIN0}; // Latch

// *** 7 Segment LED configuration ***

#define MAX_7_SEG_LED_PIN_NUMBER 3

portPinArrayPointerArray WhutBoardSevenSegmentLedPortPinArrayPointerArray[MAX_7_SEG_LED_PIN_NUMBER] = \
  {&WhutBoardSevenSegmentLedPortPinArraySclk, &WhutBoardSevenSegmentLedPortPinArrayDin, \
       &WhutBoardSevenSegmentLedPortPinArrayLatch};


// ***********************************************************************
// Display 7 segment LED of WHUT Evaluation Board
// 2013sep23hkt0950
// ***********************************************************************

// positive going pulse to latch segment data

void sendGoingPositivePulse(portPinArray *portPinArrayPointer)
{
setGpioDataPinHigh01(portPinArrayPointer);
setGpioDataPinLow01(portPinArrayPointer);
}

// load 7 segment bits and decimal point

void loadSevenSegmentDataBits(portPinArray *portPinArrayPointerData, \
portPinArray *portPinArrayPointerClock, int alphaNumbericCharacter)
{
int segmentNumber;
int segmentBit;
int segmentByte, segmentByte1;

int Segment0 = 0b11111100; // 7 sements bits & decimal point pattern of digit 0
int Segment1 = 0b01100000;
int Segment2 = 0b11011010;
int Segment3 = 0b11110010;
int Segment4 = 0b01100110;
int Segment5 = 0b10110110;
int Segment6 = 0b10111110;
int Segment7 = 0b11100000;
int Segment8 = 0b11111110;
int Segment9 = 0b11110110; // digit 9

int AllBlank = 0b00000000; // all 7 segments and decimal pont blank

int SegmentArray[] = {Segment0, Segment1, Segment2, Segment3, Segment4, \
Segment5, Segment6, Segment7, Segment8, Segment9, AllBlank};

segmentByte = SegmentArray[alphaNumbericCharacter];

    for (segmentNumber = 0; segmentNumber < 8; segmentNumber++) // load 8 segment bits
    {
    segmentByte1 = segmentByte | (1 << segmentNumber);
    if (segmentByte1 == segmentByte)
    setGpioDataPinHigh01(portPinArrayPointerData);
    else
    setGpioDataPinLow01(portPinArrayPointerData);

        sendGoingPositivePulse(portPinArrayPointerClock); // then write positive going pulse to latch data
    }
}

void displayDigitBlank() // display blank digit
{
int DigitBlank = 10;
displayDigit(DigitBlank);
}

void displayDigit01(portPinArrayPointerArray sevenSegmentPortPinArrayPointerArray, \
  int digitNumber) // display 1 digit
{
portPinArray *portPinArrayPointerClock; // GPIO pin for clock
portPinArray *portPinArrayPointerData;  // GPIO pin for data
portPinArray *portPinArrayPointerLatch; // GPIO pin for latch

portPinArrayPointerClock = sevenSegmentPortPinArrayPointerArray[SCLK_INDEX];
portPinArrayPointerData  = sevenSegmentPortPinArrayPointerArray[DIN_INDEX];
portPinArrayPointerLatch = sevenSegmentPortPinArrayPointerArray[LATCH_INDEX];

setGpioDataPinLow01(portPinArrayPointerLatch); // set latch low
setGpioDataPinLow01(portPinArrayPointerClock); // set clock pin low
loadSevenSegmentDataBits(portPinArrayPointerData, portPinArrayPointerClock, digitNumber); // load segment bits
setGpioDataPinHigh01(portPinArrayPointerLatch); // set latch pin high
}

void displayDigit(int digitNumber) // display 1 digit
{
displayDigit01(WhutBoardSevenSegmentLedPortPinArrayPointerArray, digitNumber);
}

void displayAllDigits01() // display all digits
{
int digitNumber;

for (digitNumber = 0; digitNumber < 10; digitNumber++)
    {
displayDigit(digitNumber);
delayTime(ONE_HALF_SECOND);
    }
}

void displayAllDigits() // WHUT 7 Segment LED
{
initializeAllOutputPins(WhutBoardSevenSegmentLedPortPinArrayPointerArray, \
MAX_7_SEG_LED_PIN_NUMBER);

delayTime(TWO_SECONDS);

displayAllDigits01();
}

void blinkDigit(int digitNumber, int onTime, int offTime, int repeatCount) // blink 1 digit
{
int count;

for (count = 0; count < repeatCount; count++)
   {
displayDigitBlank();
delayTenthSecond(offTime);
displayDigit(digitNumber);
delayTenthSecond(onTime);
   }
}

void blinkAllDigits()
{
initializeAllOutputPins(WhutBoardSevenSegmentLedPortPinArrayPointerArray, \
MAX_7_SEG_LED_PIN_NUMBER);
delayTime(ONE_SECOND);

int digitNumber;

for (digitNumber = 0; digitNumber < 10; digitNumber++)
    {
blinkDigit(digitNumber, ON_ONE_FIFTH_SECOND, OFF_ONE_SECOND, REPEAT_2_TIMES);
    }

displayDigitBlank();
}



.END

No comments:

Post a Comment