Hi, I want to use port 2 of 167 on MCB net board for two peripherals, one for keyboard interface and other for lcd interface. Please suggest some code on how to access the same port in parts. regards Rajesh
To the best of my knowledge there is no way to have a sort of separate variable for writing to a part of a port. Using bytewide write to a port clears the second byte, so it's useless (but using bytewide read from a port, on the other hand, could be quite useful). It seems to me that all that's left is macros and functions. By the way, maybe there is another way of writing to a port. You could create the following sequence of instructions somewhere in RAM: BFLDL reg(=P2), mask(=0xFF), data RET After that, you could fill the 'data' field of the BFLDL instruction and call that sequence to write to the lower byte of the port. Compared to this, the AND-OR approach has one disadvantage: the AND-OR sequence must not be interrupted by other port-accessing code because it would corrupt some of the data written to the port. Everything becomes simple if P2.0-P2.7 are configured as outputs and P2.8-P2.15 as inputs. In this case it's possible to use bytewide access: #define LCD MVAR(unsigned char, (unsigned char*)&P2) #define KBD MVAR(unsigned char, (unsigned char*)&P2 + 1) Sorry if I tried to complicate things. Good luck! Mike
Hi Mike Thanks for the suggestion. But it surely sounds complicated for a newbie like me. I will stick to the previous suggestion. It has definitely helped me. regards Rajesh