// ***********************************************************************
// Program - Test LPC1114
// Function - Test LPC1114
// Author - TL Fong
// Build - 2013.08.26.01
// Date - 2013aug26hkt0912
// Hardware - LPC1114/102, LPC1114/301
// Software - GCC ARM 4.7, CoIDE 1.7.4, CoLinkEx 1.1, Flash Magic v7.51
// ***********************************************************************
#include "config031.h"
#include "test031.h"
// ***********************************************************************
// Functions
// ***********************************************************************
void testSingleAndSevenSegmentLed();
void testInitLedSystem();
void testBlinkOneLed();
void testDisplay7SegLed1Digit();
// ***********************************************************************
// Main Function
// ***********************************************************************
int main()
{
// testSingleAndSevenSegmentLed();
testInitLedSystem();
testBlinkOneLed(LED_3);
testDisplay7SegLed1Digit(DIGIT_4);
return 0;
}
// ***********************************************************************
// test031.h
// ***********************************************************************
#include "blink031.h"
#include "blink032.h"
#include "display7SegLed031.h"
void testSingleAndSevenSegmentLed()
{
blinkLedP18(ON_ONE_FIFTH_SECOND, OFF_ONE_FIFTH_SECOND, REPEAT_2_TIMES);
blinkLedP09(ON_ONE_FIFTH_SECOND, OFF_ONE_FIFTH_SECOND, REPEAT_2_TIMES);
blinkAllLeds(ON_ONE_FIFTH_SECOND, OFF_ONE_FIFTH_SECOND, REPEAT_2_TIMES);
displayAllDigits();
}
void testInitLedSystem()
{
initializeAllOutputPins(WhutBoardSevenSegmentLedPortPinArrayPointerArray, \
MAX_7_SEG_LED_PIN_NUMBER);
initializeAllOutputPins(WhutBoardLedPortPinArrayPointerArray, MAX_LED_NUMBER);
}
void testBlinkOneLed(int ledNumber)
{
blinkOneLed(WhutBoardLedPortPinArrayPointerArray, ledNumber, \
ON_ONE_FIFTH_SECOND, OFF_ONE_FIFTH_SECOND, REPEAT_2_TIMES );
}
void testDisplay7SegLed1Digit(int digitNumber)
{
displayOneDigit(WhutBoardSevenSegmentLedPortPinArrayPointerArray, digitNumber);
}
// ***********************************************************************
// End
// ***********************************************************************
// ***********************************************************************
// blink032.h
// ***********************************************************************
#include "config031.h"
#include "delay031.h"
#include "gpio032.h"
// ***********************************************************************
// Blink LED functions
// ***********************************************************************
void setGpioDataPinHigh01(portPinArray *portPinArrayPointer)
{
pinNumber pinNumber;
portNumber portNumber;
GPIO_TypeDef *gpioStructPointer;
pinNumber = getPinNumber(portPinArrayPointer);
portNumber = getPortNumber(portPinArrayPointer);
gpioStructPointer = getGpioStructPointer(portNumber);
setGpioDataPinHigh(gpioStructPointer, pinNumber);
}
void setGpioDataPinLow01(portPinArray *portPinArrayPointer)
{
pinNumber pinNumber;
portNumber portNumber;
GPIO_TypeDef *gpioStructPointer;
pinNumber = getPinNumber(portPinArrayPointer);
portNumber = getPortNumber(portPinArrayPointer);
gpioStructPointer = getGpioStructPointer(portNumber);
setGpioDataPinLow(gpioStructPointer, pinNumber);
}
// ***********************************************************************
// 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;
portPinArray *portPinArrayPointer;
portPinArrayPointer = portPinArrayPointerArray[ledNumber - 1];
for (count = 0; count < blinkCount; count++)
{
setGpioDataPinHigh01(portPinArrayPointer);
delayTenthSecond(onTime);
setGpioDataPinLow01(portPinArrayPointer);
delayTenthSecond(offTime);
}
}
// ***********************************************************************
// Function - Blink all LEDs
// Input - PortPinArrayPointerArray, device number, on time, off time,
// blink repetition times
// Output - none
// ***********************************************************************
void blinkAllLeds(int onTime, int offTime, int repeatCount)
{
int ledNumber;
initializeAllOutputPins(WhutBoardLedPortPinArrayPointerArray, MAX_LED_NUMBER);
for (ledNumber = 1; ledNumber < (MAX_LED_NUMBER + 1); ledNumber++ )
{
blinkOneLed(WhutBoardLedPortPinArrayPointerArray, ledNumber, \
onTime, offTime, repeatCount);
}
}
// ***********************************************************************
// End
// ***********************************************************************
// ***********************************************************************
// display7SegLed031.h
// ***********************************************************************
#include "config031.h"
#include "delay031.h"
#include "gpio032.h"
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 = 0b11011010;
int Segment3 = 0b11110010;
int Segment4 = 0b01100110;
int Segment5 = 0b10110110;
int Segment6 = 0b10111110;
int Segment7 = 0b11100000;
int Segment8 = 0b11111110;
int Segment9 = 0b11110110;
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)
{
portPinArray *portPinArrayPointerClock;
portPinArray *portPinArrayPointerData;
portPinArray *portPinArrayPointerLatch;
portPinArrayPointerClock = sevenSegmentPortPinArrayPointerArray[SCLK_INDEX];
portPinArrayPointerData = sevenSegmentPortPinArrayPointerArray[DIN_INDEX];
portPinArrayPointerLatch = sevenSegmentPortPinArrayPointerArray[LATCH_INDEX];
setGpioDataPinLow01(portPinArrayPointerLatch);
setGpioDataPinLow01(portPinArrayPointerClock);
loadSevenSegmentDataBits(portPinArrayPointerData, portPinArrayPointerClock, digitNumber);
setGpioDataPinHigh01(portPinArrayPointerLatch);
}
// ***********************************************************************
// Function - Display all digits
// ***********************************************************************
void displayAllDigits()
{
int digitNumber;
initializeAllOutputPins(WhutBoardSevenSegmentLedPortPinArrayPointerArray, \
MAX_7_SEG_LED_PIN_NUMBER);
for (digitNumber = 0; digitNumber < 10; digitNumber++)
{
displayOneDigit(WhutBoardSevenSegmentLedPortPinArrayPointerArray, digitNumber);
delayTime(ONE_SECOND);
}
}
// ***********************************************************************
// End
// ***********************************************************************
No comments:
Post a Comment