The majority of the testing simply involves exploring/developing the PIC16F876A code library to provide the necessary interfacing and control.
The Video Section shows the developed code in example software to control dot matrix LED displays and animated scrolling text displays.
MAX7221 SPI Interface/Control Registers
The MAX7221 datasheet gives full details, but the following is a summary of the interfacing via SPI/control registers.
Data is sent to the MAX7221 as a serial data stream of 16-bit packets. To clock data into the MAX7221, the CS line (pin 12) is held low, and then the data is clocked into DIN (pin 1) with each rising edge of CLK (pin 13). After the 16th bit, the data is latched when the CS line goes high. If more than one 16-bit data packet is clocked into the MAX7221, the data is propagated at DOUT (pin 24). Consequently, connecting DOUT from one MAX7221 to the DIN of a further MAX7221 allows daisy-chaining.
The MAX7221 register map and the BCD to Code B font mapping (together with the MAX7221 pin outs for when not using BCD decode mode) is summarised in the following diagram.
PIC Microcontroller Interface Code
The PIC micrcontroller code is based upon information given in a blog post discussing interfacing a PIC18F4550 with a 7-segment numeric LED display.(1). Various downloads are available in the table below.
The header file contains various #define's used to specify the MAX7221 command set, SPI/interface pin definitions and the following functions:
void max7221_ClkOutData(char theData);
// 'bit-bang' sending a single byte of data to MAX7221
void max7221_putData(char RegAddr,char theData, char addr7221);
//RegAddr - Max7221 register address
//theData - register data portion
//add7221 - the Id number for cascaded Max7221 (1st chip is Id 1)
//uses max7221_ClkOutData() to send the actual data to the MAX7221
void max7221_init();
// Initialise all daisy-chained MAX7221.
// #define NUM_CASCADED_MAX7221 = number of cascaded chips
// Initialised state = no decode mode, scan limit all digits,
// duty cycle 7, normal mode for shutdown
The current code is targetted at controlling 8x8 dot matrix displays to enable scrolling text messages and animated displays. This means specific functions to enable output of 'decimal' digits to 7-segment LED displays is not specifically handled (i.e. using the MAX7221 capacity to decode BCD directly to 7-segment output display control).
The following example program (output shown in the Video Section) demonstrates the functionality of a scrolling message with a three 8x8 dot-matrix display.
#include "string.h"
#include "max7221.h"
//#define NUM_CASCADED_MAX7221 3 in max7221.h
#define STRING_SIZE 6 //max chars allowed = STRING_SIZE-1
void main() {
char dispChar;
char input_str[STRING_SIZE]={'H','E','L','L','O'};
int i;
int j;
int stringLen;
int scrollEnd;
max7221_init();
//! max7221_putData(MAX7221Reg_DISPLAY_TEST,DISPLAY_TEST_MODE);
stringLen=strlen(input_str);
scrollEnd=-6*stringLen; //6=character width
do {
for (i=24;i>scrollEnd;i--) {
currentPos=i;
for (j=0; j < stringLen; j++) {
max7221_PrintChar(input_str[j]);
delay_ms(50); //scroll 'step' time
}
}
} while (TRUE);
}
A more comprehensive example of the code for the MAX7221 incorporating scrolling text display with animations is given in the Animated LED Matrix Sign project which utilises five Max7221's daisy-chained to control a 8 x 36 inch DIY display composed of LED's.
PIC Microcontroller Code Downloads
Only Logged-In Members can add comments