2003-04-22 03:45 AM
2003-04-10 01:43 AM
Hello.
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? regards2003-04-10 03:30 AM
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.2003-04-10 04:01 AM
Thanks!
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?2003-04-22 02:58 AM
for example:
PAOR = 0x00; PADDR = 0x00; // floating input < .. your code.. > PAOR = 0xFF; PADDR = 0xFF; // push-pull output (optional)2003-04-22 03:45 AM
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