Hi All
I write a function like this
test.c void a(U8 val) { U8 ch=0;
dev[ch].fun1(val); <--this is a function pointer , it will call the b function
dev[ch].fun2(val); <--Fail here }
void b( U8 val) { U8 dummy = val *5;
writeReg[0x55AA]= dummy; }
after run the " dev[ch].fun1(val)"
The ch varible will be change , so it will fail when run " dev[ch].fun2(val)"
I found the varible is in the same memory address, How can I avoid it??
and how can I know the memory map of all local varible ??
I found the m51 file , the data is map to 18h to 28h
DATA 0018H 0028H UNIT ?DT?TEST
why ch varible is map to 0x40 and same as dummy varible??
Thanks for you kindly help and sorry for my poor english
[ I found the varible is in the same memory address, How can I avoid it??]
Sorry , the correct is
[ I found the "ch" varible is in the same memory adddress as "dummy" varible,
So when "dummy" is change , the "ch" value also change", How can I avoid it??]
"I found the 'ch' varible is in the same memory adddress as 'dummy' varible"
This is perfectly normal & correct operation for the Keil C51 compiler.
This is called Overlaying - it is Keil's solution to the problem that the 8051 has virtually no stack to speak of.
Overlaying achieves at build-time what "normal" compilers achieve at run-time by using the stack.
That is to say, it is the solution that Keil uses - it is not exclusive to Keil, and they didn't invent it.
More on Overlaying here: http://www.keil.com/forum/19231/
Just spotted this:
void a( U8 val ) { U8 ch=0; dev[ch].fun1(val); <--this is a function pointer, it will call the b function dev[ch].fun2(val); <--Fail here }
The Overlaying means that you have to be very careful how you use function pointers in Keil C51 - if you use them at all.
You must read this: http://www.keil.com/appnotes/docs/apnt_129.asp - and follow its directions carefully!
Andrew Neil ,Thanks a lot
but I still don't know how to use the key word [overlay] correctly
I just use " ?PR?A?Test!* " in BL51 Misc to fix this
In my code , Do I need to write Overlay (?PR?A?TEST ~ ?PR?B?TEST )??
Thanks again for your kindly help
Then you're going to have to keep researching & studying documentation until you do!
There's a lot of other information - App Notes, knowledgebase articles, etc - I gave some links in the thread I mentioned earlier.
Alternatively, perhaps you should take a hint that this is not something for which the 8051 is well-suited - and either restructure your application in a way that's more appropriate to the target, or choose a different target that's more appropriate to this kind of thing...