i am trying to use code memory space to store some constants patterns. to do this, i have defined an array in code memory space as follows: unsigned char code A[]={0x00,0x3F,0x50,0x90,0x50,0x3F,0xAA}; it doesn't work at all or sometimes i get unpredicted results. but when i define the array in data memory and initialize the array as follows. can anyone help me? thanks A[1] = 0x00; A[2] = 0x3F; . A[6] = 0xAA
dear Andy Neil if you still read me, first of all, thanks for writing me back anyway, cause this problem is making me crazy, any way, i haven't tried it on simulator,instead i am trying this code directly on hardware each time i proramme it, the irony is that it works perfectly well when i initialize the array element by element,but it doesn't work when i try it the following way: A[] = {0x00,0x03F,0x050,0x090,0x050,0x03F}; or A[] = {0x00,0x03F,0x050,0x090,0x050,0x03F}; you have any suggestion?
The array defined with initializers is initialized by the runtime startup code, whereas the other way is by explicit assignment in your program. Are you including the runtime startup in your project? http://www.keil.com/support/man/docs/c51/c51_ap_startup.htm
"Are you including the runtime startup in your project?" It shouldn't be necessary to explicitly include it - if you don't explicitly include it, you should automatically get the default.
"i haven't tried it on simulator, instead i am trying this code directly on hardware each time i proramme it" And you say it's driving you crazy - so don't do it! Unless you have a chip with on-chip debug - in which case, use it! IF you can reproduce the problem in the simulator, it will be much easier to debug; if you can't, it most likely means that you have a hardware fault, misconfiguration, or your interfacing is bad. "you have any suggestion?" I'm still waiting for your response to my previous questions & suggestion: Have you looked in the map file & verified that the code constants are being placed in a sensible location? Are you getting any errors or warnings during the build? Post the smallest complete program that illustrates the problem.