To put a specific number into a memory location or register (e.g.,
to put 0x55 into PORTA):
movb #$55,PORTA PORTA = 0x55;
To set a particular bit of a register (e.g., set Bit 3 of PORTA) while
leaving the other bits unchanged
do a bitwise OR of the register and a mask which has a 1 in the bit(s) you
want to set, and a 0 in the other bits:
bset PORTA,#$10 PORTA = PORTA | 0x10;
To clear a particular bit of a register (e.g., clear Bit 4 of PORTA)
while leaving the other bits unchanged
do a bitwise AND of the register and a mask which has a 0 in the bit(s) you
want to clear, and a 1 in the other bits. You can construct this mask by
complementing a mask which has a 1 in the bit(s) you want to set, and a 0 in
the other bits:
bclr PORTA,#$20 PORTA = PORTA & 0xDF;
PORTA = PORTA & ~0x20;
Write to all bits of a register when you know what all bits should be,
such as when you initialize it. Set or clear bits when you want to change
only one or a few bits and leave the others unchanged.
To clear a bit in a timer flag register (TFLG1 and TFLG2)
write a 1 to the bit(s) you want to clear and a zero to all other bits.
Do not do a bitwise OR of the register and a mask. To clear the Timer
Overflow flag (Bit 7 of TFLG2):