Hi I have the following array declared at the start of my program as global: int number[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98}; 0 1 2 3 4 5 6 7 8 9 It is for a 7 segment display to display the numbers that I need, the array is from 0-9 in that order. My code to call the array is: P2 = number[4]; so in this case it should get the 4th number being 0x99 This works fine if i replace the 4 with 0,1 or 2 but anything greater than 2 all it does is return the data for 8 (80) If anyone can work out why this is doing this please let me know Thanks
May be a problem with the RAM in your target hardware. You should define it in ROM using the code memory type. Change definition to:
unsigned char code number[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98};
while Reinhard did correct it, he did not mention your basic mistake in using int. While that supposedly would not make a difference, using int in lieu of char when char will do is an ugly PC habit that has no business in the uC world. Now, since you could not be bothered to select a toolset, I may be wrong since it could be that you referred to amemory rich chip in which case the above would be less important. Erik
erik Thanks for the little explination and reinhard thanks for the advice I didnt understand what you were saying about the memory stuff is there a link to that manual? If I just change the definition to what you suggested should it work?
Im using an 89LPC935.
"If I just change the definition to what you suggested should it work?" What you wrote originally should have worked, it just wasn't the most efficient use of resources on an 8051. If using Reinhard's code works you still have a problem you need to understand and fix. If you declare an array without specifying a memory space it will be created in the default memory space which will be either internal or external RAM. This is pointless as your array is read-only. Using the 'code' specifier causes the array to remain in code space. The other issue that was pointed out to you is the fact that you are storing 8 bit values in an array of 16 bit 'slots'. This is also wasteful. Reinhard is suggesting that you may have a hardware problem with the RAM which is causing your original declaration not to work properly. There are other possibilities though - what memory model are you using?
Hi my array is working correctly if it is declared as an integer in my program, however if I change it as suggested to unsigned char code then what happens is it only diplays for a very quick period of time <1 second then no longer displays. I have tried it in a simple program and it works fine however in my larger program this does not work. Can you suggest why this might be happening? Also I'm trying to display a 2 digit number 1 digit at a time so I'm using the following code: P2 = number[set_temp/10]; //Display Tens and P2 = number[set_temp%10]; //Display Units This also doesnt work properly, this time it wont work while trying to access the integer "set_temp" which is defined as: int set_temp = 27; however if I take out "set_temp" from the code above and replace it with 27 it works fine. This also works fine in the simple program however not in my larger program. If you would like to see my whole program code to work this out please email me on alex@allsound.com.au Thanks
What memory model are you using?
I'm not sure how do I tell?
It is a P89LPC935 PLCC version the numbers on the chip are: 89LPC935FA CD4397 TtG0440 A Alex
View all questions in Keil forum