|
|
View previous topic :: View next topic |
Author |
Message |
KamPutty Guest
|
18f452, spi and 7219 [again!] |
Posted: Tue Dec 13, 2005 12:49 pm |
|
|
Hi all!
Sorry for another 7219 question! I've scanned this board, checked my code, wiring, and I still cannot make my anything display on my LEDs (8) other then the "test" (?) mode. All the digits are "8" and DP is active.
Here is my code, can anyone just double check for stupid mistakes?
Code: |
#include <18F452.h>
#device *=16
#device adc=10
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(stream=SERIAL, baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8)
#zero_ram
#case
#fill_rom 0xdead
#id checksum
#define MAX_DIN PIN_C5
#define MAX_CS PIN_C4
#define MAX_CLK PIN_C3
void update7219(int8 address, int8 data)
{
output_high(MAX_CS);
delay_us(1);
spi_write(address);
delay_us(1);
spi_write(data);
delay_us(1);
output_low(MAX_CS);
}
void init_7219()
{
setup_spi(SPI_MASTER |
SPI_L_TO_H |
SPI_XMIT_L_TO_H |
SPI_CLK_DIV_16);
// config 7219
update7219(0x0b, 0x07); // 8 total leds (0-7)
update7219(0x09, 0xff); // decode leds 0-7
update7219(0x0f, 0x01); // turn off test mode
update7219(0x0a, 0x07); // 50% intensity
update7219(0x0c, 0x01); // get into "normal" mode
}
void test_7219()
{
int x;
printf("LED test...\r\n");
init_7219();
// print numbers 0-7 on leds 0-7
for(x=0; x<8; x++)
{
update7219(x+1, x);
}
}
void main()
{
test_7219();
printf("Sleeping...\r\n");
#ignore_warnings 203
while(1);
#ignore_warnings none
}
|
Any thoughts?
~Kam (^8* |
|
|
kamputty Guest
|
commented out zero ram... |
Posted: Tue Dec 13, 2005 1:12 pm |
|
|
Hi all,
I just read a post and they mentioned that "zero ram" has caused strange issues with people, and I am using it...commented it out and still everything shows up.
~Kam (^8* |
|
|
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Tue Dec 13, 2005 1:43 pm |
|
|
Try it like this.
void update7219(int8 address, int8 data)
{
output_low(MAX_CS); // output_high(MAX_CS);
delay_us(1);
spi_write(address);
delay_us(1);
spi_write(data);
delay_us(1);
output_high(MAX_CS); // output_low(MAX_CS);
} _________________ David |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Tue Dec 13, 2005 2:39 pm |
|
|
CS must be low before clocking any Data In or Out as @drh well pointed.
But must stay high all other time, even after Power up.
output_high(MAX_CS);
Code: |
void init_7219()
{
update7219(0x0b, 0x07); // 8 total leds (0-7)
update7219(0x09, 0xff); // decode leds 0-7
update7219(0x0f, 0x01); // turn off test mode
update7219(0x0a, 0x07); // 50% intensity
update7219(0x0c, 0x01); // get into "normal" mode
}
|
Test this:
Code: |
void main()
{
...................
Ports configurations, etc
...................
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);
output_high(MAX_CS);
output_low(MAX_CLK);
init_7219();
address = 1;
data = 0;
while(1)
{
update7219(address, data);
delay_ms(600);
address++; data++;
if(address>=8) address=1;
if(data>=10) data=0;
}
}
|
Humberto |
|
|
KamPutty Guest
|
still not working... |
Posted: Tue Dec 13, 2005 3:43 pm |
|
|
Hi all,
Well, I tried swapping the "high" and "low" in the "update7219" method and it flashes random(?) digits and non digits (ie. not decoding), and changes intensity etc...
Here is the latest updated code...
any thoughts would be greatly appriciated!
Code: |
#include <18F452.h>
#device *=16
#device adc=10
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock = 4000000)
#use rs232(stream=SERIAL, baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8)
//#zero_ram
#case
#fill_rom 0xdead
#id checksum
#define MAX_DIN PIN_C5
#define MAX_CS PIN_C4
#define MAX_CLK PIN_C3
void update7219(int8 address, int8 data)
{
output_low(MAX_CS);
delay_us(1);
spi_write(address);
delay_us(1);
spi_write(data);
delay_us(1);
output_high(MAX_CS);
}
void init_7219()
{
// config 7219
update7219(0x09, 0xff); // decode 0-7
update7219(0x0b, 0x07); // 8 total leds (0-7)
update7219(0x0f, 0x00); // turn off test mode
update7219(0x0a, 0x07); // 50% intensity
update7219(0x0c, 0x01); // get into "normal" mode
}
void test_7219()
{
int x;
int8 address, data;
printf("LED test...\r\n");
setup_spi(SPI_MASTER |
SPI_L_TO_H |
// SPI_XMIT_L_TO_H |
SPI_CLK_DIV_16);
output_high(MAX_CS);
delay_us(1);
output_low(MAX_CLK);
delay_us(1);
init_7219();
address = 1;
data = 0;
while(1)
{
update7219(address, data);
delay_ms(500);
address++;
if(address>=8) address=1;
data++;
if(data>=10) data=0;
printf("Address [%d], Data[%d]\r\n", address, data); // using hyperterminal to "see" values
}
// // print numbers 0-7 on leds 0-7
// while(1)
// {
// for(x=0; x<8; x++)
// {
// update7219(x+1, x);
// printf("Address [%d], Data[%d]\r\n", x, x); // using hyperterminal to "see" values
// delay_ms(500);
// }
// }
}
void main()
{
test_7219();
printf("Sleeping...\r\n");
#ignore_warnings 203
while(1);
#ignore_warnings none
}
|
I'm going to recheck the wiring etc....
~Kam (^8* |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Tue Dec 13, 2005 5:11 pm |
|
|
It seems something wrong with the impossed time slot.
I used this display driver once and I wrote a function like update7219()
I didn't use the CCS SPI built in functions - do not remember why -.
This is the code:
Code: |
void update_display(char address, char data )
{
char x;
output_low(CS); //Change CS to Low before start toggling Clk
// Following clock-in '0000' for the unused D15-D12 bits.
for (x=4;x>0;x--)
{
output_low(Din);
output_high(Clk);
delay_cycles(2);
output_low(Clk);
}
// Clock-in the Register Address in bits D11-D8
for (x=4;x>0;x--)
{
if (bit_test(address,x-1))
output_high(Din);
else
output_low(Din);
output_high(Clk);
delay_cycles(2);
output_low(Clk);
}
// Clock-in data in bits D7-D0
for (x=8;x>0;x--)
{
if (bit_test(data,x-1))
output_high(Din);
else
output_low(Din);
output_high(Clk);
delay_cycles(2);
output_low(Clk);
}
output_high(CS); // Restore CS to it's high state to end.
}
|
Try with this code, it worked like a charm. Not tested now.
If you can get a scope to watch CS, Clk and Din would be a good help.
What Compiler version are you using ?
Humberto |
|
|
KamPutty Guest
|
sad sad me! |
Posted: Tue Dec 13, 2005 10:22 pm |
|
|
My compiler is 3.234 for all 3 versions.
Your code did not work. Same results.
Now, here is something interesting...
My test setup:
- PicDemo2 Plus as the programmer
- 7219 on breadboard wth LED's
- secondary PCB with max232, power etc. This is where the pic sits for standalone.
- I had added jumpers/wire from the PicDemo2 board, to the secondary pcb since it's a pain removing the pic and installing each time a compile is done
- PCB has a 9 volt power with a 7805 for my 5 volts
So now here is the strange part.
When the 7219 is powered from the PCB, all the lights come on etc and garbage is there, when the 7219 is powered from the PicDemo2 (I just added wire from one to the other), NOTHING appears! At a minimum, it should (?) act like the other setup. There is 5volts/ground
Said that, can I be having issues with power? Why work from one and not the other?
Again, picdemo connected to PCB connect to 7219 on breadboard. All my needed pins (c3,4,5) go from picdemo2 to pcb (using a Zif socket to easily connect the pins via a wire) then from the pcb to the breadboard. All connections checkout.
power....whats with the power?....
Again, thanks all for helping! AHHH!
~Kam (^8* |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Wed Dec 14, 2005 6:13 am |
|
|
Quote: |
Your code did not work. Same results.
|
KamPutty, for your info this is a working code. It is pretty simple and traceable and is still working since 3 years.
I guess you have a hardware problem. You are working with a breadboard plenty of jumpers and a mix of boards.
I can't help you by now.
Good luck,
Humberto |
|
|
KamPutty Guest
|
power? |
Posted: Wed Dec 14, 2005 10:02 am |
|
|
Humberto, et al.,
Not trying to bash your code or your input! Just that it did not work, and as it is working code, then the problem lies with my hardware setup...
I did find some interesting issues with the power, and I just don't know enough about it to really understand the issue.
Again, I thank you for your time and input.
I guess I'll rip the wiring apart and rebuild and see if the issue is there...
Can anyone make any guesses about the bizzarre power issues? Listed in the previous message.
~Kam (^8* |
|
|
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Wed Dec 14, 2005 12:22 pm |
|
|
Make sure you have added the bypass capacitors as suggested on page 10 of the 7219 data sheet. _________________ David |
|
|
|
|
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
|