51单片机驱动DHT11温度传感器编译出错
时间:10-02
整理:3721RD
点击:
51单片机驱动DHT11温度传感器编译出错,
Rebuild target 'Target 1'
assembling STARTUP.A51...
compiling dht11.c...
dht11.c(175): warning C290: missing return value
linking...
BL51 BANKED LINKER/LOCATER V6.22 - SN: Eval Version
COPYRIGHT KEIL ELEKTRONIK GmbH 1987 - 2009
"STARTUP.obj",
"dht11.obj"
TO "11"
*** FATAL ERROR L256: MODULE CONTAINS DUPLICATE SEGMENT NAMES
SEGMENT: ?PR?_DELAY?DHT11
MODULE: dht11.obj (DHT11)
Target not created
请问是怎么回事?
以下是代码,帮看一下
#define uint unsigned int
sbit P2_0 = P2^0 ;
sbit P2_1 = P2^1 ;
U8 U8FLAG;
U8 U8count,U8temp;
U8 U8T_data_H,U8T_data_L,U8RH_data_H,U8RH_data_L,U8checkdata;
U8 U8T_data_H_temp,U8T_data_L_temp,U8RH_data_H_temp,U8RH_data_L_temp,U8checkdata_temp;
U8 U8comdata;
U8 indata[5];
U8 count, count_r=0;
U16 U16temp1,U16temp2;
sbit wei1=P2^4;
sbit wei2=P2^5;
sbit wei3=P2^6;
sbit wei4=P2^7;
uchar code LEDData[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar data display[5] = {0x00,0x00,0x00,0x00,0x00};
void Delay(U16 j)
{
U8 i;
for(;j>0;j--)
{
for(i=0;i<27;i++);
}
}
void delay(unsigned int num)
{
while( --num );
}
void Delay_10us(void)
{
U8 i;
i--;
i--;
i--;
i--;
i--;
i--;
}
void COM(void)
{
U8 i;
for(i=0;i<8;i++)
{
U8FLAG=2;
P2_1=0 ;
P2_1=1 ;
while((!P2_0)&&U8FLAG++);
Delay_10us();
Delay_10us();
U8temp=0;
if(P2_0)U8temp=1;
U8FLAG=2;
while((P2_0)&&U8FLAG++);
P2_1=0 ;
P2_1=1 ;
if(U8FLAG==1)break;
U8comdata<<=1;
U8comdata|=U8temp;
}
}
void RH(void)
{
P2_0=0;
Delay(180);
P2_0=1;
Delay_10us();
Delay_10us();
Delay_10us();
Delay_10us();
P2_0=1;
if(!P2_0)
{
U8FLAG=2;
while((!P2_0)&&U8FLAG++);
U8FLAG=2;
while((P2_0)&&U8FLAG++);
COM();
U8RH_data_H_temp=U8comdata;
COM();
U8RH_data_L_temp=U8comdata;
COM();
U8T_data_H_temp=U8comdata;
COM();
U8T_data_L_temp=U8comdata;
COM();
U8checkdata_temp=U8comdata;
P2_0=1;
U8temp=(U8T_data_H_temp+U8T_data_L_temp+U8RH_data_H_temp+U8RH_data_L_temp);
if(U8temp==U8checkdata_temp)
{
U8RH_data_H=U8RH_data_H_temp;
U8RH_data_L=U8RH_data_L_temp;
U8T_data_H=U8T_data_H_temp;
U8T_data_L=U8T_data_L_temp;
U8checkdata=U8checkdata_temp;
}
}
}
Disp_Temperature()
{
unsigned char n=0;
display[4]=U8RH_data_H;
display[4]=display[4]%100;
display[3]=display[4]/10;
display[2]=display[1]%10;
display[4]=U8T_data_H;
display[4]=display[4]%100;
display[1]=display[4]/10;
display[0]=display[4]%10;
if(!display[3])
{
display[3]=0x0a;
if(!display[1])
display[1]=0x0a;
}
wei1=0;
P0=LEDData[display[0]];
delay(5);wei1=1;
wei2=0;
P0=LEDData[display[1]];
delay(5);wei2=1;
wei3=0;
P0=LEDData[display[2]];
delay(5);wei3=1;
wei4=0;
P0=LEDData[display[3]];
delay(5);wei4=1;
}
void main(void)
{
while(1)
{
RH();
Disp_Temperature();
Delay(20000);
}
}
Rebuild target 'Target 1'
assembling STARTUP.A51...
compiling dht11.c...
dht11.c(175): warning C290: missing return value
linking...
BL51 BANKED LINKER/LOCATER V6.22 - SN: Eval Version
COPYRIGHT KEIL ELEKTRONIK GmbH 1987 - 2009
"STARTUP.obj",
"dht11.obj"
TO "11"
*** FATAL ERROR L256: MODULE CONTAINS DUPLICATE SEGMENT NAMES
SEGMENT: ?PR?_DELAY?DHT11
MODULE: dht11.obj (DHT11)
Target not created
请问是怎么回事?
以下是代码,帮看一下
#define uint unsigned int
sbit P2_0 = P2^0 ;
sbit P2_1 = P2^1 ;
U8 U8FLAG;
U8 U8count,U8temp;
U8 U8T_data_H,U8T_data_L,U8RH_data_H,U8RH_data_L,U8checkdata;
U8 U8T_data_H_temp,U8T_data_L_temp,U8RH_data_H_temp,U8RH_data_L_temp,U8checkdata_temp;
U8 U8comdata;
U8 indata[5];
U8 count, count_r=0;
U16 U16temp1,U16temp2;
sbit wei1=P2^4;
sbit wei2=P2^5;
sbit wei3=P2^6;
sbit wei4=P2^7;
uchar code LEDData[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar data display[5] = {0x00,0x00,0x00,0x00,0x00};
void Delay(U16 j)
{
U8 i;
for(;j>0;j--)
{
for(i=0;i<27;i++);
}
}
void delay(unsigned int num)
{
while( --num );
}
void Delay_10us(void)
{
U8 i;
i--;
i--;
i--;
i--;
i--;
i--;
}
void COM(void)
{
U8 i;
for(i=0;i<8;i++)
{
U8FLAG=2;
P2_1=0 ;
P2_1=1 ;
while((!P2_0)&&U8FLAG++);
Delay_10us();
Delay_10us();
U8temp=0;
if(P2_0)U8temp=1;
U8FLAG=2;
while((P2_0)&&U8FLAG++);
P2_1=0 ;
P2_1=1 ;
if(U8FLAG==1)break;
U8comdata<<=1;
U8comdata|=U8temp;
}
}
void RH(void)
{
P2_0=0;
Delay(180);
P2_0=1;
Delay_10us();
Delay_10us();
Delay_10us();
Delay_10us();
P2_0=1;
if(!P2_0)
{
U8FLAG=2;
while((!P2_0)&&U8FLAG++);
U8FLAG=2;
while((P2_0)&&U8FLAG++);
COM();
U8RH_data_H_temp=U8comdata;
COM();
U8RH_data_L_temp=U8comdata;
COM();
U8T_data_H_temp=U8comdata;
COM();
U8T_data_L_temp=U8comdata;
COM();
U8checkdata_temp=U8comdata;
P2_0=1;
U8temp=(U8T_data_H_temp+U8T_data_L_temp+U8RH_data_H_temp+U8RH_data_L_temp);
if(U8temp==U8checkdata_temp)
{
U8RH_data_H=U8RH_data_H_temp;
U8RH_data_L=U8RH_data_L_temp;
U8T_data_H=U8T_data_H_temp;
U8T_data_L=U8T_data_L_temp;
U8checkdata=U8checkdata_temp;
}
}
}
Disp_Temperature()
{
unsigned char n=0;
display[4]=U8RH_data_H;
display[4]=display[4]%100;
display[3]=display[4]/10;
display[2]=display[1]%10;
display[4]=U8T_data_H;
display[4]=display[4]%100;
display[1]=display[4]/10;
display[0]=display[4]%10;
if(!display[3])
{
display[3]=0x0a;
if(!display[1])
display[1]=0x0a;
}
wei1=0;
P0=LEDData[display[0]];
delay(5);wei1=1;
wei2=0;
P0=LEDData[display[1]];
delay(5);wei2=1;
wei3=0;
P0=LEDData[display[2]];
delay(5);wei3=1;
wei4=0;
P0=LEDData[display[3]];
delay(5);wei4=1;
}
void main(void)
{
while(1)
{
RH();
Disp_Temperature();
Delay(20000);
}
}