Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

binary constant in Keil C51

Status
Not open for further replies.

garg29

Advanced Member level 1
Joined
Nov 17, 2004
Messages
443
Helped
25
Reputation
50
Reaction score
10
Trophy points
1,298
Activity points
3,593
keil binary

Hello ,

I'm doing programming in C51. i'm trying to issue some binary value to P1 (Port 1) of 89c51. I'm not able to issue a binary value. Hex and decimal i know, but how do i issue a binary value. I've tried P1=0b00001111, P1=00001111Y (as given in help file), but non of them works. Please help me out.

Thanks a lot.

Garg
 

keil c binary value syntax

I know nothing at all about C51.....but

wouldn't P1 be a pointer?

making the assignment *P1=0b00001111
 

longtobin

Hi.

Did u try it use the hex one? or maybe the decimal one ?
Is it work in your opinion ?

If it is work, I think P1 = 0b00001111 is true to give the port a new value.
Make sure u try with hex first and compare it with the binary one....

Thanks...
 

macro for binary constants

xave1200 i think you didn't read my problem carefully. I've mentioned there i know how to put on hex it would had been P1=0x0F; but what in case if i want to mention in binary form.
 

binary + keil

So that u can use P1 = 0b0001111.
That's I usually use if I want to play with binay constant.
 

keil c binary code

Dear Garg,
I've tried P1=0b00001111, P1=00001111Y (as given in help file)

The Y option will work in entering EXPRESSION for DEBUGGER only. That option is evaluated by uVision3 (not by c51 compiler). Keil is not specifying any method to use binary constants in applications.

Here are two popular methods you can use.

First Method:

You can write a macro. Look at the following code which defines a macro and uses it:

#define BIN_TO_BYTE(b7,b6,b5,b4,b3,b2,b1,b0) ((b7 << 7)+(b6 << 6)+(b5 << 5)+(b4 << 4)+(b3 << 3)+(b2 << 2)+(b1 << 1)+b0)

void main(void)
{
volatile unsigned char x;

x = BIN_TO_BYTE(1,1,1,1,1,0,0,0);
}

The code generated for the assignment is simply:

MOV x,#0F8H

The compiler evaluates the constant value at compile-time and inserts it into the assembler as a constant. Note that the value will be evaluated at run-time if variables are used in place of 1s or 0s. This may generate a lot of code.

A similar method may be used for unsigned ints and longs.

Second Method:

#define LongToBin(n) \
(\
((n >> 21 ) & 0x80) | \
((n >> 18 ) & 0x40) | \
((n >> 15 ) & 0x20) | \
((n >> 12 ) & 0x10) | \
((n >> 9 ) & 0x08) | \
((n >> 6 ) & 0x04) | \
((n >> 3 ) & 0x02) | \
((n ) & 0x01) \
)

#define Bin(n) LongToBin(0x##n##l)

Then when you write Bin(00010001), you will get a 0x11.


I got these info from Keil forum. Search that for more details.

Thanking you.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top