子模塊是這樣的:
unsigned char temperature()
{
unsigned char TempH,TempL;
TMOD|=0x01;//定時器設置
TH0=0xef;
TL0=0xf0;
IE=0x82;
TR0=1;
P2=0x00;
count=0;
while(1)
{
if(flag_get==1) //定時讀取當前溫度
{
temp=ReadTemperature();
TempH=temp>>4;
TempL=temp&0x0F;
TempL=TempL*6/10;//小數近似處理
flag_get=0;
}
str[0]=tab[(TempH%100)/10]; //十位溫度
str[1]=tab[(TempH%100)%10]|0x80; //個位溫度,帶小數點
str[2]=tab[TempL];
}
return(str);
}
頭文件是這樣的:
#ifndef _temperature_H_
#define _temperature_H_
extern unsigned char temperature();
#endif
這是主函數:
#include<string.h>
#include "LCD1602.h"
#include "temperature.h"
void main(void)
{
unsigned char string0[]="ST: . C,T: . C";
unsigned char string1[]="Code ";
unsigned char temp[3]=temperature();
string0[11]=temp[0];
string0[12]=temp[1];
string0[14]=temp[2];
string0[3]="2";
string0[4]="5";
string0[6]="0";
while(1)
{
LCD1602(string0,string1);
}
}
可是報錯:SRC\MAIN.C(13): error C247: non-address/-constant initializer
怎么解決??急急急!!!
|