16 and 32 bit comnination

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

16 and 32 bit comnination

3,586件の閲覧回数
ernestsnaith
Contributor I
Hi
 
I have the timer running as well as secondary counter which increments on timer overflow. I am storing values of both at regualr intervals. Is there away of storing both 16 bit values as a long integer type to be used in expressions at a later time? Also is the reverse possible? accessing high and low parts of long int.
 
Cheers
ラベル(1)
0 件の賞賛
返信
5 返答(返信)

1,282件の閲覧回数
ernestsnaith
Contributor I
Thanks
0 件の賞賛
返信

1,282件の閲覧回数
bigmac
Specialist III
Hello,
 
A possible method is to form a union between a long and an integer array.  You can then manipulate the value of the individual words forming the long.
 
#define dword unsigned long
 
typedef union {
  word wordval[2];
  dword val;
} long_val;
 
long_val timer;
dword temp;
 
timer.wordval[0] = highreg;
timer.wordval[1] = lowreg;
 
temp = timer.val;  // 32-bit value
 
Regards,
Mac
 
0 件の賞賛
返信

1,282件の閲覧回数
Obetz
Contributor III
bigmac wrote:

typedef union {
  word wordval[2];
  dword val;
} long_val;
 
long_val timer;
dword temp;
 
timer.wordval[0] = highreg;
timer.wordval[1] = lowreg;



I'm missing the big red warning in your suggestion. How can you be sure about the order of high and low word?

Oliver
0 件の賞賛
返信

1,282件の閲覧回数
bigmac
Specialist III
Hello Oliver,
 
It is my understanding that the MC9S12XDT512 is big endian, and the code was presented with this in mind.  For a little endian case, the allocation of individual word values would obviously need to be reversed.
 
Since the problem presented was to specifically deal with hardware registers, "portability" does not seem to be an issue in this instance.
 
Regards,
Mac
 
0 件の賞賛
返信

1,282件の閲覧回数
ernestsnaith
Contributor I
...using
 
Codewarrior 4.5
MC9S12XDT512
0 件の賞賛
返信