hturluce
Joined: 12 Feb 2006 Posts: 2
|
Led Dot Matrix Moving Sign Problem |
Posted: Mon Feb 20, 2006 11:42 am |
|
|
Hello all,
I am a new member of this board, but follow posts since 2003.
I built an led moving message from a message I was following. It was:
http://www.ccsinfo.com/forum/viewtopic.php?t=21166&highlight=moving
The circuit was:
And here is the code:
Code: |
#include <18F452.H>
#include <STDLIB.H>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, RESTART_WDT, ERRORS)
#define PIN_ST_CP PIN_C2 // RCLK ----> Pin 12 ST_CP
#define PIN_SH_CP PIN_C3 // SRCLK ---> Pin 11 SH_CP
#define PIN_SER_IN PIN_C5 // SER -----> Pin 14
#define PIN_MRS PIN_C1 // PIN 10
#define PIN_OE PIN_C4 // PIN 13
#byte port_b = 0x0F81
#byte port_c = 0x0F82
#use fast_io(B)
#use fast_io(C)
long s1_char_size=41;
char s1[79];
long i;
void get_line1(void)
{
for(i=0; i<s1_char_size; i++)
{
if(kbhit())
{
s1[i]=getc();
delay_cycles(2);
printf("%C",s1[i]);
delay_us(1);
}
else
i -= 1;
}
}
char const msg_default[] = "Yet onother moving message led board 123";
char const ascii1[32][5] = {
{0,0,0,0,0} // 0
{0,0,95,0,0} // {0,95,0,0,0,0}
// 1
{0,7,0,7,0} // {0, 7,0,7,0,0}
// 2
{20,127,20,127,20} // 3
{36, 42, 127, 42, 18} // 4
{39, 21, 107, 84, 114} // 5
{54, 73, 86, 32, 80} // 6
{0, 11, 7,0,0} // {0, 11, 7,0,0,0}
// 7
{0, 28, 34, 65,0} // {0, 28, 34, 65,0,0}
// 8
{0, 65, 34, 28,0} // {0, 65, 34, 28,0,0}
// 9
{42, 28, 127, 28, 42} // 10
{8, 8, 62, 8, 8} // 11
{0, 88, 56, 0,0} // {0, 88, 56,0,0,0}
// 12
{8,8,8,8,8} // 13
{0, 96, 96, 0,0} // {0, 96, 96,0,0,0}
// 14
{32, 16, 8, 4, 2} // 15
{62, 81, 73, 69, 62} // 16
{0, 66, 127, 64,0} // {0,66, 127, 64,0,0}
// 17
{114, 73, 73, 73, 70} // 18
{34, 65, 73, 73, 54} // 19
{24, 20, 18, 127, 16} // 20
{39, 69, 69, 69, 57} // 21
{60, 74, 73, 73, 48} // 22
{1, 113, 9, 5, 3} // 23
{54, 73, 73, 73, 54} // 24
{6, 73, 73, 41, 30} // 25
{0, 54,54,0,0} // {0, 54, 54,0,0,0}
// 26
{0, 91, 59, 0,0} // {0, 91, 59,0,0,0} // 27
{8, 20, 34, 65,0} // 28
{20, 20, 20, 20, 20} // 29
{65, 34, 20, 8,0} // 30
{2, 1, 81, 9, 6} // 31
};
char const ascii2[32][5] = {
{50, 73, 121, 65, 62} // 0
{124, 18, 17, 18, 124} // 1 A
{65, 127, 73, 73, 54} // 2 B
{62, 65, 65, 65, 34} // 3 C
{65, 127, 65, 65, 62} // 4 D
{127, 73, 73, 65, 65 } // 5 E
{127, 9, 9, 1, 1} // 6
{62, 65, 73, 73, 58} // 7
{127, 8, 8, 8, 127} // 8
{0, 65, 127, 65, 0} // {0, 65, 127, 65,0,0}
// 9
{32, 64, 65, 63, 1} // 10
{127, 8, 20, 34, 65} // 11
{127, 64, 64, 64, 64} // 12
{127, 2, 12, 2, 127} // 13
{127, 2, 4, 8, 127} // 14
{62, 65, 65, 65, 62} // 15
{127, 9, 9, 9, 6} // 16
{62, 65, 81, 33, 94} // 17
{127, 9, 25, 41, 70} // 18
{38, 73, 73, 73, 50} // 19
{1,1,127, 1, 1} // 20
{63, 64, 64, 64, 63} // 21
{7, 24, 96, 24, 7} // 22
{127, 32, 24, 32, 127} // 23
{99, 20, 8, 20, 99} // 24
{3, 4, 120, 4, 3} // 25
{97, 81, 73, 69, 67} // 26
{0, 127, 65, 65,0} // {0, 127, 65, 65,0,0}
// 27
{2, 4, 8, 16, 32} // 28
{0, 65, 65, 127,0} // {0, 65, 65, 127,0,0}
// 29
{4, 2, 1, 2, 4} // 30
{64, 64, 64, 64, 64} // 31
};
char const ascii3[31][5] = { // 0 -- 30 == 31 elements
{0, 0, 7, 11,0} // {0, 7, 11,0,0,0}
// 0
{32, 84, 84, 84, 56} // 1
{127, 40, 68, 68, 56} // 2
{56, 68, 68, 68,0} // 3
{56, 68, 68, 40, 127} // 4
{56, 84, 84, 84, 24} // 5
{8, 126, 9, 9, 2} // 6
{8, 84, 84, 84, 60} // 7
{127, 8, 4, 4, 120} // 8
{0, 68, 125, 64,0} // {0, 68, 125, 64,0,0}
// 9
{32, 64, 68, 61,0} // 10
{127, 16, 40, 68,0} // 11
{0, 65, 127, 64, 0} // {0, 65, 127, 64,0,0}
// 12
{124, 4, 120, 4, 120} // 13
{124, 8, 4, 4, 120} // 14
{56, 68, 68, 68, 56} // 15
{124, 20, 20, 20, 8} // 16
{8, 20, 20, 20, 124} // 17
{124, 8, 4, 4, 8} // 18
{72, 84, 84, 84, 36} // 19
{4, 63, 68, 68,0} // 20
{60, 64, 64, 32, 124} // 21
{28, 32, 64, 32, 28} // 22
{60, 64, 48, 64, 60} // 23
{68, 40, 16, 40, 68} // 24
{12,80, 80, 80, 60} // 25
{68, 100, 84, 76, 68} // 26
{0, 8, 54, 65,0} // {0, 8, 54, 65,0,0}
// 27
{0,0,119,0,0} // {0, 119,0,0,0,0} // 28
{0, 65, 54, 8,0} // {0, 65, 54, 8,0,0}
// 29
{2,1,2,4,2} // 30
};
void main(void)
{
int char_index,i;
int col_index;
// int16 speed;
int x = 0;
long MSD, LSD;
int delaycount;
int16 startposition;
set_tris_b(0);
set_tris_c(0x40);
set_tris_d(0);
port_b = 0;
port_c = 0;
startposition = 0;
delaycount=0;
output_high(PIN_OE);
output_low(PIN_MRS);
for(i=0; i<79; i++)
s1[i] = 16;
for(i=0; i<sizeof(msg_default); i++)
s1[i] = msg_default[i];
delay_ms(100);
do
{
if(!input(PIN_E1)) //if RE1==LOW (pressed)
{
do
{
delay_cycles(2);
printf("\f\r\n");
printf("\f\r\n How many char.(0--99):");
MSD=getc();
delay_cycles(2);
printf("%C",MSD);
delay_us(1);
}while(!isamoung(MSD,"0123456789"));
do
{
LSD=getc();
delay_cycles(2);
printf("%C",LSD);
delay_us(1);
}while(!isamoung(LSD,"0123456789"));
s1_char_size = 10*(MSD-48) + (LSD-48);
delay_cycles(2);
printf("\r\n\n Enter the %lu char.: ",s1_char_size);
get_line1(); // acquire 16 char.
} // END of INPUT(PIN_E1)
delaycount=4;
while (delaycount)
{
col_index = startposition % 6;
char_index = startposition / 6;
if (char_index >= sizeof(s1))
{
startposition = 0;
char_index = 0;
col_index = 0;
}
x = s1[char_index];
output_high(PIN_MRS);
output_high(PIN_ST_CP);
output_high(PIN_SH_CP);
output_high(PIN_SER_IN);
output_low(PIN_SH_CP);
delay_us(1);
output_high(PIN_SH_CP);
output_low(PIN_SER_IN);
for (i=0;i<60;i++) // we've 80 columns to
{
port_b=0;
output_low(PIN_ST_CP);
delay_us(1);
output_high(PIN_ST_CP);
delay_us(1);
output_low(PIN_SH_CP);
delay_us(1);
output_high(PIN_SH_CP);
if (col_index == 5)
{
col_index = 0;
char_index++;
if (char_index >= sizeof(s1))
char_index = 0;
x = s1[char_index];
}
else
{
if ( x < 32)
port_b = 0;
else if( x < 64)
port_b = ascii1[x-32][col_index];
else if( x < 96 )
port_b = ascii2[x-64][col_index];
else if( x < 128)
port_b = ascii3[x-96][col_index];
col_index++;
}
output_low(PIN_OE);
delay_us(120);
output_High(PIN_OE);
}// END for-loop
delaycount--;
}
startposition++;
//
} while(1); //End of do-while
}// END main()
|
Test board working and scrolling left. Great, but there is an illusion when you watch the animation it looks like this:
if you look at the code you will find a line like;
Code: |
delaycount=4;
while (delaycount)
{
|
this means, whole screen will be scanned 4 times to slow down the scrolling effect. And this scan makes this illusion. If you scan the screen only one time there won't be any problem. But this will make the effect faster which I don't want.
After that I tried to add a big delay to the end of the code, like:
Code: |
delay_ms(50);
startposition++;
|
And not a suprise. Flickering.
I don't understand the problem. I tried couple of days and I gave up.
Please help me.
Regards. |
|