View previous topic :: View next topic |
Author |
Message |
josephazzam
Joined: 03 May 2013 Posts: 10 Location: Lebanon
|
how to exceed the 255 length limit of byte table |
Posted: Fri May 03, 2013 6:25 am |
|
|
Hi, I'm programming a pic,
and I have a table of byte: byte a[300];
but when I reach a[255] in a for loop
The table go back to a[0]
Any ideas ?
Thank You |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Fri May 03, 2013 6:36 am |
|
|
What is your chip number?
in Ram or on the local EEPROM? _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
josephazzam
Joined: 03 May 2013 Posts: 10 Location: Lebanon
|
|
Posted: Fri May 03, 2013 6:42 am |
|
|
I am using pi18f4520, but I do not see how's that relevant since the problem is in the code, it compiles but what happens that:
when I store values :
for(i=0;i<300;i++)
a[i]=i/2;
the result would be:
a[0] = 0 ;
a[1] = 1/2 ;
.....
then when it passes i=256
I get:
a[0] = 256/2 ;
a[1] = 257/2 ;
the byte table is limited to 256 bytes then is start over
Last edited by josephazzam on Fri May 03, 2013 6:43 am; edited 2 times in total |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri May 03, 2013 6:42 am |
|
|
Hi,
As a newbie to the CCS forum, you should be made aware of the forum guidelines: http://www.ccsinfo.com/forum/viewtopic.php?t=47549
If you answer all four of the bullet points in the first post in that thread then we can help you.
John |
|
|
josephazzam
Joined: 03 May 2013 Posts: 10 Location: Lebanon
|
|
Posted: Fri May 03, 2013 6:50 am |
|
|
version 4.114
microchip pic18f4520 |
|
|
josephazzam
Joined: 03 May 2013 Posts: 10 Location: Lebanon
|
|
Posted: Fri May 03, 2013 6:51 am |
|
|
void displaystring(byte *PORT, byte Alphabet[40][6])
{
char MyStr[90] = "PLEASE FEAL FREE TO INSERT YOUR FINGER - WE ARE NOT RESPONSIBLE FOR WHAT MIGHT HAPPENS - " ;
byte tab[540];
byte temp;
int i,j;
int16 a;
for(i=0 ; i < 89 ; i++)
{
if((MyStr[i]>='A') && (MyStr[i]<='Z' ))
for(j=0 ; j< 6 ; j++ )
tab[(i*6)+j] = Alphabet[ MyStr[i] -65 ][j] ;
else
if((MyStr[i]>='0') && (MyStr[i]<='9'))
for(j=0 ; j< 6 ; j++ )
tab[(i*6)+j] = Alphabet[ MyStr[i] -22 ][j] ;
else
if(MyStr[i]=='_')
for(j=0 ; j< 6 ; j++ )
tab[(i*6)+j] = Alphabet[ 37 ][j] ;
else
if(MyStr[i]=='.')
for(j=0 ; j< 6 ; j++ )
tab[(i*6)+j] = Alphabet[ 38 ][j] ;
else
if(MyStr[i]=='-')
for(j=0 ; j< 6 ; j++ )
tab[(i*6)+j] = Alphabet[ 39 ][j] ;
else
for(j=0 ; j< 6 ; j++ )
tab[(i*6)+j] = Alphabet[ 36 ][j] ;
}
} |
|
|
josephazzam
Joined: 03 May 2013 Posts: 10 Location: Lebanon
|
|
Posted: Fri May 03, 2013 6:52 am |
|
|
well this is the original example,
if I change the max value in the for loop from 89 to 42, the software works properly
but after 42, since 43*6 >256, I get problems |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri May 03, 2013 6:54 am |
|
|
Hi,
Please reread step #4 in the link I sent previously, and also use the 'Code' button when posting your Small, Compilable program that shows the problem........
John |
|
|
josephazzam
Joined: 03 May 2013 Posts: 10 Location: Lebanon
|
|
Posted: Fri May 03, 2013 6:55 am |
|
|
Code: |
for(i=0 ; i < 89 ; i++)
{
if((MyStr[i]>='A') && (MyStr[i]<='Z' ))
for(j=0 ; j< 6 ; j++ )
tab[(i*6)+j] = Alphabet[ MyStr[i] -65 ][j] ;
else
if((MyStr[i]>='0') && (MyStr[i]<='9'))
for(j=0 ; j< 6 ; j++ )
tab[(i*6)+j] = Alphabet[ MyStr[i] -22 ][j] ;
else
if(MyStr[i]=='_')
for(j=0 ; j< 6 ; j++ )
tab[(i*6)+j] = Alphabet[ 37 ][j] ;
else
if(MyStr[i]=='.')
for(j=0 ; j< 6 ; j++ )
tab[(i*6)+j] = Alphabet[ 38 ][j] ;
else
if(MyStr[i]=='-')
for(j=0 ; j< 6 ; j++ )
tab[(i*6)+j] = Alphabet[ 39 ][j] ;
else
for(j=0 ; j< 6 ; j++ )
tab[(i*6)+j] = Alphabet[ 36 ][j] ;
}
}
|
|
|
|
josephazzam
Joined: 03 May 2013 Posts: 10 Location: Lebanon
|
|
Posted: Fri May 03, 2013 6:57 am |
|
|
this is a small compilable function, just put it in a main.
if you want something more simple just see the example I've putter about (the a[i] = i/2) |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri May 03, 2013 6:58 am |
|
|
Hi,
Do you know what 'compilable' means? It means a piece of code that I can
simply cut and paste, and compile myself.
I'm beginning to see where the problem lies here. You aren't big on following instructions are you?
My guess is that some of your variable defines are wrong, but you aren't showing any of that! Not relevant, you say?
John
Last edited by ezflyr on Fri May 03, 2013 6:59 am; edited 1 time in total |
|
|
josephazzam
Joined: 03 May 2013 Posts: 10 Location: Lebanon
|
|
Posted: Fri May 03, 2013 6:59 am |
|
|
the problem is simple the after 256 it goes back to 0 :
a[0] a[1]...... a[255] a[0] a[1] instead of going to a[256] a[257] |
|
|
josephazzam
Joined: 03 May 2013 Posts: 10 Location: Lebanon
|
|
Posted: Fri May 03, 2013 7:00 am |
|
|
I can't give you a small code,
I need to give you the entire code because it's not independant, and the isis file too |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri May 03, 2013 7:02 am |
|
|
Hi,
If the problem is 'simple' (your words!), then it should be possible to write a small program to demonstrate the problem......
If you want to rigidly dictate how we must help you, then good luck solving your problem!
John |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Fri May 03, 2013 7:26 am |
|
|
Easy guys...
think about this:
how many bits in a byte?
what is the largest number you can hold with that many bits?
what happens if you increment the number of bits?
diferences between int and int16?
Max expected value? does that fit in an "int" or do you need an int16? or Larger?
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
|