|
在mega8中做AD转换后得到的数据送到液晶1602中显示,我自己写了一个指针函数把AD里读得的数据转换成ASCII码,但是那个指针函数老是有问题.指针函数如下:
返回的是地址是转换后字符串的首地址.
unsigned char *adget_to_lcd(unsigned long data_value)
{
volatile unsigned char *str;
unsigned char temp[5] = {0, 0, 0, 0};
unsigned char j = 0 ;
unsigned char k ;
do//将data_value从低到高逐位存入temp数组中
{
temp[j] = data_value%10 + '0';
j++;
}while ((unsigned) (data_value/=10));
temp[j]='\0';
for (k=j;k>0;k--) //将存入的数按正确顺序存到指向str单元中。
{
*str = temp[k];
str++;
}
*str='\0';
return str;
}
但是有以下警告:
main.c: In function `adget_to_lcd':
main.c:41: warning: return discards qualifiers from pointer target type
main.c:21: warning: 'str' might be used uninitialized in this function
而且整个程序不能正常工作,我用的GCC编译器是 20070525版的.本来用库函数也可以实现上述功能,但是库函数生成的代码量太多了.接触单片机的时间还不长, |
|