Hi , I have used BDATA for my 12 bit ADC program where all the 12 bits are collected at 0x20 by declearing volatile unsigned int bdata ADC _at_ 0x20 The information of the data accessed from the ADC is stored in the respective locations from the the absolute address. Now how can I access those two bytes from the specified location i.e., 0x20 and 0x21 in order to process the ADC data ? I have initilzed as, volatile unsigned char ReadADC1 _at_ 0x20; volatile unsigned char ReadADC2 _at_ 0x21; but I was getting DATA SPACE MEMORY OVERLAP warning!! Please suggest me how can I access two bytes from 0x20 and 0x21. MURALI
volatile unsigned int bdata ADC _at_ 0x20
volatile unsigned char ReadADC1 _at_ 0x20; volatile unsigned char ReadADC2 _at_ 0x21;
volatile unsigned int bdata ADC _at_ 0x20 volatile unsigned char ReadADC1 _at_ 0x20; but I was getting DATA SPACE MEMORY OVERLAP warning!! Of course you do, you define TWO variables in ONE slot. Erik
Now how can I access those two bytes from the specified location i.e., 0x20 and 0x21 in order to process the ADC data ? You might want to consult your favorite C textbook on what a union is, and then use one to achieve the desired effect.
Hi Erik,. Please suggest me solution to the problem . how can access the data from those two absolute locations??? If u have some solution plz reply back with some sample code Thanks, MURALI
Is the Union only solution to the problem??? or is there any other way we can access the data from the absolute location!!
Could you please send me a sample code how I can access data from union from absolute address , I need how It should be initilzed to access those variables??
Is the Union only solution to the problem??? No. or is there any other way we can access the data from the absolute location!! You could go the ugly, convoluted and confusing way and use absolute access macros.
If you want to use union, then go for
union uData { unsigned char MSB _at_ 0x20; unsigned char LSB _at_ 0x21; unsigned int uiValue _at_ 0x20; }; union uData val1; void main() { val1.LSB = 0xff; val1.MSB = 0x0f; while(1); }
unsigned char MSB _at_ 0x20; unsigned char LSB _at_ 0x21; unsigned int uiADC; void main() { MSB = 0x0f; LSB = 0xff; uiADC = (MSB*256) + LSB; }
Thanks a lot for the solution given , ADC is working fine with code