I'm writing a library to set a Port BIT , that can be used on ARTX for xc167 . I use a function with parameters "PortAddr" and "PortBit" :
*(PortAddr) |= ( 1<<PortBit );
and analog function for Clear the bit . This function is translated to (pseudo)Assembler :
MOV R4,PortState OR R4,bit MOV PortState,R4
When an interrupt access to the same port ( to set or clear a bit ) , and the interruption is before or after OR operation , I have an error because the the final value of the port is not correct .
I would like to use a solution that use the single instruction BSET and BCLR ( like compiled for direct set or clear ) , but I dont' find a good solution . The only one I find out is to insert a "switch ... case" , but it's not the better I think .
I hope someone have a good solution for me . Thank You