0% found this document useful (0 votes)
1 views

BCD Program

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

BCD Program

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

“Through BCD” convertor, convert a 1-byte binary number into a 3-byte BCD number in

C language for 8052 Microcontroller

#include <8051.h> // Include header for 8052 microcontroller

Void binaryToBCD(unsigned char binary, unsigned char *bcd) {

Bcd[0] = binary / 100; // Hundreds place

Bcd[1] = (binary / 10) % 10; // Tens place

Bcd[2] = binary % 10; // Units place

Void main() {

Unsigned char binary = 0x7B; // Example binary input (123 in decimal)

Unsigned char bcd[3]; // Array to store BCD result

binaryToBCD(binary, bcd);

// Output the BCD result to ports for verification (e.g., debugging)

P1 = bcd[0]; // Hundreds place

P2 = bcd[1]; // Tens place

P3 = bcd[2]; // Units place

While (1); // Infinite loop to hold results

You might also like