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.

How to read P2 and convert the value to a float number? (AT89c51RC2)

Status
Not open for further replies.

fatihbasaris

Newbie level 4
Joined
Oct 1, 2004
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
90
I am using AT89c51RC2. I want to read P2 and convert to a float number and
write this number to the LCD...
 

Re: float????

If you are using a C compiler, the function sprinf can convert a float to ASCII.
 

Re: float????

thanks for reply. ı am using keil. ı wrote this codes.:(
For example received=174

.
.
.
.
void DATAdatawrite(char data[])
{
int i=0;
while(data!=0)
{
RS=1;lcddelay(1);
RW=0;lcddelay(1);
EN=1;lcddelay(1);
DATA=data;
EN=0;lcddelay(1);
i++;

}
}
.
.
.
.
void main()

unsigned int received,lasttwo,number1,number2,number3;


while(1)
{
received=P1;

lasttwo=received%100;
number1=lasttwo%10;
number2=(lasttwo-number1)/10;
number3=(received-lasttwo)/100;

LCDinit();

LCDdatawrite(????)

For example received=174

I want to write to lcd 174 but ı did not do this.
 

Re: float????

float? I don't see any floats in your code. Only unsigned int.

When I run your statements in the following program, it prints 1 7 4
Code:
#include <stdio.h>

int main(void)
{
  unsigned int received,lasttwo,number1,number2,number3;

  received = 174;
  lasttwo = received % 100;
  number1 = lasttwo % 10;
  number2 = (lasttwo - number1) / 10;
  number3 = (received - lasttwo) / 100;

  printf("%u %u %u\n", number3, number2, number1);
  return 0;
}

Maybe you forgot to convert your three numbers to ASCII characters before sending them to your LCD?

You could convert the unsigned int to a string, and then use that:
Code:
#include <stdio.h>

int main(void)
{
  unsigned int received = 174;
  char buf[100];

  sprintf(buf, "%u", received);
  puts(buf);
  return 0;
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top