[Icc-avr] Reading fuses on Mega168
Tim Mitchell
tim at sabretechnology.co.uk
Tue Apr 29 08:31:45 PDT 2008
> Still the same problem, the first example uses ldi instructions to
> load
> R16/17 with 87
> whereas the second example uses in instruction to load 0x37 into R16
> and clrs R17.
>
> The actual definition of SPMSCR is
>
> #define SPMCSR (*(volatile unsigned char *)0x57)
>
> which for some strange reason the compiler translates to 0x37.
>
SPMCSR is not a constant, it is effectively a variable reading the
special function register.
So your "readfusesbyte(SPMCSR,0x0003)" will use the contents of the
SPMCSR register, not the number 0x57, hence the "in R16,0x37"
The reason it's 0x37 not 0x57 is because you can access most of the
special function registers as I/O (using in/out opcodes) or as SRAM
(using lds/sts opcodes), but the i/o address is not the same as the sram
address - normally 0x20 lower. The compiler obviously knows this
somehow, "lds R16,0x57" would give the same result.
If you look in the datasheet register summary the IO address is shown
without brackets and the sram address is shown with brackets.
--
Tim Mitchell
tim at sabretechnology.co.uk http://www.sabretechnology.co.uk
Sabre Technology (Hull) Ltd, 3a Newlands Science Park, Hull HU6 7TQ
Registered in England and Wales no.3131504
t:01482 801003 f:01482 801078
More information about the Icc-avr
mailing list