Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

RE: [AVR-Chat] Reading and writing 16-bit registers

RE: [AVR-Chat] Reading and writing 16-bit registers

2005-07-18 by Larry Barello

Both constructs are equivalent.

One thing you *do* have to pay attention to:  Make sure your access is
non-interruptable as the temporary register used to hold the high byte can
be clobbered by an interrupt handler doing a word access (there is only one
temp register...)

I must admit that I don't pay attention to my own caveat...  I better go
change that!
Show quoted textHide quoted text
-----Original Message-----
From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com]On
Behalf Of Chuck Hackett
Sent: Sunday, July 17, 2005 6:43 PM
To: AVR-Chat@yahoogroups.com
Subject: [AVR-Chat] Reading and writing 16-bit registers


In looking at the instructions generated by WinAVR(gcc) I take it that:

	// Set timer counter to 0xC180 = 49,536
	TCNT1H = 0xC1;
	TCNT1L = 0x80;

	LDI     R24,0xC1         Load immediate
	OUT     0x2D,R24         Out to I/O location
	LDI     R18,0x80         Load immediate
	OUT     0x2C,R18         Out to I/O location

Generates the functionally identical (to my AVR inexperienced eye) code as
is
that generated by:

	TCNT1 = 0xC180;

	LDI     R24,0x80         Load immediate
	LDI     R25,0xC1         Load immediate
	OUT     0x2D,R25         Out to I/O location
	OUT     0x2C,R24         Out to I/O location

Do all/most AVR compilers do this correctly, i.e.: write the high byte
first?

I've noticed that I've seen the first form used more often than the second.
Assuming I stick with WinAVR, the second form seems clearer but is it bad
coding
style/practice?

If there's no style/practice problem with the second form, can I always use
it,
or are there 'gotchas' in some cases?  ... seems the world is filled with
'special cases' :-)

Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck






Yahoo! Groups Links

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.