View previous topic :: View next topic |
Author |
Message |
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
Subroutine to display a counter on max7221 |
Posted: Mon Jan 16, 2006 3:54 pm |
|
|
I need a subroutine in CCS-C for driving a MAX7221.
The standard initialize routines works already thanks sebdey
This subroutine must past a value ( from 0 to 9999999) and display this on a 8 digit seven segment display
Can someone help me how to built this? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 16, 2006 4:29 pm |
|
|
It seems like you gave up on the other code in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=25672
You need to learn how to read error messages from the compiler
and fix syntax errors or other coding problems.
To fix that code, you just need to add these two lines at the top:
Code: | #case
#define MAX7221_CS PIN_C0 |
The reason for using #case is because he has defined the word
"intensity" in two places, and the compiler doesn't like that.
Code: | #define INTENSITY 0x0A
void setDisplayIntensity(int intensity) |
So it's obvious to me that he must be using the #case directive
to prevent compiler errors.
The chip select (MAX7221_CS) obviously must be defined as some
PIC i/o pin. He didn't provide a definition, so you must choose a pin,
and then put it into a #define statement, as shown above. I just
chose Pin C0 because it seemed convenient. |
|
|
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
|
Posted: Mon Jan 16, 2006 4:38 pm |
|
|
I have this code working,
but i need a subroutine thats counts ket we say from 1 to 999999
and past that value to a subroutine to drive the MAX7221
How can i send this value to this routine
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);
}
}
There must an translation to drive digit 1 with the correct value, digit 2 with the correct value and so on
How to realize that? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 16, 2006 5:07 pm |
|
|
Look at the SplitDigit() function in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=24866
It will extract the digits and put them in an array.
Then you can use a for() loop to index into the array
and get each digit and send it to the MAX7221 with
the setDisplayDigit(int digit, int value) function. |
|
|
|