![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
MAX7219 and built-in SPI commands (CCS C) |
Posted: Sun Jan 15, 2006 10:42 am |
|
|
Please can someone post a source with use the built-in SPI command from CCS-C
Commands are:
setup_spi, write_spi
The code has only put an 1 on digit 1, that's all
I can't get it work ![Sad](images/smiles/icon_sad.gif) |
|
![](templates/subSilver/images/spacer.gif) |
sebdey
Joined: 11 Sep 2003 Posts: 17 Location: Switzerland
|
Driver for max7221 |
Posted: Sun Jan 15, 2006 11:42 am |
|
|
The max7219 is not spi compatible, the max7221 IS the spi display driver.
Please find my code for the spi driver, read it, and if you don't understand something, don't hesitate to ask... (but take the time to read the code)
MAX7221.h
Code: |
/*! \file max7221.h
* \brief Driver pour le driver d'affichages 7-segments SPI MAX7221
*
* !! MAX7221_CS doit être défini dans le fichier principal !!
*/
// Addresses des différents registres du MAX7221
#define NOP 0x00
#define DIG_0 0x01
#define DIG_1 0x02
#define DIG_2 0x03
#define DIG_3 0x04
#define DIG_4 0x05
#define DIG_5 0x06
#define DIG_6 0x07
#define DIG_7 0x08
#define DECODE_MODE 0x09
#define INTENSITY 0x0A
#define SCAN_LIMIT 0x0B
#define SHUTDOWN 0x0C
#define TEST 0x0F
// Diverses valeurs pour la configuration de ces registes
// Registre SHUTDOWN
#define SHUTDOWN_MODE 0x00
#define NORMAL_MODE 0x01 // Valable aussi pour le registre TEST
// Registre DECODE_MODE
#define NO_DECODE 0x00
#define BCD_DIG0 0x01
#define BCD_DIG0to3 0x0F
#define BCD_ALL 0xFF
// Registre SCAN_LIMIT
#define DIG0_ONLY 0x00
#define DIG0to1 0x01
#define DIG0to2 0x02
#define DIG0to3 0x03
#define DIG0to4 0x04
#define DIG0to5 0x05
#define DIG0to6 0x06
#define DIG0to7 0x07
// Registre TEST
#define TEST_MODE 0x00
//#define NORMAL_MODE 0x01 // Défini pour le registre Shutdown
///////////////////////////////////////////////////////////////////////////////
/*! \brief Allumage/Extinction de l'affichage
*
*
* \param booléen, true=on, false=off
*/
///////////////////////////////////////////////////////////////////////////////
void setDisplayOnOffState(short int state)
{
output_low(MAX7221_CS);
delay_cycles(4);
spi_write(SHUTDOWN);
if(state)
spi_write(NORMAL_MODE);
else
spi_write(SHUTDOWN_MODE);
output_high(MAX7221_CS);
}
///////////////////////////////////////////////////////////////////////////////
/*! \brief Entrée, sortie du mode de test
*
*
* \param booléen, true=test, false=std
*/
///////////////////////////////////////////////////////////////////////////////
void setDisplayTest(short int state)
{
output_low(MAX7221_CS);
delay_cycles(4);
spi_write(TEST);
if(state)
spi_write(TEST_MODE);
else
spi_write(NORMAL_MODE);
output_high(MAX7221_CS);
}
///////////////////////////////////////////////////////////////////////////////
/*! \brief Setup de l'intensité de l'affichage
*
*
* \param int, l'intensité, <16
*/
///////////////////////////////////////////////////////////////////////////////
void setDisplayIntensity(int intensity)
{
if(intensity<16)
{
output_low(MAX7221_CS);
delay_cycles(4);
spi_write(INTENSITY);
spi_write(intensity);
output_high(MAX7221_CS);
}
}
///////////////////////////////////////////////////////////////////////////////
/*! \brief Setup du mode de décodage pour les digits
*
*
* \param int, indiquant le mode à utiliser
*/
///////////////////////////////////////////////////////////////////////////////
void setDisplayDecodeMode(int decodeMode)
{
output_low(MAX7221_CS);
delay_cycles(4);
spi_write(DECODE_MODE);
spi_write(decodeMode);
output_high(MAX7221_CS);
}
///////////////////////////////////////////////////////////////////////////////
/*! \brief Setup du nombre de digits affichés
*
*
* \param int, le nombre de digits à afficher, 1-8
*/
///////////////////////////////////////////////////////////////////////////////
void setDisplayDigitsCount(int digitCount)
{
if(digitCount>0 && digitCount<9)
{
output_low(MAX7221_CS);
delay_cycles(4);
spi_write(SCAN_LIMIT);
spi_write(digitCount-1);
output_high(MAX7221_CS);
}
}
///////////////////////////////////////////////////////////////////////////////
/*! \brief Envoi d'une valeur au digit considéré
* L'affichage dépendra du mode de décodage du digit considéré
*
* \param int, le digit (<8)
* int, la valeur à charger
*/
///////////////////////////////////////////////////////////////////////////////
void setDisplayDigit(int digit, int value)
{
if(digit<8)
{
output_low(MAX7221_CS);
delay_cycles(4);
spi_write(digit+1);
spi_write(value);
output_high(MAX7221_CS);
}
}
|
In your main you need to setup the spi, please read the datasheet of your pic and for the max7221..., you'll also have to define MAX7221_CS, which is the pin where the Chip Select of the MAX7221 is connected.
Then, to init the display (in my case a 4 digits display) call:
Code: |
// Digits 0-3 devront être décodés en BCD
setDisplayDecodeMode(BCD_DIG0to3);
// On sélectionne une intensité moyenne
setDisplayIntensity(8);
// On lui indique que seuls les digits 0-3 seront utilisés
setDisplayDigitsCount(4);
// On le met en mode standard
setDisplayTest(NORMAL_MODE);
// Et on l'allume
setDisplayOnOffState(TRUE);
|
And use setDisplayDigit(int digit, int value) to show 'value' on 'digit'... |
|
![](templates/subSilver/images/spacer.gif) |
sebdey
Joined: 11 Sep 2003 Posts: 17 Location: Switzerland
|
SPI setup... |
Posted: Sun Jan 15, 2006 11:46 am |
|
|
I can't give you the CCS command for setting the SPI, I'm directly writing to the pic registers, if someone in this forum can translate these values in CCS, please don't hesitate to do it...
Code: |
SSPSTAT=0b01000000;
SSPCON=0b00100000;
|
|
|
![](templates/subSilver/images/spacer.gif) |
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
|
Posted: Sun Jan 15, 2006 11:57 am |
|
|
I have a board with the MAX7219 with 8 7-segment displays.
can i replace the max7219 with te max7221?? |
|
![](templates/subSilver/images/spacer.gif) |
sebdey
Joined: 11 Sep 2003 Posts: 17 Location: Switzerland
|
|
Posted: Sun Jan 15, 2006 1:32 pm |
|
|
No, my fault, I didn't read the dadasheet carefully enough, the 7219 IS spi compatible... sorry
So you can just use the code provided as is!
Good luck !! |
|
![](templates/subSilver/images/spacer.gif) |
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
|
Posted: Sun Jan 15, 2006 2:25 pm |
|
|
sebdey wrote: | No, my fault, I didn't read the dadasheet carefully enough, the 7219 IS spi compatible... sorry
So you can just use the code provided as is!
Good luck !! |
No, 7221 is spi comp.
See here
The MAX7219/MAX7221 are compact, serial input/output common-cathode display drivers that interface microprocessors (µPs) to 7-segment numeric LED displays of up to 8 digits, bar-graph displays, or 64 individual LEDs. Included on-chip are a BCD code-B decoder, multiplex scan circuitry, segment and digit drivers, and an 8x8 static RAM that stores each digit. Only one external resistor is required to set the segment current for all LEDs. The MAX7221 is compatible with SPI™, QSPI™, and MICROWIRE™, and has slew-rate-limited segment drivers to reduce EMI.
A convenient 4-wire serial interface connects to all common µPs. Individual digits may be addressed and updated without rewriting the entire display. The MAX7219/MAX7221 also allow the user to select code-B decoding or no-decode for each digit.
The devices include a 150µA low-power shutdown mode, analog and digital brightness control, a scan-limit register that allows the user to display from 1 to 8 digits, and a test mode that forces all LEDs on.
For applications requiring 3V operation or segment blinking, refer to the MAX6951 data sheet |
|
![](templates/subSilver/images/spacer.gif) |
sebdey
Joined: 11 Sep 2003 Posts: 17 Location: Switzerland
|
|
Posted: Mon Jan 16, 2006 1:17 am |
|
|
Yes, the 7221 is the SPI compatible chip, but what I wanted to say is that the serial interface of the 7219 is also compatible with SPI, if you look on page 6, you'll see that the signals (Data, Clock, Load/_CS) are the same.
Quote: |
The MAX7219 and MAX7221 are identical except for
two parameters: the MAX7221 segment drivers are
slew-rate limited to reduce electromagnetic interference
(EMI), and its serial interface is fully SPI compatible.
|
For me, both devices are equal in terms of serial interface (by looking at the timing diagram of the signals...) |
|
![](templates/subSilver/images/spacer.gif) |
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
|
Posted: Mon Jan 16, 2006 12:34 pm |
|
|
I can't compile this code
Get 21 errors
Is this code for CCS-C??
UPDATE
Fault found (intensity double)
void setDisplayIntensity(int intensity)
{
if(intensity<16)
{
output_low(MAX7221_CS);
delay_cycles(4);
spi_write(INTENSITY);
spi_write(intensity);
output_high(MAX7221_CS);
}
}
I need a source code to count from 0 to 9999999
Please can someone help? |
|
![](templates/subSilver/images/spacer.gif) |
-sebdey Guest
|
|
Posted: Tue Jan 17, 2006 2:06 am |
|
|
Of course this is ccs code, and works very well for me...
But you need to create your main.c, make sure that all needed declarations are done, and maybe also understand the code and what you are doing...
It will need some personal work...
If you want to find someone that makes everything for you, I am not the right person, sorry... |
|
![](templates/subSilver/images/spacer.gif) |
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
|
Posted: Tue Jan 17, 2006 4:08 pm |
|
|
It working so far.
But it counts only to 65536. Why??? Is haved used long variables
Howcan i count further than 65536?
void writeDisplayValue(unsigned long value)
{
dig5 = (value%1000000)/100000;
setDisplayDigit(DIGIT_5,dig5);
dig4 = (value%100000)/10000;
setDisplayDigit(DIGIT_4,dig4);
dig3 = (value%10000)/1000;
setDisplayDigit(DIGIT_3,dig3);
dig2 = (value%1000)/100;
setDisplayDigit(DIGIT_2,dig2);
dig1 = (value%100)/10;
setDisplayDigit(DIGIT_1,dig1);
dig0 = (value%10);
setDisplayDigit(DIGIT_0,dig0);
}
void main()
{
unsigned long tel;
setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16);
setDisplayDecodeMode(BCD_ALL);
setDisplayIntensity(7);
setDisplayDigitsCount(6);
setDisplayTest(NORMAL_MODE);
setDisplayOnOffState(TRUE);
while (1)
{
writeDisplayValue(tel);
tel++;
delay_ms(5);
}
} |
|
![](templates/subSilver/images/spacer.gif) |
newguy
Joined: 24 Jun 2004 Posts: 1903
|
|
Posted: Tue Jan 17, 2006 4:23 pm |
|
|
This is why I never use words like "long" when I declare variables. A long int is 16 bits in CCS, thus the reason your counter tops out at 65,535.
Try an int32 instead. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Sat Nov 04, 2006 1:38 am |
|
|
Does this work on a 7219?
I've defined the CS pin, and output a test digit but with no go. The digit pins are all high, and the segments are all low =/
Code: | // Digits 0-3 devront être décodés en BCD
setDisplayDecodeMode(BCD_DIG0to3);
// On sélectionne une intensité moyenne
setDisplayIntensity(8);
// On lui indique que seuls les digits 0-3 seront utilisés
setDisplayDigitsCount(4);
// On le met en mode standard
setDisplayTest(NORMAL_MODE);
// Et on l'allume
setDisplayOnOffState(TRUE);
setDisplayDigit(0,1);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Sat Nov 04, 2006 1:49 am |
|
|
Oh sorry oops forgot to setup_spi (: ..now it responds but it still doesn't work. Segments doesn't go high |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Thu Jun 28, 2007 3:08 pm |
|
|
Good driver, but how do I turn on/off a segment DP without changing any other segments? For example the display already shows 123, and I want to turn on the decimal 12.3 |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Thu Jun 28, 2007 5:53 pm |
|
|
Whoops wrong one. I'm actually using the bit bang one, how do I turn on DP? I'm not fluent with this stuff, more with PHP (:
Quote: |
void display(char adresse,char wert)
{
char x;
output_low(LOAD);
for (x=0;x<4>0;x--)
{
if (bit_test(adresse,x-1)) output_high(DATA);
else output_low(DATA);
output_high(CLK);
delay_us(1);
output_low(CLK);
delay_us(1);
}
for (x=8;x>0;x--)
{
if (bit_test(wert,x-1)) output_high(DATA);
else output_low(DATA);
output_high(CLK);
delay_us(1);
output_low(CLK);
delay_us(1);
}
output_high(LOAD);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|