For Assembly Language:
The bits in the CRGFLG register are "write 1 to clear". To clear specific bits you must use the instruction sequence:
Method 1:
LDAA bitmask
STAA CRGFLG
(Of course B could be used)
Or
Method 2:
BCLR CRGFLG, ~bitmask
Could be used.
You cannot use:
Wrong Method:
BSET CRGFLG, bitmask
On this register, because BSET is a "read-modify-write" instruction: all set bits will be cleared.
**************************************************************************************
For C Language:
Assuming CRGFLG is defined as
volatile unsigned char CRGFLG @ (0x37 + REG_BASE);
Then,
Method 1 – Flag Register:
CRGFLG = 0x80; /* clear RTIF */
Will translate to LDAA/B STAA/B and clear RTIF and nothing else.
To make this easier, define bitmasks for the register:
#define RTIF 0x80
#define PORF 0x40
Etc.
Then write,
CRGFLG = RTIF; /* clear RTIF */
Or
CRGFLG = RTIF + PORF; /* clear RTIF and PORF */
Method 2 – Flag Register:
To get the BCLR CRGFLG, $7F instruction, you need to use
CRGFLG &= 0x80; /* clear RTIF */
Or
CRGFLG &= RTIF; /* clear RTIF */
EMontanez wrote:This may be a stupid question, but isn't BCLR a read-modify-write instruction as well?Method 2:
BCLR CRGFLG, ~bitmask
Could be used.
You cannot use:
Wrong Method:
BSET CRGFLG, bitmask
On this register, because BSET is a "read-modify-write" instruction: all set bits will be cleared.
Message Edited by EMontanez on 02-20-2006 04:13 PM