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.

4 bit binary to ascii in c

Status
Not open for further replies.

ronydc

Full Member level 3
Joined
Nov 17, 2005
Messages
166
Helped
4
Reputation
8
Reaction score
3
Trophy points
1,298
Activity points
2,612
Dear Friends,

In a project I am getting 4 bits at port P2 ( bits d0 to d3) when i am Receiving any alphabate ( I mask the other bits , d4 to d7) from a system.
then when I try to display it on the lcd, i dont get the original alphabet on the lcd but I get the digit instead of that.
ex. -- if I Send the letter "k" on port as said above, I get the "11" display on the lcd ---- but not leter -- "k" ..

why this is happening.. do i need to do some ascii conversion ..?

( all the numbers are comming corectly on lcd from 0 to 9-- but not only the alphabets)

is the only 4 bits( d0 to d7 ) not capable to make an alphabet..? - -mean leck of data or something .?
i m stuck.
( i m using "c" and this is 8051 programming)
(my lcd code is ok.)


please advise, freinds.
- Rony
 

The LCD is using ascii character with is 7bit, so you need to change to ascii hex first for example you want to send 'A' so the uc need to send hex 0x41 to the LCD then the 'A' will display on screen
 

thanks,
i will investigate more on the way you shown.

but its still strange that when i give %s to represent the incoming data as string , why it shows 11 for alphabet "k" . letters 1 to 9 are represented ok only when i give %d

so it seems it only responding to digits and not to the alphabets.

my lcd side programming is

data = P2 & 0x0f; // get data from p2 and store
//in data variable
// mask the bits d4 to d7 as same
// data is coming as input

line(1); // lcd formalities
clearscreen(); // lcd formalities
sprintf(buf, "%S" , data) //store data in a buf[20]
// as string
string ( buf) // print tht buf to lcd
===========================

still confused with this behaviour of lcd.
can soime one find out whts going wrong .?

Please Advise.
-Rony
 

sprintf(buf, "%S" , data) //store data in a buf[20]

Try "%x" for hex conversion.
 

friend i need either a single alphabet or a string.. to be desplayed on lcd
 

'data' can not hold string?
If you want a single char, use "%c"
If you want hex, use "%x"
Look up printf format.
 

yes you are correct.

but as i said in my first post..even, that even after using %s i dont se the alphabets on the screen.. i just see the figure -- 11 on lcd when i send alphabet -- k .
i msurprised and thts my problem actually

my code is,

data = p2 & 0x0f; // get data fomr port p2
// make lcd ready now
sprintf ( buf, "%s" data) // take data in a buf[10]
print_string( buf) /// print on lcd

the above code results in the result i said

-- rony
 

Have you tried

buf[0] = 'k';
buf[1] = '\0';
print_string( buf); //Print to lcd
 

your code is in C- so for sending a character you need to used this format 'A' or 'c' but if you have a string "ABCDFFG", lat say you have store the strings in array buffer used for loop for sending 1 char at time. exe

unsigned char buffer[10];

//fill the buffer
buffer[0] = 'a';
buffer[1] = 'b';
buffer[3] = 'b';
buffer[4] = 'b';

for(i=0;i<10;i++)
{
PORTB = buffer;
}

...this code not include the LCD control cmd.... you need to add for it working
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top