2014-01-17
SPI test -mled080.h
/ ***********************************************************************
// mled080.h 2014jan17hkt2053
// ***********************************************************************
#include "ledcode080.h"
// *** MAX7219 Register Addresses ***
#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 Commands ***
#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 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 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_MATRIX_NUMBER 16
#define MAX_BUFFER_SIZE 32
// ***************************************************************************
// MAX7219 Functions
// ***************************************************************************
#define TEST_DIGIT_ARRAY_00 0
#define TEST_DIGIT_ARRAY_01 1
#define TEST_DIGIT_ARRAY_02 2
#define TEST_DIGIT_ARRAY_03 3
#define TEST_DIGIT_ARRAY_10 4
#define TEST_DIGIT_ARRAY_14 5
#define TEST_DIGIT_ARRAY_15 6
#define TEST_DIGIT_ARRAY_16 7
typedef int eightDigitArray[8];
typedef eightDigitArray *eightDigitArrayPointerArray[8];
eightDigitArray EightDigitArraySpi00 = {5, 14, 1, 15, 0, 0, 15, 3}; // SPI sp 0 0 sp 3
eightDigitArray EightDigitArraySpi01 = {5, 14, 1, 15, 0, 1, 15, 1};
eightDigitArray EightDigitArraySpi02 = {5, 14, 1, 15, 0, 2, 15, 2};
eightDigitArray EightDigitArraySpi03 = {5, 14, 1, 15, 0, 3, 15, 3};
eightDigitArray EightDigitArraySpi10 = {5, 14, 1, 15, 1, 0, 15, 4};
eightDigitArray EightDigitArraySpi14 = {5, 14, 1, 15, 1, 4, 15, 5};
eightDigitArray EightDigitArraySpi15 = {5, 14, 1, 15, 1, 5, 15, 6};
eightDigitArray EightDigitArraySpi16 = {5, 14, 1, 15, 1, 6, 15, 7};
eightDigitArrayPointerArray EightDigitArrayPointerArrayTest01 = \
{
&EightDigitArraySpi00, \
&EightDigitArraySpi01, \
&EightDigitArraySpi02, \
&EightDigitArraySpi03, \
&EightDigitArraySpi10, \
&EightDigitArraySpi14, \
&EightDigitArraySpi15, \
&EightDigitArraySpi16
};
void displayMax7219EightDigitV090d(uint8_t mcuBoardNumber, uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
uint8_t testDigitArrayNumber)
{
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
OPERATION_ADDR, SHUT_DOWN);
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
DIGIT_ADDR_7, (*EightDigitArrayPointerArrayTest01[testDigitArrayNumber])[0]);
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
DIGIT_ADDR_6, (*EightDigitArrayPointerArrayTest01[testDigitArrayNumber])[1]);
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
DIGIT_ADDR_5, (*EightDigitArrayPointerArrayTest01[testDigitArrayNumber])[2]);
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
DIGIT_ADDR_4, (*EightDigitArrayPointerArrayTest01[testDigitArrayNumber])[3]);
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
DIGIT_ADDR_3, (*EightDigitArrayPointerArrayTest01[testDigitArrayNumber])[4]);
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
DIGIT_ADDR_2, (*EightDigitArrayPointerArrayTest01[testDigitArrayNumber])[5]);
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
DIGIT_ADDR_1, (*EightDigitArrayPointerArrayTest01[testDigitArrayNumber])[6]);
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
DIGIT_ADDR_0, (*EightDigitArrayPointerArrayTest01[testDigitArrayNumber])[7]);
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
OPERATION_ADDR, NORMAL);
}
void writeMax7219CommandV0909(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
portPinArray *portPinArrayPointer, \
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;
spiTransmit0909(spiChannelNumber, slaveSelectNumber, portPinArrayPointer, xferConfig);
}
void setupMax7219DigitModeV090c(uint8_t mcuBoardNumber, uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
OPERATION_ADDR, SHUT_DOWN);
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
DECODE_MODE_ADDR, DECODE_ALL_8_DIGITS);
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
SCAN_LIMIT_ADDR, SCAN_ALL_8_DIGITS);
}
void setupMax7219MatrixModeV090c(uint8_t mcuBoardNumber, uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
OPERATION_ADDR, SHUT_DOWN);
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
DECODE_MODE_ADDR, NO_DECODE_ALL_8_ROWS); // no 7 segment decode for matrix mode
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
SCAN_LIMIT_ADDR, SCAN_ALL_8_DIGITS);
}
// void displayMax7219OneMatrixV090d(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
// uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
// uint8_t matrixNumber, uint8_t matrixColumn[])
void displayMax7219OneMatrixV090d(uint8_t mcuBoardNumber, uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
uint8_t matrixColumn[])
{
// *** shut down ***
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
OPERATION_ADDR, SHUT_DOWN);
// *** display 8 columns ***
uint8_t columnNumber;
uint8_t digitAddress;
for (columnNumber = 0; columnNumber < 8; columnNumber++)
{
digitAddress = columnNumber + 1;
// displayMax7219OneMatrixColumnV090d(portPinArraryPointerArrayArray, \
// spiChannelNumber, slaveSelectNumber, \
// matrixNumber, digitAddress, matrixColumn[7 - columnNumber]);
displayMax7219OneMatrixColumnV090d(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
digitAddress, matrixColumn[7 - columnNumber]);
}
// *** start up ***
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
OPERATION_ADDR, NORMAL);
}
void displayMax7219OneMatrixColumnV090d(uint8_t mcuBoardNumber, uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
uint8_t digitAddress, uint8_t digitData)
{
// writeMax7219CommandV0803(portPinArraryPointerArrayArray, \
// spiChannelNumber, slaveSelectNumber, matrixNumber, digitAddress, digitData);
writeMax7219CommandV0909(spiChannelNumber, slaveSelectNumber, \
(*SlaveSelectPortPinArrayPointerArrayPointerArrayWuyinsSpi[spiChannelNumber])[slaveSelectNumber], \
digitAddress, digitData);
}
// ***************************************************************************
// End
// ***************************************************************************
.END
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment