while (1)
{
writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, SHUTDOWN_ADDR, SHUTDOWN_MODE);
writeBufferToMax7219(xferConfigPointer);
delayTime(ONE_SECOND);
writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, DECODE_MODE_ADDR,
CODE_B_DECODE_ALL_BITS);
writeBufferToMax7219(xferConfigPointer);
writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, SCAN_LIMIT_ADDR,
DISPLAY_8_DIGITS);
writeBufferToMax7219(xferConfigPointer);
writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, DIGIT_0_ADDR, DIGIT_2_DATA);
writeBufferToMax7219(xferConfigPointer);
writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, DIGIT_1_ADDR, DIGIT_4_DATA);
writeBufferToMax7219(xferConfigPointer);
writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, SHUTDOWN_ADDR,
NORMAL_OPERATION_MODE);
writeBufferToMax7219(xferConfigPointer);
delayTime(ONE_SECOND);
}
}
// ***********************************************************************
// spi050.h 2013oct25hk1010
// ***********************************************************************
#include "gpio050.h"
#include "led050.h"
#include "lpc11xx_ssp.h"
#include "semihosting.h"
#include "stdio.h"
// ***********************************************************************
// Max7219 Functions
// ***********************************************************************
void max7219v02() // 2013oct25hkt0934
{
// *** Print project title ***********************************************
printf("*** MAX7219 Test - 2013oct25hk1010 ***\n\n");
// *** Setup MAX7219 digit control register buffer ***********************
// Digit control register buffer
#define BUFFER_SIZE 2
#define ADDRESS_INDEX 0
#define DATA_INDEX 1
uint8_t digitControlRegisterBuffer[BUFFER_SIZE];
uint8_t dummyReceiveBuffer[BUFFER_SIZE];
// *** Set up SPI ********************************************************
// Setup SPI0 SCLK and SSEL
setupSpi050(SCK0_PIO0_6);
setupSpiSsel();
// Setup SPI0 xferConfig
SSP_DATA_SETUP_Type xferConfig;
SSP_DATA_SETUP_Type *xferConfigPointer;
xferConfigPointer = &xferConfig;
setupXferConfig(xferConfigPointer, digitControlRegisterBuffer, dummyReceiveBuffer, BUFFER_SIZE);
// *** Setup Max7219 digit and control ***********************************
// Register addresses
#define NO_OP_ADDR 0x00
#define DIGIT_0_ADDR 0x01
#define DIGIT_1_ADDR 0x02
#define DIGIT_2_ADDR 0x03
#define DIGIT_3_ADDR 0x04
#define DIGIT_4_ADDR 0x05
#define DIGIT_5_ADDR 0x06
#define DIGIT_6_ADDR 0x07
#define DIGIT_7_ADDR 0x08
#define DECODE_MODE_ADDR 0x09
#define INTENSITY 0x0a
#define SCAN_LIMIT_ADDR 0x0b
#define SHUTDOWN_ADDR 0x0c
#define DISPLAY_TEST 0x0f
// Control byte
#define SHUTDOWN_MODE 0x00
#define NORMAL_OPERATION_MODE 0x01
#define CODE_B_DECODE_ALL_BITS 0xff
#define DISPLAY_8_DIGITS 0x07
#define DIGIT_0_DATA 0
#define DIGIT_1_DATA 1
#define DIGIT_2_DATA 2
#define DIGIT_3_DATA 3
#define DIGIT_4_DATA 4
// *** Blink Digit 0 = 1, Digit 1 = 2 ************************************
while (1)
{
writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, SHUTDOWN_ADDR, SHUTDOWN_MODE);
writeBufferToMax7219(xferConfigPointer);
delayTime(ONE_SECOND);
writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, DECODE_MODE_ADDR, CODE_B_DECODE_ALL_BITS);
writeBufferToMax7219(xferConfigPointer);
writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, SCAN_LIMIT_ADDR, DISPLAY_8_DIGITS);
writeBufferToMax7219(xferConfigPointer);
writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, DIGIT_0_ADDR, DIGIT_2_DATA);
writeBufferToMax7219(xferConfigPointer);
writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, DIGIT_1_ADDR, DIGIT_4_DATA);
writeBufferToMax7219(xferConfigPointer);
writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, SHUTDOWN_ADDR, NORMAL_OPERATION_MODE);
writeBufferToMax7219(xferConfigPointer);
delayTime(ONE_SECOND);
}
}
// *** Max7219 Functions ***
void writeSegmentLedCommandToBuffer(uint8_t digitControlRegisterBuffer[BUFFER_SIZE], \
uint8_t commandRegisterAddress, uint8_t command)
{
digitControlRegisterBuffer[ADDRESS_INDEX] = commandRegisterAddress;
digitControlRegisterBuffer[DATA_INDEX] = command;
}
void writeBufferToMax7219(SSP_DATA_SETUP_Type *xferConfigPointer)
{
setSselLow();
SSP_ReadWrite(LPC_SSP0, xferConfigPointer, SSP_TRANSFER_POLLING);
setSselHigh();
}
// *** SPI Functions ***
void setupSpi050(SCK0_Position_Typedef sck0)
{
// Enable SSP0 block clock
SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_SSP0, ENABLE);
// Reset SSP0 and clock divider
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP0, ENABLE);
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP0, DISABLE);
SYSCON_SetSPI0ClockDiv(10);
// Assign GPIO pins for SPI
// SSP_SSP0PinsInit(sck0, ENABLE);
SSP_SSP0PinsInit(sck0, DISABLE); // Disable SSEL
// Initialize SSP with default configuration (Master mode, 8 bit data)
SSP_CFG_Type SSP_ConfigStruct;
SSP_ConfigStructInit(&SSP_ConfigStruct);
SSP_Init(LPC_SSP0, &SSP_ConfigStruct);
// Enable SSP peripheral
SSP_Cmd(LPC_SSP0, ENABLE);
}
void setupSpiSsel()
{
setupGpioPinOutputLow050(PortPinArraySsel); // setup GPIO pin as output
}
void setSselLow()
{
setGpioDataPinLow01(PortPinArraySsel); // SSEL low
}
void setSselHigh()
{
setGpioDataPinHigh01(PortPinArraySsel); // SSEL low
}
void setupXferConfig(SSP_DATA_SETUP_Type *xferConfigPointer, uint8_t digitControlRegisterBuffer[], \
uint8_t dummyReceiveBuffer[], uint8_t bufferSize)
{
xferConfigPointer->tx_data = digitControlRegisterBuffer;
xferConfigPointer->rx_data = dummyReceiveBuffer;
xferConfigPointer->length = bufferSize;
}
// ***************************************************************************
No comments:
Post a Comment