Packed BCD to ASCII
What to do??
Say number be 28
First separate 2 to get 02.
Second separate 8 to get 08.
Now add 30 to both to get 32 and 38 respectively.
Hence these are our ascii values.
#include<reg51.h>
void main()
{
unsigned
char x,y,z;
unsigned
char bytemy = 0x28;
x
= mybyte & 0x0F; //mask
lower 4 bits
P1
= x | 0x30; //make
it ascii
y
= mybyte & 0xF0; //mask
upper 4 bits
y
= y >> 4; //shift
it to lower 4 bits
P2
= y | 0x30; //make
it ascii
}// end of main
end of program
|
ASCII to Packed BCD.
What to do??
Say we have 2 ascii numbers 02 and 08.
We need to get say 28.
So shift 02 to 20.
Add 08 to it.
Hence this is our packed BCD.
#include<reg51.h>
void main()
{
unsigned
char myBCD;
unsigned
char x = '2',y='8';
x
= x & 0x0F; //mask lower 4
bits just in case.
x
= x << 4; //shift 4
left to make it upper digit
y
= y & 0x0F; //just in case
myBCD
= x | y; //combine to make BCD
P1
= myBCD;
}// end of main
// end of program
|
Interesting Blog
ReplyDeletehttp://www.dataentryhelp.com
Thanks
Manoj Singh