// ***********************************************************************
// display7SegLed031.h
// ***********************************************************************
#include "config031.h"
#include "delay031.h"
#include "gpio032.h"
// ***********************************************************************
// 7 segment LED functions
// ***********************************************************************
void sendGoingPositivePulse(portPinArray *portPinArrayPointer)
{
setGpioDataPinHigh01(portPinArrayPointer);
setGpioDataPinLow01(portPinArrayPointer);
}
void loadSevenSegmentDataBits(portPinArray *portPinArrayPointerData, \
portPinArray *portPinArrayPointerClock, int alphaNumbericCharacter)
{
int segmentNumber;
int segmentBit;
int segmentByte, segmentByte1;
int Segment0 = 0b11111100;
int Segment1 = 0b01100000;
int Segment2 = 0b11111111;
int Segment3 = 0b11111111;
int Segment4 = 0b11111111;
int Segment5 = 0b11111111;
int Segment6 = 0b11111111;
int Segment7 = 0b11111111;
int Segment8 = 0b11111111;
int Segment9 = 0b11111111;
int SegmentArray[] = {Segment0, Segment1, Segment2, Segment3, Segment4, \
Segment5, Segment6, Segment7, Segment8, Segment9};
segmentByte = SegmentArray[alphaNumbericCharacter];
for (segmentNumber = 0; segmentNumber < 8; segmentNumber++)
{
segmentByte1 = segmentByte | (1 << segmentNumber);
if (segmentByte1 == segmentByte)
setGpioDataPinHigh01(portPinArrayPointerData);
else
setGpioDataPinLow01(portPinArrayPointerData);
sendGoingPositivePulse(portPinArrayPointerClock);
}
}
void displayOneDigit(portPinArrayPointerArray sevenSegmentPortPinArrayPointerArray, \
int digitNumber, int onTime, int offTime, int blinkCount)
{
int count = 0;
portPinArray *portPinArrayPointerClock;
portPinArray *portPinArrayPointerData;
portPinArray *portPinArrayPointerLatch;
portPinArrayPointerClock = sevenSegmentPortPinArrayPointerArray[SCLK_INDEX];
portPinArrayPointerData = sevenSegmentPortPinArrayPointerArray[DIN_INDEX];
portPinArrayPointerLatch = sevenSegmentPortPinArrayPointerArray[LATCH_INDEX];
// setGpioDataPinHigh01(portPinArrayPointerClock); // debugging p1.8
// setGpioDataPinHigh01(portPinArrayPointerData); // debugging p1.9
// setGpioDataPinHigh01(portPinArrayPointerLatch); // debugging p1.10
// setGpioDataPinLow01(portPinArrayPointerClock); // debugging p1.8
// setGpioDataPinLow01(portPinArrayPointerData); // debugging p1.9
// setGpioDataPinLow01(portPinArrayPointerLatch); // debugging p1.10
// Latch low before shifting in 8 segment data bits
setGpioDataPinLow01(portPinArrayPointerLatch);
// Clock low before sending high clock pulse
setGpioDataPinLow01(portPinArrayPointerClock);
// Now shifting in 8 segment data signals, each followed by a clock pulse
loadSevenSegmentDataBits(portPinArrayPointerData, portPinArrayPointerClock, 1);
// Latch high to transfer 8 segment data bits to parallel register
setGpioDataPinHigh01(portPinArrayPointerLatch);
while (1);
}
// ***********************************************************************
// Function - Display all digits
// Input -
// Output -
// ***********************************************************************
// ***********************************************************************
// WhutBoardSevenSegmentLedPortPinArraySclk
// ***********************************************************************
// #define SCLK_INDEX 0
// #define DIN_INDEX 1
// #define LATCH_INDEX 2
// portPinArray WhutBoardSevenSegmentLedPortPinArraySclk = {PORT2, PIN1}; // Serial Clock
// portPinArray WhutBoardSevenSegmentLedPortPinArrayDin = {PORT2, PIN3}; // Data in
// portPinArray WhutBoardSevenSegmentLedPortPinArrayLatch = {PORT2, PIN0}; // Latch
// #define MAX_7_SEG_LED_PIN_NUMBER 3
// portPinArrayPointerArray \
WhutBoardSevenSegmentLedPortPinArrayPointerArray[MAX_7_SEG_LED_PIN_NUMBER] = \
{&WhutBoardSevenSegmentLedPortPinArraySclk, \
&WhutBoardSevenSegmentLedPortPinArrayDin, \
&WhutBoardSevenSegmentLedPortPinArrayLatch};
void displayAllDigits(int onTime, int offTime, int repeatCount)
{
int digitNumber;
initializeAllOutputPins(WhutBoardSevenSegmentLedPortPinArrayPointerArray, \
MAX_7_SEG_LED_PIN_NUMBER);
for (digitNumber = 0; digitNumber < 10; digitNumber++)
{
displayOneDigit(WhutBoardSevenSegmentLedPortPinArrayPointerArray, digitNumber, \
onTime, offTime, repeatCount);
}
}
// ***********************************************************************
// End
// ***********************************************************************
No comments:
Post a Comment