Appen
define sbi(
dix 3: Debugging Tale
ubstitution yields:
sfr, bit) ( (*(volatile uint8_t *)( ((uint16_t) &(sfr)) )) |= _BV(bit))
t *)(((
impleme
n that m
ed reg
dress
mory
ed v
ed ea
bi:
high
RTB
RTB
RTB
S
And _BV is? In pgmspace.h it is:
#define _BV(bit) (1 << (bit))
More substitiuton yields:
#define sbi(sfr, bit) ((*(volatile uint8_ uint16_t) &(sfr)) )) |= (1 << (bit)))
ntation specific type qualifier that
ight, in our case, screw things up if
ters. W
By the by, what’s a volatile? It is an
tells a complier to suppress optimizatio
we are using pointers to memory mapp is e don’t want the compiler to
help us by using some other memory ad
e
since a register is hardwired into the
machine and though addressed like m , isn’t ordinary memory. Volatile also
tells the compiler that that the so modifi ariable can change unexpectedly (like
by an interrupt) so it needs to be check
s
ch time it is used and not just stored
omewhere like on the stack.
More substitution for an actual use of s
sbi(PORTB, 5); // set OC1A
yields:
(((volatile uint8_t )(((uint16_t) &(PO )) )) |= (1 << (5)))
But the complier doesn’t know what PO is. What is it?
From io169.h
#define PORTB _SFR_IO8(0x05)/ PO /
and _SFR_IO8 id defined in sfrdefs.h: