• Bitwise and logic operations are useful. Not only they are fast, they just deal with the
designated bits only. SPL has support for such operations but it is still better to know them.
Here are some common operations:
#define bit_set(reg, bit_val) reg |= (1 << bit_val) //For setting a bit of a register
#define bit_clr(reg, bit_val) reg &= (~(1 << bit_val)) //For clearing a bit of a register
#define bit_tgl(reg, bit_val) reg ^= (1 << bit_val) //For toggling a bit of a register
#define get_bit(reg, bit_val) (reg & (1 << bit_val)) //For extracting the bit state of a register
#define get_reg(reg, msk) (reg & msk) //For extracting the states of masked bits of a register
Unlocking a Locked STM8 Chip
If you have accidentally locked a STM8 chip by setting the Readout Protection configuration bit and
no longer able to use it, you can unlock it easily.
When you lock a chip, the programmer interface will give you a warning notification. If you retry to
reprogram/erase a locked chip you’ll get an error like this:
No matter what you do, you won’t be able to use it.