So, I am trying to put together two (rather involved) functions that calculate the DAC. My processing routine for CalcDAC1 and CalcDAC2 are more or less the same, but with different variables. Currently, I'm using global variables that are directly called from the routine. I would like to use the same functionality but send it the variables I want the program to use to process so instead of:
global variables: unsigned int var1a; unsigned int var2a; unsigned int var3a; unsigned int var1b; unsigned int var2b; unsigned int var3b; void main(void) { while(1) { CalcDAC1(); CalcDAC2(); } } void CalcDAC1(void) { //Do stuff with var1a //Do stuff with var2a //Do stuff with var3a } Void CalcDAC2(void) { //Do stuff with var1b //Do stuff with var2b //Do stuff with var3b }
I instead would like to do
void main(void) { while(1) { CalcDAC(var1a, var2a, var3a); CalcDAC(var1b, var2b, var3b); } } void CalcDAC(unsigned char var1, unsigned char var2, unsigned char var3) { //Do stuff with var1 //Do stuff with var2 //Do stuff with var3 }
Unfortunately, my particular function has about 7-10 variables (complicated equation with lots of variables) so it requires me to create a LOT of local variables for each iteration, which I don't have the local space for (if that's the right term). Instead, I would like to send it pointers to local variables (if possible).
I ASSUME it would look something like this:
void main(void) { while(1) { CalcDAC(*var1a, *var2a, *var3a); CalcDAC(*var1b, *var2b, *var3b); } } void CalcDAC(unsigned char *var1, unsigned char *var2, unsigned char *var3) { //Do stuff with var1 //Do stuff with var2 //Do stuff with var3 }
Is this correct or is this even possible in C? Is this something you can only do in C++? Any help with implementation you can give me would be greatly appreciated. Thanks!
my book doesnt have them in the index. it it is not a '51 book it will not. if it is a '51 book, look for "memory areas"
why dont you tell me what they are for sure, but there is not room to write 25000 words in a post. READ "THE BIBLE" (link in above post)
if you are one of those i eh people that believe "C is C" then drop all intents of working with micros.
Erik
what do you mean. i am using keil c. it understand normal c programs?
If the Keil C compiler have extra keywords - added specifically because the 8051 processor is a bit different from normal processors - that relates specifically to the 8051 processor, then you might be able to realize the need to figure out exactly what is different with the 8051.
A normal processor can't address individual bits. So the C language don't have "bit" as a data type. So what happens if a user wants their C program to take advantage of the specific bit commands in the 8051 processor?
A "normal" processor don't have multiple memory regions that all can have address 0 (zero) but that represents totally different data. So a "normal" C compiler don't need ways for the programmer to specify which memory region that should be accessed.
So - have you read up on the 8051 architecture yet? Because you will not be able to understand the extra 8051 keywords before you have understood the specials with the 8051 architecture.
And by the way - why are you still asking questions in this thread? This thread was about when to use the different regions. Your problem is to even understand that they exist. Why they exist. And why you need to know that they exist. First them, will it be possible to debate the advantages of making use of them in different ways - which this thread was about.
what do you mean. i am using keil c. it understand normal c programs? evidently you are.
The most amazing part is that, who should "drop all intents of working with micros", are good experienced developers of micros, here in my current company.
I had tried so many times, but had failed again and again, just to convince them that, different processors have different architectures. And of course, they believe there is only one assembly language on earth, which is the traditional PIC assembly.