I want to set one bit of a port. However the other bits of this port should not affected. I use Cosmic C Compiler. for example: _asm(''bset 0x00,#5''); or (PADR) &= ~0x20; What is the right line to set the bit in portA? Or can I use both? The other bits of portA are not affected? regards
PADR |= 0x20; // set 5 bit (other bits are not affected)
PADR &= ~0x20; // reset 5 bit (other bits are not affected) PADR ^= 0x20; // invert 5 bit (other bits are not affected) _asm(''bset 0x00,#5''); - is equivalent of first line.
And if I want to read an input of a port, can I write the code in this way: if(PADR & 0x04) { mark = TRUE; } else { mark = FALSE; } I think it's right, isn't it?
I notice that in your example you set the port option register first, doing this could trigger an unwanted interrupt.
When setting follow the order PxDDR then PxOR, when resetting a port use PxOR then PxDDR. If you have a mixed port with both inputs/outputs then to be safe you need to use a port shadow register. Regards SJO