Keil uVision
Thu Nov 19 2009, 10:42 pm
Hi
I have little query regarding programming in uVision Keil software. As In C programming we define port as
#define LED P2 (complete port)
I want to ask....How to define Half port in c ??
I have little query regarding programming in uVision Keil software. As In C programming we define port as
#define LED P2 (complete port)
I want to ask....How to define Half port in c ??
Fri Nov 20 2009, 02:02 am
#define UpperHalf(X) (X> > 4) #define LowerHalf(X) (X&0x0F) MyVar = UpperHalf( P2); or MyVar = LowerHalf(P2);
Fri Nov 20 2009, 02:09 am
See Daves, I'm not want to alter any of other bits like if I'm using the upper port the lower port should not be altered in any case as it is receiving its data from other device and vice verse.
So are you achieving it in this method of port definition ?
So are you achieving it in this method of port definition ?
[ Edited Fri Nov 20 2009, 02:09 am ]
Fri Nov 20 2009, 02:30 am
I don't understand the question...
These macros can be used to single out the upper most nibble and the lower most nibble of a typical port value when you read the port...
The port value isn't modified when you read from it.
This isn't a definition of a port, only a definition of what to do with the value that is read from the port...
I hope this better explains these two macros...
These macros can be used to single out the upper most nibble and the lower most nibble of a typical port value when you read the port...
The port value isn't modified when you read from it.
This isn't a definition of a port, only a definition of what to do with the value that is read from the port...
I hope this better explains these two macros...
Fri Nov 20 2009, 05:19 pm
Dave gave you macro for reading half port.
here is example for writing half port.
here is example for writing half port.
#define WrUpperHalf(x,y) (x & 0x0F | y) #define WrLowerHalf(x,y) (x & 0xF0 | y) //usage WrUpperHalf (P2, 5); WrLowerHalf (P2, 2);
Fri Nov 20 2009, 09:58 pm
What is difference exactly b/w that macro and yours example....?
And in your example why 'y' is used ?
And in your example why 'y' is used ?
Fri Nov 20 2009, 10:16 pm
Ah, I believe I see the problem here...
You are new to macros in C, right?
You can read about them here:
Macro definition and expansion
Hope this helps,
You are new to macros in C, right?
You can read about them here:
Macro definition and expansion
Hope this helps,
Powered by e107 Forum System