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 input to pic microconroller

Status
Not open for further replies.

pisces12

Junior Member level 2
Joined
Dec 2, 2009
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
malaysia
Activity points
1,436
hi...

how to convert binary input to pic microcontroller to decimal value..for example the input is 1100100 = 200..i'm using picc compiler..tq
 

Hi pisces12,

Tell us how you are giving the binary input, serial or parallel? If it is parallel, input the 8bits to a single port and read the port value to a variable. If you are not going to display the value, there is no need of conversion. Its a matter of how you visualize the content of the variable. You can think it as a binary or decimal or hexadecimal....
 

sorry, but can i ask. what do you mean by serial or parallel input?i don't need to display it, but i'm going t use the value in my calculation.
 

Hi pisces12,

If you are using it in calculations then you may use it without any modifications.

For example:

unsigned short int x; //x is an 8bit variable
.
.
.
x=PORTB;//read 8bit value from portb to x

now, if the 8bit value input on portb was = 1100100

then x= 1100100 binary == 100 decimal == 64 hexadecimal

Only the representation of value is changing in the above cases and the magnitude remains the same.
 

uhm..HI!
I happened to be thinking about the same thing.:-D
like,

How would I put into code an 8 bit binary as input and convert it to decimal?

so far, I am planning to experiment with switches. I assigned PORT B as input and I declared a variable of type byte where the value would be stored...and I used this code:


a = ( ( (PORTB and 0xF0) div 10) << 4) + (PORTB and 0x0F)

where a is of type byte
oh, I'm using MikroBasic.
I've seen this code on another topic, I just tried it out and see what happens.lol. Nothing much happened. I converted the byte to string to be able to see its output on the LCD..it produced : 25,23, -19 regardless if I switched on/off other switches on PortB.

any ideas how I can do this?
help would be very much appreciated.

Thank you!

Sincerely,
heina[/b]
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top