int hundreds, tens, ones;
unsigned char buffer[16];
ones = adc_data%10;
adc_data = adc_data/10;
tens = adc_data%10;
hundreds = adc_data/10;
//Now convert this into ASCII by ORing it with 0x30
ones = ones | 0x30;
tens = tens | 0x30;
hundreds = hundreds | 0x30;
#include<stdio.h>
//create a string variable
unsigned char buffer[16];
sprintf(buffer,"%d",temp);
//This will convert the temp value to ASCII and these values are stored in buffer..
//don't forget to inculde stdio.h header file.
i am trying to convert the binary data form adc 0804 to asci value to display
#include <REGX51.H>
#include<stdio.h>
#include<string.h>
sbit INTR = P3^5;
sbit RD_ADC = P2^4;
sbit WR_ADC = P2^3;
sfr MYDATA = 0x80; //Port-0
sfr LcdData = 0x90; //Port-1
sbit RS = P2^5;
sbit RW = P2^6;
sbit EN = P2^7;
void lcdcmd(unsigned char value);
void lcddata(unsigned char value);
void lcdstr(unsigned char msg[]);
void Delay(unsigned int itime);
void SerTX(unsigned char x);
void SerTX_str(unsigned char msg[]);
unsigned char msg[] = "VOLTAGE --->";
void main()
{
unsigned int temp;
int hundreds,tens,ones;
unsigned char buffer[10];
TMOD = 0x20; //Timer-1, 8-Bit Auto Reload Mode
TH1 = 0xFD; //9600 Baud Rate When Crystal Used is 11.0592MHZ
SCON = 0x50;
TR1 = 1; //Start Timer
MYDATA = 0xFF; //Making P1 as Input Port
INTR = 1;
RD_ADC = 1; //Set RD high
WR_ADC = 1; //Set WR high
lcdcmd(0x38);
Delay(1);
lcdcmd(0x0E);
Delay(1);
lcdcmd(0x01);
Delay(1);
lcdcmd(0x80);
lcdstr("VOLTAGE");
lcdcmd(0x0C);
while(1)
{
lcdcmd(0xC0);
WR_ADC = 0; //Send WR Pulse
Delay(1);
WR_ADC = 1; //Low-High Pulse means Start of Conversion
while(INTR == 1); //Wait until End of Conversion
//When Conversion Gets Completed the INTR Pin Goes Low we get out of the Loop
RD_ADC = 0; //Send RD Pulse
temp = MYDATA * 2;
//Conversion Process Starts Here
ones = temp%10;
temp = temp/10;
tens = temp%10;
hundreds = temp/10;
sprintf(buffer,"%d.%d%d Volts",hundreds,tens,ones);
lcdstr(buffer);
SerTX_str(msg);
SerTX_str(buffer);
SerTX(13);
SerTX(13);
Delay(10);
Delay(10);
RD_ADC = 1;
}
}
void lcdcmd(unsigned char value)
{
LcdData = value;
RS = 0;
RW = 0;
EN = 1;
Delay(1);
EN = 0;
}
void lcddata(unsigned char value)
{
LcdData = value;
RS = 1;
RW = 0;
EN = 1;
Delay(1);
EN = 0;
}
void Delay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<1275;i++)
for(j=0;j<itime;j++);
}
void lcdstr(unsigned char msg[])
{
unsigned short int len,i;
len = strlen(msg);
for(i=0;i<len;i++)
{
lcddata(msg[i]);
Delay(1);
}
}
void SerTX(unsigned char x)
{
SBUF = x;
while(TI == 0);
TI = 0;
}
void SerTX_str(unsigned char msg[])
{
unsigned short len,i;
len = strlen(msg);
for(i=0;i<len;i++)
{
SerTX(msg[i]);
}
}
temp = from adc
a[0] = temp/100;
temp = temp%100;
a[1] = temp/10;
a[2] = temp%10;
for(i=0;i<3; i++)
{
bcdNum = a;
t = 0x30 + BCDToDecimal(bcdNum);
writedat(t);
}
uint8 BCDToDecimal (uint8 bcdByte)
{
return (((bcdByte & 0xF0) >> 4) * 10) + (bcdByte & 0x0F);
}
here only displaying corresponding decimal value only not ascii please help me
a[0] = temp/100;
temp = temp%100;
a[1] = temp/10;
a[2] = temp%10;
for(i=0;i<3; i++)
{
t = 0x30 | a[i]; //it is better than addition (+)
writedat(t);
}
a[0] = 161/100 = 1
a[1] = 161%100 = 61 , then 61/10 = 6
a[2] = 61%10 = 1
so
a[0]=0x01
a[1]=0x06
a[2]=0x01
if you add 0x30 to these values then
a[0] | 0x30 =0x31 this is ascii character "1"
a[1] | 0x30 =0x36 this is ascii character "6"
a[2] | 0x30 =0x31 this is ascii character "1"
thannara123 said:P2 = 0xff; // from adc 11111111
bcdNum = P2;
temp = BCDToDecimal(bcdNum);
a[0] = temp / 100;
P2 = 0xff; // from adc 11111111
temp = P2;
a[0] = temp / 100;
//.......................The rest of the code stays unchanged
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?