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.

C Program to Convert Binary Number to Decimal PIC18F4520

Status
Not open for further replies.

qlouis76

Newbie level 4
Newbie level 4
Joined
Jun 1, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,291
Location
Malaysia
Visit site
Activity points
1,331
Hi,

Beginner here for C Programming.

Basically using MPlab to work on my C program.

Some problem, with input binary number using 4-sliding switch to PIC18F4520 (PortB. RB0 RB1 RB2 RB3). :-(

Am I suppose to write the program for each bit for each port to convert binary to decimal?

Need some help and suggestion.

Thank you :)
 

which compiler you are using?

Am I suppose to write the program for each bit for each port to convert binary to decimal?
No.

you can do something like this,

unsigned int number[8] = {0,1,2,3,4,5,6,7};

void DELAY_ACTUATE()
{
a = (input_b() & 0b11111111);
decimal_value = number[a];
}

Best wishes :)
 

which compiler you are using?


No.

you can do something like this,

unsigned int number[8] = {0,1,2,3,4,5,6,7};

void DELAY_ACTUATE()
{
a = (input_b() & 0b11111111);
decimal_value = number[a];
}

Best wishes :)


Thank you.

I am using C18 C compiler.

I am beginner. it is like this

void main ()
{
TRISBbit.TRISB4=1
unsigned int number[4] = {0,1,2,3,4}; //only 4 bit (1111) so maximum is 15 in decimal.

void DELAY_ACTUATE()
{
a = (input_b() & 0b1111);
decimal_value = number[a];
}

Correct me if I am wrong. Is C program will know example (1001 is 9 )?

I am sorry still learning.
 

If the 1001 is suffixed by 0b then it will indicate the compiler that the number following is a binary number.

void main ()
{
TRISBbit.TRISB4=1
unsigned int number[4] = {0,1,2,3,4}; //only 4 bit (1111) so maximum is 15 in decimal.

void DELAY_ACTUATE()
{
a = (input_b() & 0b1111);
decimal_value = number[a];
}

is this correct?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top