Docsity

Binary Coded Decimal (BCD) Conversion for Microcontrollers, Summaries of Microcontrollers

Partial preview of the text

Download Binary Coded Decimal (BCD) Conversion for Microcontrollers and more Summaries Microcontrollers in PDF only on Docsity!

EE 308: Microcontrollers

Binary Coded Decimal

Aly El-Osery

Electrical Engineering Department New Mexico Institute of Mining and Technology Socorro, New Mexico, USA

February 21, 2019

Introduction Conversion ASCII

What is BCD?

It is more natural for us to think in terms of decimal numbers with representation of

0 to 9.

Introduction Conversion ASCII

What is BCD?

It is more natural for us to think in terms of decimal numbers with representation of

0 to 9.

Digital systems represent numbers in binary.

How can we manipulated digital system to display numbers in our favorite format.

Introduction Conversion ASCII

What is BCD?

It is more natural for us to think in terms of decimal numbers with representation of

0 to 9.

Digital systems represent numbers in binary.

How can we manipulated digital system to display numbers in our favorite format.

Using Binary Coded Decimal (BCD)

Introduction Conversion ASCII

Binary to decimal

How we can break the number into its individual digit? (00-FF to 000-255)

Introduction Conversion ASCII

Binary to decimal using C

unsigned char x , tmp ;

tmp = x / 10; d1 = x % 10; //least significant digit d2 = tmp % 10; //middle digit d3 = x / 10; //most significant digit

Introduction Conversion ASCII

ASCII table

How can we display numbers (for exmaple using an LCD)

Introduction Conversion ASCII

Hex to ASCII using C

unsigned char x ; unsigned char hexnum = 0 x56 ; unsigned lsb_digit , msb_digit ;

x = hexnum & 0 x0F ; //grap the lower 4 −bits lsb_digit = x | 0 x30 ; //convert lsb to ascii

x = hexnum & 0 xF0 ; //grap the upper 4 −bits x = x > >4; //shift to lower 4 −bits msb_digit = x | 0 x30 ; //convert msb to ascii

Introduction Conversion ASCII