|
|
View previous topic :: View next topic |
Author |
Message |
rovtech
Joined: 24 Sep 2006 Posts: 262
|
Alphanumerics on 8x8 LED matrix with MAX7219 |
Posted: Tue Mar 02, 2021 4:12 pm |
|
|
Has anyone driven a MAX7219 and 8x8 LED matrix with a PIC to display alphanumerics?
Here is what I mean, done with Arduino:
https://www.instructables.com/Dot-Matrix-With-MAX7219-Interfacing-With-Arduino/
It uses libraries that may not exist for CCS.
I did find a few examples in this forum with SPI and MAX7219 problems discussed, but not for alphanumerics.
I assume it would require a character generator table that would be big? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Tue Mar 02, 2021 5:22 pm |
|
|
The 'driver' as well as 'scrolling alphabet' prgram are in that link and translating to CCS C is not that difficult.
Neither is really that long nor complicated. Maybe an evenings work and a pot of coffee. |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
|
Posted: Wed Mar 03, 2021 3:58 pm |
|
|
I appreciate your reply temtronic but "Not that difficult" is relative.
I have never used SPI so it will take me a day to master that.
I have never used Arduino and if I have to learn that I may as well use the Arduino project.
That said I can guess at some of the functions used in the Arduino code and hope to find equivalent ones in CCS.
I have never used the MAX 7219 so I will learn that at the same time I learn SPI. I read the data sheet and there is no mention of driving an 8x8 array. It covers 7 segment displays which seems weird for a device that has a 16 bit data input (8x8). I guess it drives 8 characters of 7 segments plus a decimal point, so 8x8. I am more familiar wit BCD to 7 segment decoders but I had to scan the displays with separate hardware.
I see on the schematic they use the digit select for the horizontal row of LEDs, 1 to 8 from the left which makes sense.
The segment select lines are used to select the vertical row of LEDs but the segments used are, from the bottom, A F B G C E Dp D which are marked on the schematic as HGFEDCBA which must have a reason but is not obvious to me. Any X and Y selection will light the selected LED.
The Arduino software for scrolling characters sends, from an array, width and height followed by five 8 bit bytes. The width is from 1 to 5 (never any higher) and the height is always 8. I can guess that the characters are from 1x8 to 5x8 and the 5 bytes are the LEDs to light in the rows. For example a ! (exclamation) uses one row and lights B10111111 and the other 4 bytes are not used or are turned off. I find it confusing but I guess it is to reduce storage in some way.
It seems easier for me to design my own program with software I understand. I think converting the code directly will drive me crazy.
Writing this helps me understand and any contributions are welcome.
I was hoping there were functions and libraries in CCS similar to those used in the Arduino projects. Such as Parola used here:
https://www.makerguides.com/max7219-led-dot-matrix-display-arduino-tutorial/
However I can't even figure out what language it is written in. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 03, 2021 4:19 pm |
|
|
This webpage is for the PIC. It doesn't use Arduino.
https://microcontrollerslab.com/8x8-led-matrix-interfacing-max7219-pic-microcontroller/
It's not written in CCS, but it has functions such as spi_write() and
spi_read(), and you can substitute the CCS functions for those.
Also, it has a character table. You wanted that:
Code: | unsigned const char symbol[97][8] ={
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, //Ascii- space
{ 0x00,0x00,0x00,0x5F,0x5F,0x00,0x00,0x00 }, //Ascii- !
{ 0x00,0x07,0x07,0x00,0x00,0x07,0x07,0x00 }, //Ascii- "
{ 0x24,0x7E,0x7E,0x24,0x7E,0x7E,0x24,0x00 }, //Ascii- #
etc.
} |
|
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
|
Posted: Wed Mar 03, 2021 6:36 pm |
|
|
Thank you, thank you.
At last something that looks familiar that I can understand.
I have figured out the 7219 and the pins on my PIC and the SPI functions.
This will help immensely.
Peter |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Mar 04, 2021 6:00 am |
|
|
aw.. the 7219 is a 'cheat'...if, IF, you really want to have 'fun', just tie the LED display directly to a PIC with 16 I/O lines then cut code......
After you spend hours and hours and ......sigh,
yeah the 7219 makes life a LOT easier
Jay |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
|
Posted: Fri Mar 05, 2021 7:55 pm |
|
|
A few problems:
I had purchased two 8x8 LED arrays complete with PCB and MAX7219 in sockets, same vendor and on the same order. I got a green PCB and a blue PCB. Each LED array had different markings. I started with the green one. I thought I had a grasp of SPI so tried a simple program.
I was getting garbage on the LED array so simplified my software down to sending data to one column. Still garbage.
I read "SPI with MAX7219 and MAX31855" in this forum and noted Ttelmah's advice on reading while writing to allow the buffer to empty and added that to my program, still garbage. I was about to start tracing the board wiring and pulled the LED array. On impulse I turned it around and started getting something reasonable but the columns did not appear where I thought they should although the data looked OK.
I tried the blue PCB and got different results in different columns. I traced the wiring and patched the 8 lines to where I thought they should be. Now the columns appeared where I expected them but I could only display the first two.
I was misled by the scan limit register thinking it meant the number of displays (which it does) but in my case it means the number of columns. Increasing it from 1 to 8 solved the problem. I experimented and got a clear function working.
Conclusion: The two boards are wired differently and both are wrong.
I now have a working knowledge of SPI but I will never be a programmer.
Here is my working code. It lights every LED (64 of them) in order.
I will try displaying text next.
Code: | ///////////////////////////////////////////////////////////////////////////
/// LED Matrix_16F1503.C ///
/// Last modified: 4 Mar 2021 ///
/// A program to test the MAX7219 and 8x8 LED Matrix ///
/// C0 (pin 10) is SCK ///
/// C1 (pin 9) is SDI also known as MISO or CIPO ///
/// C2 (pin 8) is SDO also known as SIMO or PICO if I remember OK ///
/// C3 (pin 7) is SS or CE. below is my program, sketch, or App ///
///////////////////////////////////////////////////////////////////////////
/* Pre-processor directives */
#include <16F1503.H>
#include <stdio.h>
#include <stdlib.h>
#include "ascii_chars.h"
// #include "MAX7219.h"
#fuses INTRC_IO, NOWDT, PUT, NOPROTECT, NOBROWNOUT
#use delay (clock = 1MHz) // PIC runs at 4 MHz
#use SPI(FORCE_HW, MODE=0, BITS=8)
#byte portA = getenv("SFR:PORTA")
#byte portC = getenv("SFR:PORTC")
// Variables
#define DISP PIN_C3 // Chip Select for Display on SPI Bus
// Function Prototypes
void maxsetup(); //configure MAX7219 registers
void maxsend(char address, char data); // send routine for max7219 to update display
void maxclear();
// void MAX7219_displayText(char *text);
/* The main function */
void main()
{
// declare variables
int i,j; // integer counters
// initialize port directions
set_tris_a (0b11000111); // set Port A2
set_tris_c (0b11110010); // set Port C all inputs
maxsetup(); // setup MAX7219
maxclear(); // clear MAX7219
// main loop
while (1) // loop endlessly
{
for(j=1;j<=8;j++) // select the columns
{
for(i=1;i!=0;i=i*2) // select each LED in turn
{
maxsend(j,i);
delay_ms(200);
} // end of i loop
maxsend(j,0); // clear the last LED
} // end of j loop
} // end of endless while loop
} // end of main function
// ********** Functions **********
// function maxsetup
void maxsetup() //configure MAX7219 registers
{
maxsend(0x09, 0x00); // Decode Mode: 0 = no decode
maxsend(0x0a, 0x03); // Brightness: 0 = dim, f = brightest
maxsend(0x0b, 0x07); // Number of columns: 8 Digits
maxsend(0x0f, 0x00); // Test Register: 0 = Normal, 1 = Test Operation
maxsend(0x0c, 0x01); // Shutdown: 0 = Shutdown, 1 = Normal Operation
}
// function maxclear
//void maxclear(char address, char data) // clear display
void maxclear()
{
char i,j;
for(j=1;j<=8;j++)
{
for(i=1;i!=0;i=i*2)
maxsend(j,0);
}
}
// function maxsend
void maxsend(char address, char data) // send routine for max7219 to update display
{
char temp; // temporary character
output_low(DISP);
temp=spi_xfer(address); //send address
temp=spi_xfer(data); //send data
output_high(DISP);
delay_us(2);
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Fri Mar 05, 2021 8:57 pm |
|
|
re: ...
Conclusion: The two boards are wired differently and both are wrong.
Welcome to my world !!
Maybe a 3rd board, red ?, will be wired correctly ?, sigh, sorry but it is ,well, kinda funny....
The EASY part of the prject SHOULD be the PCBs.....
If you want a real headache, try to figure out HOW you can get a PIC to detect a 'missing' DS18B20(broken wire) on a string of 5-10 pieces and STILL have the other 9 communicate...using '1-wire'....
I'm getting too old for this ......
Jay |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|