// Program - Fong Blink02
// Function - Blink LED
// Author - TL Fong
// Build - 2013.08.21.01
// Date - 2013aug21hkt2055
// 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"
// ***********************************************************************
// Functions
// ***********************************************************************
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);
// ***********************************************************************
// Constants definition
// ***********************************************************************
#define HIGH_LEVEL 1
#define LOW_LEVEL 0
#define OUTPUT_DIRECTION 1
#define INPUT_DIRECTION 0
// *** 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;
// *** 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;
// *** LED, Key, PWM number ***
typedef const int deviceNumber;
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 int portPinArray[2];
typedef int portPinArrayIndex;
portPinArrayIndex PortIndex = 0;
portPinArrayIndex PinIndex = 1;
// *** Fong Board v2.0 configuration ***
#define MAX_BOARD_DEVICE_NUMBER 5
#define MAX_BOARD_LED_NUMBER 5
#define MAX_BOARD_KEY_NUMBER 5
#define MAX_BOARD_PWM_NUMBER 5
const int MaxBoardDeviceNumber = 5;
const int MaxFongBoardLedNumber = 5;
const int MaxFongBoardKeyNumber = 3;
const int MaxFongBoardPwmNumber = 5;
portPinArray FongBoardLedPortPinArray1 = {PORT1, PIN8};
portPinArray FongBoardLedPortPinArray2 = {PORT0, PIN9};
// *** Fong Board v1.0 configuration ***
/* portPinArray FongLedPortPinArray1 = {Port0, Pin5};
portPinArray FongLedPortPinArray2 = {Port0, Pin6};
portPinArray FongLedPortPinArray3 = {Port0, Pin3};
portPinArray FongLedPortPinArray4 = {Port0, Pin4};
portPinArray FongLedPortPinArray5 = {Port0, Pin7};
portPinArray FongKeyPortPinArray1 = {Port1, Pin0};
portPinArray FongKeyPortPinArray2 = {Port1, Pin5};
portPinArray FongKeyPortPinArray3 = {Port1, Pin8};
portPinArray FongPwmPortPinArray1 = {Port0, Pin8};
portPinArray FongPwmPortPinArray2 = {Port0, Pin9};
portPinArray FongPwmPortPinArray3 = {Port1, Pin1};
portPinArray FongPwmPortPinArray4 = {Port1, Pin2};
portPinArray FongPwmPortPinArray5 = {Port1, Pin9};
portPinArray FongPwmPortPinArray6 = {Port1, Pin10};
*/
// *** portPinArrayPointerArray - array of pointers to portPinArray ***
typedef portPinArray *portPinArrayPointerArray[MAX_BOARD_DEVICE_NUMBER];
portPinArrayPointerArray FongBoardLedList1[MAX_BOARD_LED_NUMBER] = {&FongBoardLedPortPinArray1, &FongBoardLedPortPinArray2};
/*
portPinArrayPointerArray FongKeyList1[MaxFongBoardKeyNumber] =
{
&FongKeyPortPinArray1, &FongKeyPortPinArray2, &FongKeyPortPinArray3
};
portPinArrayPointerArray FongPwmList1[MaxFongBoardPwmNumber] =
{
&FongPwmPortPinArray1,
&FongPwmPortPinArray2,
&FongPwmPortPinArray3,
&FongPwmPortPinArray4,
&FongPwmPortPinArray5,
&FongPwmPortPinArray6
};
*/
// *** Evaluation board structure ***
typedef struct
{
portPinArrayPointerArray *LedPortPinArrayPointerArray;
portPinArrayPointerArray *KeyPortPinArrayPointerArray;
portPinArrayPointerArray *PwmPortPinArrayPointerArray;
} mcuBoardStruct;
mcuBoardStruct *CreateFongBoardStruct()
{
mcuBoardStruct *FongBoardStruct;
FongBoardStruct->LedPortPinArrayPointerArray = FongBoardLedList1;
// FongBoardStruct->KeyPortPinArrayPointerArray = FongBoardKeyList1;
// FongBoardStruct->PwmPortPinArrayPointerArray = FongBoardPwmList1;
return FongBoardStruct;
}
// ***********************************************************************
// Main function
// ***********************************************************************
void FongBlink02() // Blink WHUT Board PIO1_8 LED
{
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);
}
}
// ***********************************************************************
// Delay functions
// ***********************************************************************
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++)
{
}
}
}
}
// *** Loop constants ***
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;
#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
// ***********************************************************************
// System initialization functions
// ***********************************************************************
void systemInitialization()
{
/* Enable GPIO block clock */
SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_GPIO, ENABLE);
}
// ***********************************************************************
// GPIO functions
// ***********************************************************************
// * typedefs and #defines *
#define INPUT_DIRECTION 0
#define OUTPUT_DIRECTION 1
#define LOGIC_LOW_LEVEL 0
#define LOGIC_HIGH_LEVEL 1
#define LOW 0
#define HIGH 1
typedef int directionValue;
directionValue InputDirection = 0;
directionValue OutputDirection = 1;
typedef int logicLevelValue;
logicLevelValue LogicLevelLow = 0;
logicLevelValue LogicLevelHigh = 1;
#define LOW 0
#define HIGH 1
// *** GPIO typedef and functions ***
typedef GPIO_TypeDef *gpioStructPointerArray[4];
gpioStructPointerArray GpioStructPointerArray = {LPC_GPIO0, LPC_GPIO1, LPC_GPIO2, LPC_GPIO3};
GPIO_TypeDef *getGpioStructPointer(int portNumber)
{
GPIO_TypeDef *gpioStructPointer;
gpioStructPointer = GpioStructPointerArray[portNumber];
return gpioStructPointer;
}
typedef struct
{
GPIO_TypeDef *GpioStructPointer;
int PinNumber;
} gpioPortStructPinStruct;
gpioPortStructPinStruct *getGpioPortStructPinStructPointer(portNumber portNumber, pinNumber pinNumber)
{
gpioPortStructPinStruct *gpioPortStructPinStruct;
gpioPortStructPinStruct->GpioStructPointer = getGpioStructPointer(portNumber);
gpioPortStructPinStruct->PinNumber = pinNumber;
return gpioPortStructPinStruct;
}
// ***********************************************************************
// Name - setGpioDirectionRegisterBitInput
// Input - port control structure, pin number
// Output - set pin as input
// ***********************************************************************
void setGpioDirectionRegisterBitInput(GPIO_TypeDef *gpio_struct_ptr, int bitNumber)
{
gpio_struct_ptr->DIR &= ~(1 << bitNumber);
}
// ***********************************************************************
// Name - setGpioDirectionRegisterBitOutput
// Input - port control structure, pin number
// Output - set pin as output
// ***********************************************************************
void setGpioDirectionRegisterBitOutput(GPIO_TypeDef *gpio_struct_ptr, int bitNumber)
{
gpio_struct_ptr->DIR |= (1 << bitNumber);
}
// ***********************************************************************
// Name - setGpioDataRegisterBitLow
// Input - port control structure, pin number
// Output - set pin as output
// ***********************************************************************
void setGpioDataRegisterBitLow(GPIO_TypeDef *gpio_struct_ptr, int bitNumber)
{
gpio_struct_ptr->DATA &= ~(1 << bitNumber);
}
// ***********************************************************************
// Name - setGpioDataRegisterBitHigh
// Input - port control structure, pin number
// Output - set pin as output
// ***********************************************************************
void setGpioDataRegisterBitHigh(GPIO_TypeDef *gpio_struct_ptr, int bitNumber)
{
gpio_struct_ptr->DATA |= (1 << bitNumber);
}
// ***********************************************************************
// Name - setGpioDirectionRegister
// Input - port control structure, pin number, direction value
// Output - set pin as input or output
// ***********************************************************************
void setPortPinDirection(GPIO_TypeDef *gpio_struct_ptr, int pinNumber, directionValue directionValue)
{
if (directionValue == InputDirection)
setGpioDirectionRegisterBitInput(gpio_struct_ptr, pinNumber);
else
setGpioDirectionRegisterBitOutput(gpio_struct_ptr, pinNumber);
}
// ***********************************************************************
// Name - setGpioDataRegister
// Input - port control structure, pin number, data value
// Output - none
// ***********************************************************************
void setPortPinData(GPIO_TypeDef *gpio_struct_ptr, int pinNumber, logicLevelValue logicLevelValue)
{
if (logicLevelValue == LogicLevelLow)
setGpioDataRegisterBitLow(gpio_struct_ptr, pinNumber);
else
setGpioDataRegisterBitHigh(gpio_struct_ptr, pinNumber);
}
// ***********************************************************************
// Function - getGpioDataRegisterBitValue
// Input - GPIO structure pointer, bit position
// Output - port pin data bit
// ***********************************************************************
logicLevelValue getGpioDataRegisterBitValue(GPIO_TypeDef *gpio_struct_ptr, int bitPosition)
{
logicLevelValue logicLevelValue;
int GpioDataRegisterMask = (1 << bitPosition);
if ((gpio_struct_ptr->DATA &= GpioDataRegisterMask) == GpioDataRegisterMask)
logicLevelValue = HIGH;
else
logicLevelValue = LOW;
return logicLevelValue;
}
// ***********************************************************************
// Name - get port number for portPinArray
// Input - port pin array
// Output - portNumber
// ***********************************************************************
portNumber getPortNumber061(portPinArray portPinArray)
{
int portNumber;
portNumber = portPinArray[PortIndex];
return portNumber;
}
// ***********************************************************************
// Name - get port number from portPinArrayPointerArray
// Input - portPinPointerArray, deviceNumber
// Output - portNumber
// ***********************************************************************
portNumber getPortNumber06(portPinArrayPointerArray portPinArrayPointerArray, deviceNumber deviceNumber)
{
int portNumber;
portNumber = getPortNumber061(*portPinArrayPointerArray[deviceNumber - 1]);
return portNumber;
}
// ***********************************************************************
// Name - get pin number for portPinArray
// Input - port pin array
// Output - pinNumber
// ***********************************************************************
pinNumber getPinNumber061(portPinArray portPinArray)
{
int pinNumber;
pinNumber = portPinArray[PinIndex];
return pinNumber;
}
// ***********************************************************************
// Name - get pin number from portPinArrayPointerArray and index
// Input - portPinPointerArray, index
// Output - pinNumber
// ***********************************************************************
pinNumber getPinNumber06(portPinArrayPointerArray portPinArrayPointerArray, deviceNumber deviceNumber)
{
int pinNumber;
pinNumber = getPinNumber061(*portPinArrayPointerArray[deviceNumber - 1]);
return pinNumber;
}
// *** 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