int main()
{
testMax7219DisplayDigitV0801(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
SPI_CHANNEL_0, SLAVE_SELECT_0, \
5, 0, 0, 0, 0, 0, 0, 0);
testMax7219DisplayDigitV0801(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
SPI_CHANNEL_0, SLAVE_SELECT_1, \
5, 0, 0, 0, 0, 0, 0, 1);
testMax7219DisplayDigitV0801(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
SPI_CHANNEL_0, SLAVE_SELECT_2, \
5, 0, 0, 0, 0, 0, 0, 2);
testMax7219DisplayDigitV0801(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
SPI_CHANNEL_0, SLAVE_SELECT_3, \
5, 0, 0, 0, 0, 0, 0, 3);
testMax7219DisplayDigitV0801(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
SPI_CHANNEL_0, SLAVE_SELECT_4, \
5, 0, 0, 0, 0, 0, 0, 4);
testMax7219DisplayMatrixV0801(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
SPI_CHANNEL_0, SLAVE_SELECT_5, MATRIX_0, MatrixChar_O);
delayMilliSecond(2000);
testMax7219DisplayMatrixV0803(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
SPI_CHANNEL_0, SLAVE_SELECT_5, MATRIX_1, MatrixChar_K);
delayMilliSecond(2000);
testMax7219DisplayMatrixV0804(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
SPI_CHANNEL_0, SLAVE_SELECT_5, \
MATRIX_0, MatrixChar_O, \
MATRIX_1, MatrixChar_K);
}
void testMax7219DisplayMatrixV0804(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
uint8_t matrixNumber0, uint8_t matrixData0[], \
uint8_t matrixNumber1, uint8_t matrixData1[])
{
setupAllSpiChannelsAndSlaveSelectPorts(portPinArraryPointerArrayArray);
setupMax7219PositionMatrixModeV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, \
matrixNumber0);
setupMax7219PositionMatrixModeV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, \
matrixNumber1);
displayMax7219OneMatrix0803(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, \
matrixNumber0, matrixData0);
displayMax7219OneMatrix0803(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, \
matrixNumber1, matrixData1);
}
void testMax7219DisplayMatrixV0803(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
uint8_t matrixNumber, uint8_t matrixData[])
{
setupAllSpiChannelsAndSlaveSelectPorts(portPinArraryPointerArrayArray);
setupMax7219PositionMatrixModeV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, \
matrixNumber);
displayMax7219OneMatrix0803(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, \
matrixNumber, matrixData);
}
void testMax7219DisplayMatrixV0801(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
uint8_t matrixNumber, uint8_t matrixData[])
{
setupAllSpiChannelsAndSlaveSelectPorts(portPinArraryPointerArrayArray);
setupMax7219PositionMatrixModeV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, \
matrixNumber);
displayMax7219OneMatrix080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, \
matrixData);
}
// ***********************************************************************
// mled050.h 2013nov10hkt1152
// MAX7219 4-digit 7-segment and 8x8 matrix LED
// ***********************************************************************
#include "spi050.h"
// *** MAX7219 Register Address Map ***
#define NO_OP_ADDR 0x00
#define DIGIT_ADDR_0 0x01
#define DIGIT_ADDR_1 0x02
#define DIGIT_ADDR_2 0x03
#define DIGIT_ADDR_3 0x04
#define DIGIT_ADDR_4 0x05
#define DIGIT_ADDR_5 0x06
#define DIGIT_ADDR_6 0x07
#define DIGIT_ADDR_7 0x08
#define DECODE_MODE_ADDR 0x09
#define INTENSITY_ADDR 0x0a
#define SCAN_LIMIT_ADDR 0x0b
#define OPERATION_ADDR 0x0c // Shutdown address actually
#define DISPLAY_TEST_ADDR 0x0f
// *** MAX7219 Command Format ***
#define SHUT_DOWN 0x00
#define NORMAL 0x01
#define CODE_B_ALL_DIGITS 0xff
#define NO_DECODE_ALL_DIGITS 0x00
#define DECODE_ALL_8_DIGITS 0xff
#define NO_DECODE_ALL_8_DIGITS 0x00
#define NO_DECODE_ALL_8_ROWS 0x00
#define DISPLAY_8_DIGITS 0x07
#define SCAN_ALL_8_DIGITS 0x07
#define SCAN_ALL_8_ROWS 0x07
// *** Data Constants ***
#define POSITION_0 0
#define POSITION_1 1
#define POSITION_2 2
#define POSITION_3 3
#define POSITION_4 4
#define POSITION_5 5
#define POSITION_6 6
#define MATRIX_0 0
#define MATRIX_1 1
#define MATRIX_2 2
#define MATRIX_3 3
#define MATRIX_4 4
#define MATRIX_5 5
#define MATRIX_6 6
#define DEVICE_1 1
#define DEVICE_2 2
#define DEVICE_3 3
#define DEVICE_4 4
#define LED_DRIVER_1 1
#define LED_DRIVER_2 2
#define LED_DRIVER_3 3
#define LED_DRIVER_4 4
#define DIGIT_0 0
#define DIGIT_1 1
#define DIGIT_2 2
#define DIGIT_3 3
#define DIGIT_4 4
#define DIGIT_5 5
#define DIGIT_6 6
#define DIGIT_7 7
#define DIGIT_8 8
#define DIGIT_9 9
#define CHAR_HYPHEN 10
#define CHAR_E 11
#define CHAR_H 12
#define CHAR_L 13
#define CHAR_P 14
#define CHAR_BLANK 15
#define PATTERN_ALL_ON 0xff
#define PATTERN_ALL_OFF 0x00
#define ADDRESS_INDEX 0
#define DATA_INDEX 1
#define MAX_DEVICE_NUMBER 16
#define MAX_BUFFER_SIZE 32
#define MAX_MATRIX_NUMBER 4
uint8_t char_A[5] = {0x7E, 0x11, 0x11, 0x11, 0x7E};
uint8_t char_K[5] = {0x41, 0x22, 0x14, 0x08, 0x7f};
uint8_t char_O[5] = {0x3E, 0x41, 0x41, 0x41, 0x3E};
uint8_t MatrixChar_A[5] = {0x7E, 0x11, 0x11, 0x11, 0x7E};
uint8_t MatrixChar_K[5] = {0x41, 0x22, 0x14, 0x08, 0x7f};
uint8_t MatrixChar_O[5] = {0x3E, 0x41, 0x41, 0x41, 0x3E};
uint8_t CharBigO[8] = {0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x00, 0x00};
uint8_t CharBigK[8] = {0x41, 0x22, 0x14, 0x08, 0x7F, 0x00, 0x00, 0x00};
uint8_t TriGram0[8] = {0x54, 0x54, 0x54, 0x00, 0x54, 0x54, 0x54, 0x00};
// *** Version 0.80 ***
// void writeMcp7219Command080()
// void setupMcp7219DigitModeV080()
// void displayMcp7219Display8DigitsV080()
// void display1LedDigit080()
// void display8LedDigit080()
// void shutDownLedDriver080()
// void startUpLedDriver080()
// void displayLedDigit080()
void setupAndDisplayMax7219EightDigitsV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4, \
uint8_t digit5, uint8_t digit6, uint8_t digit7, uint8_t digit8)
{
setupMax7219DigitModeV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber);
displayMax7219EightDigitsV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, LED_DRIVER_1, digit1, digit2, \
digit3, digit4, digit5, digit6, digit7, digit8);
}
void setupMax7219DigitModeV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, OPERATION_ADDR, SHUT_DOWN);
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, DECODE_MODE_ADDR, DECODE_ALL_8_DIGITS);
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, SCAN_LIMIT_ADDR, SCAN_ALL_8_DIGITS);
}
void setupMax7219PositionDigitModeV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, uint8_t positionNumber)
{
writeMax7219PositionCommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, OPERATION_ADDR, SHUT_DOWN, positionNumber);
writeMax7219PositionCommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, DECODE_MODE_ADDR, DECODE_ALL_8_DIGITS, positionNumber);
writeMax7219PositionCommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, SCAN_LIMIT_ADDR, SCAN_ALL_8_DIGITS, positionNumber);
}
void displayMax7219EightDigitsV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, uint8_t ledDriverNumber, \
uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4, \
uint8_t digit5, uint8_t digit6, uint8_t digit7, uint8_t digit8)
{
shutDownMax7219V080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ledDriverNumber);
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_7, digit1);
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_6, digit2);
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_5, digit3);
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_4, digit4);
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_3, digit5);
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_2, digit6);
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_1, digit7);
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_0, digit8);
startUpMax7219V080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, ledDriverNumber);
}
void displayMax7219OneDigitV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
uint8_t deviceNumber, uint8_t digitAddress, uint8_t digitData)
{
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, digitAddress, digitData);
}
void writeMax7219CommandV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
uint8_t commandRegisterAddress, uint8_t command)
{
uint8_t txBuffer[2];
uint8_t rxBuffer[2];
SSP_DATA_SETUP_Type xferConfig;
xferConfig.tx_data = txBuffer;
xferConfig.rx_data = rxBuffer;
xferConfig.length = 2;
txBuffer[ADDRESS_INDEX] = commandRegisterAddress;
txBuffer[DATA_INDEX] = command;
spiTransmit082(portPinArraryPointerArrayArray, spiChannelNumber, slaveSelectNumber, xferConfig);
}
void writeMax7219CommandV0803(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
uint8_t matrixNumber, \
uint8_t commandRegisterAddress, uint8_t command)
{
uint8_t txBuffer[MAX_BUFFER_SIZE];
uint8_t rxBuffer[MAX_BUFFER_SIZE];
SSP_DATA_SETUP_Type xferConfig;
xferConfig.tx_data = txBuffer;
xferConfig.rx_data = rxBuffer;
xferConfig.length = 2 * (matrixNumber +1);
txBuffer[ADDRESS_INDEX] = commandRegisterAddress;
txBuffer[DATA_INDEX] = command;
int i;
for (i = 1; i < matrixNumber; i++)
{
txBuffer[(i * 2) + ADDRESS_INDEX] = NO_OP_ADDR;
}
spiTransmit082(portPinArraryPointerArrayArray, spiChannelNumber, slaveSelectNumber, xferConfig);
}
/*
void writeMax7219PositionCommandV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
uint8_t commandRegisterAddress, uint8_t command, \
uint8_t positionNumber)
{
uint8_t txBuffer[MAX_BUFFER_SIZE];
uint8_t rxBuffer[MAX_BUFFER_SIZE];
SSP_DATA_SETUP_Type xferConfig;
xferConfig.tx_data = txBuffer;
xferConfig.rx_data = rxBuffer;
xferConfig.length = positionNumber * 2;
txBuffer[ADDRESS_INDEX] = commandRegisterAddress;
txBuffer[DATA_INDEX] = command;
int i;
for (i = 1; i < positionNumber; i++)
{
txBuffer[(i * 2) + ADDRESS_INDEX] = NO_OP_ADDR;
}
spiTransmit082(portPinArraryPointerArrayArray, spiChannelNumber, slaveSelectNumber, xferConfig);
}
*/
void shutDownMax7219V080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, OPERATION_ADDR, SHUT_DOWN);
}
void startUpMax7219V080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, OPERATION_ADDR, NORMAL);
}
void shutDownMax7219V0803(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, uint8_t matrixNumber)
{
writeMax7219CommandV0803(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, matrixNumber, OPERATION_ADDR, SHUT_DOWN);
}
void startUpMax7219V0803(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, uint8_t matrixNumber)
{
writeMax7219CommandV0803(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, matrixNumber, OPERATION_ADDR, NORMAL);
}
// *** Matrix mode ***********************************************************
void setupMax7219MatrixModeV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, OPERATION_ADDR, SHUT_DOWN);
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, DECODE_MODE_ADDR, NO_DECODE_ALL_DIGITS); // No decode
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, SCAN_LIMIT_ADDR, SCAN_ALL_8_DIGITS);
}
void setupMax7219PositionMatrixModeV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, uint8_t positionNumber)
{
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, OPERATION_ADDR, SHUT_DOWN);
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, DECODE_MODE_ADDR, NO_DECODE_ALL_DIGITS); // No decode
writeMax7219CommandV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, SCAN_LIMIT_ADDR, SCAN_ALL_8_DIGITS);
}
void setupAndDisplayMax7219MatrixV080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
uint8_t matrixColumn[])
{
setupMax7219MatrixModeV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber);
displayMax7219OneMatrix080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, \
matrixColumn);
}
void displayMax7219OneMatrix0803(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
uint8_t matrixNumber, uint8_t matrixColumn[8])
{
shutDownMax7219V0803(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, matrixNumber);
uint8_t columnNumber;
uint8_t digitAddress;
for (columnNumber = 0; columnNumber < 8; columnNumber++)
{
digitAddress = columnNumber + 1;
displayMax7219OneMatrixColumnV0803(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, \
matrixNumber, digitAddress, matrixColumn[7 - columnNumber]);
}
startUpMax7219V0803(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, matrixNumber);
}
void displayMax7219OneMatrixColumnV0803(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
uint8_t matrixNumber, uint8_t digitAddress, uint8_t digitData)
{
writeMax7219CommandV0803(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, matrixNumber, digitAddress, digitData);
}
void displayMax7219OneMatrix080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
uint8_t matrixColumn[8])
{
shutDownMax7219V080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber);
uint8_t columnNumber;
uint8_t digitAddress;
for (columnNumber = 0; columnNumber < 8; columnNumber++)
{
digitAddress = columnNumber + 1;
displayMax7219OneDigitV080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, \
0, digitAddress, matrixColumn[7 - columnNumber]);
}
startUpMax7219V080(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber);
}
.END
No comments:
Post a Comment