Discussion in "Software" started by    Gaurav Sharma    Nov 19, 2009.
Thu Nov 19 2009, 10:42 pm
#1
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 ??
Fri Nov 20 2009, 01:52 am
#2
Which half? Upper or lower?
Fri Nov 20 2009, 01:54 am
#3
Both...
Fri Nov 20 2009, 02:02 am
#4
#define UpperHalf(X) (X>
>
4)
#define LowerHalf(X) (X&0x0F)

MyVar = UpperHalf( P2);

or

MyVar = LowerHalf(P2);


Fri Nov 20 2009, 02:09 am
#5
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 ?



[ Edited Fri Nov 20 2009, 02:09 am ]
Fri Nov 20 2009, 02:30 am
#6
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...

Fri Nov 20 2009, 09:53 am
#7
OK Anyways ...Thanks.
Fri Nov 20 2009, 05:19 pm
#8
Dave gave you macro for reading 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
#9
What is difference exactly b/w that macro and yours example....?

And in your example why 'y' is used ?
Fri Nov 20 2009, 10:16 pm
#10
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,

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am