vinodstanur
Advanced Member level 3
- Joined
- Oct 31, 2009
- Messages
- 751
- Helped
- 114
- Reputation
- 234
- Reaction score
- 114
- Trophy points
- 1,333
- Location
- Kerala (INDIA)
- Activity points
- 7,054
extern char * itoa(char * buf, int val, int base);
itoa (buffer,i,10);
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 // convert Temp to characters if (tempinC/10000) // 48 is the decimal character code value for displaying 0 on LCD tempC[0] = tempinC/10000 + 48; else tempC[0] = ' '; tempC[1] = (tempinC/1000)%10 + 48; // Extract tens digit tempC[2] = (tempinC/100)%10 + 48; // Extract ones digit // convert temp_fraction to characters tempC[4] = (tempinC/10)%10 + 48; // Extract tens digit
#include <stdio.h>
void display_value(void)
{
unsigned int value = 22;
char buffer[16]; /* size of line on display */
sprintf(buffer, "Value is %d", value); /* Same formatting options as printf */
display_line(buffer); /* Your call to display function */
}
char chuoi_so_nguyen[7];
char *itoa(short int n )
{
unsigned char d4, d3, d2, d1, d0, q;
if (n < 0)
{
chuoi_so_nguyen[0]='-';
n = -n;
}
else
{
chuoi_so_nguyen[0]='+';
}
d1 = (n>>4) & 0xF;
d2 = (n>>8) & 0xF;
d3 = (n>>12) & 0xF;
d0 = 6*(d3 + d2 + d1) + (n & 0xF);
q = (d0 * 0xCD) >> 11;
d0 = d0 - 10*q;
d1 = q + 9*d3 + 5*d2 + d1;
q = (d1 * 0xCD) >> 11;
d1 = d1 - 10*q;
d2 = q + 2*d2;
q = (d2 * 0x1A) >> 8;
d2 = d2 - 10*q;
d3 = q + 4*d3;
d4 = (d3 * 0x1A) >> 8;
d3 = d3 - 10*d4;
chuoi_so_nguyen[1]=d4+'0';
chuoi_so_nguyen[2]=d3+'0';
chuoi_so_nguyen[3]=d2+'0';
chuoi_so_nguyen[4]=d1+'0';
chuoi_so_nguyen[5]=d0+'0';
int i=5;
// === remove left zero number =========
while(chuoi_so_nguyen[1]=='0'&& i>1)
{
int j;
for(j=1;j<i;j++)
{
chuoi_so_nguyen[j]=chuoi_so_nguyen[j+1];
}
i--;
}
chuoi_so_nguyen[i+1]='\0';
return chuoi_so_nguyen;
}
I want to display an int in an LCD display. For example,
int a=174;
Now to display it in LCD, I want to send the ascii of each digit to LCD.
unsigned int d1,d2,d3,temp,a=174;
temp=a%100;
d1=(a/100)+48;//converting to ascii
lcddata(d1);
d2=(temp/10)+48;
lcddata(d2);
d3=(temp%10)+48;
lcddata(d3);
char *int_to_string(unsigned long int i, unsigned char buf[])
{
unsigned char temp;
unsigned char s = 0,t = 0;
while(i) {
buf[s++] = i % 10 + '0';
i /= 10;
}
buf[s] = 0;
s-=1;
for(;t<s;t++,s--) {
temp = buf[s];
buf[s]=buf[t];
buf[t] = temp;
}
return buf;
}
//Time to Display Data on LCD
ones = adc_data % 10;
adc_data = adc_data / 10;
tens = adc_data % 10;
hundreds = adc_data / 10;
DelayMs(10);
LCD_Second_Line();
DelayMs(10);
LCD_GOTOXY(2,1);
LCD_Data((hundreds | 0x30));
LCD_Data((tens | 0x30));
LCD_Data((ones | 0x30));
DelayMs(5000);
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?