不知道程序哪里错了
时间:10-02
整理:3721RD
点击:
以下是程序:是 多文件程序一直显示
temp.c(14): error C141: syntax error near 'unsigned'
temp.c(16): error C141: syntax error near '{'
temp.c(36): error C141: syntax error near 'void'
文件main.c
#include <reg52.h>
#include <temp.h>
typedef unsigned char u8;
typedef unsigned int u16;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
u8 DisplayDate[8];
u8 code smgduan[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void Delay (u16 i)
{
while(i--);
}
void datapros (int temp)
{
float tp;
if (temp<0)
{
DisplayDate[0]=0x40;
temp=temp-1;
temp=!temp;
tp=temp;
temp=tp*0.0625*100+0.5;
}
else
{
DisplayDate[0]=0x00;
tp=temp;
temp=tp*0.0625*100+0.5;
}
DisplayDate [1]=smgduan[temp/10000];
DisplayDate [2]=smgduan[temp%10000/1000];
DisplayDate [3]=smgduan[temp%10000%1000/1001]|0x80;
DisplayDate [4]=smgduan[temp%100/10];
DisplayDate [5]=smgduan[temp%100%10];
}
void xianshi()
{
u8 c;
for (c=0;c<6;c++)
{
switch (c)
{
case (0):LSA=0;LSB=0;LSC=0;break;
case (1):LSA=1;LSB=0;LSC=0;break;
case (2):LSA=0;LSB=1;LSC=0;break;
case (3):LSA=1;LSB=1;LSC=0;break;
case (4):LSA=0;LSB=0;LSC=1;break;
case (5):LSA=1;LSB=0;LSC=1;break;
}
P0=DisplayDate[5-c];
Delay (100);
P0=0x00;
}
}
void main()
{
while(1)
{
datapros (Ds18b20ReadTemp());
xianshi();
}
}
文件temp.c
#include"temp.h"
void Delay1ms (uint y)
{
uint x ;
for ( ;y<0;y--)
{
for (x=110;x>0;x--);
}
uchar Ds18b20Init ()
{
uchar i;
DSPORT=0;
i=70;
while(i--) // 642 ms
DSPORT=1;
i=0;
while (DSPORT)
{
Delay1ms (1);
i++;
if (i>5)
{
return 0;
}
}
return 1;
}
void Ds18b20writebyte(uchar dat )
{
uint i,j;
for (j=0;j<8;j++)
{
DSPORT=0;
i++;
DSPORT=dat & 0x01;
i=6;
while (i--);
DSPORT=1;
dat>>=1;
}
}
unchar Ds18b20Readbyte ()
{
uint i,j;
uchar bi,byte;
for (j=0;j<8;j++)
{
DSPORT=0;
i++;
DSPORT=1;
Delay1ms(10);
bi=DSPORT;
byte=(byte>>1)|(bi<<7);
i=4;
while (i--);
}
return byte;
}
void Ds18b20ChangeTemp ()
{
Ds18b20Init ();
Delay1ms (1);
Ds18b20writebyte(0xcc);
Ds18b20writebyte(0x44);
}
void Ds18b20ReadTempCom()
{
Ds18b20Init ();
Delay1ms (1);
Ds18b20writebyte(0xcc);
Ds18b20writebyte(0xbe);
}
int Ds18b20ReadTemp()
{
uchar tmh,tml;
int temp;
Ds18b20ChangeTemp ();
Ds18b20ReadTempCom();
tml=Ds18b20Readbyte ();
tmh=Ds18b20Readbyte ();
temp=tmh;
temp<<=8;
temp=|tml;
return temp;
}
文件temp.h
uchar Ds18b20Init();
void Ds18b20WriteByte(uchar com);
uchar Ds18b20ReadByte();
void Ds18b20ChangTemp();
void Ds18b20ReadTempCom();
int Ds18b20ReadTemp();
#endif
temp.c(14): error C141: syntax error near 'unsigned'
temp.c(16): error C141: syntax error near '{'
temp.c(36): error C141: syntax error near 'void'
文件main.c
#include <reg52.h>
#include <temp.h>
typedef unsigned char u8;
typedef unsigned int u16;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
u8 DisplayDate[8];
u8 code smgduan[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void Delay (u16 i)
{
while(i--);
}
void datapros (int temp)
{
float tp;
if (temp<0)
{
DisplayDate[0]=0x40;
temp=temp-1;
temp=!temp;
tp=temp;
temp=tp*0.0625*100+0.5;
}
else
{
DisplayDate[0]=0x00;
tp=temp;
temp=tp*0.0625*100+0.5;
}
DisplayDate [1]=smgduan[temp/10000];
DisplayDate [2]=smgduan[temp%10000/1000];
DisplayDate [3]=smgduan[temp%10000%1000/1001]|0x80;
DisplayDate [4]=smgduan[temp%100/10];
DisplayDate [5]=smgduan[temp%100%10];
}
void xianshi()
{
u8 c;
for (c=0;c<6;c++)
{
switch (c)
{
case (0):LSA=0;LSB=0;LSC=0;break;
case (1):LSA=1;LSB=0;LSC=0;break;
case (2):LSA=0;LSB=1;LSC=0;break;
case (3):LSA=1;LSB=1;LSC=0;break;
case (4):LSA=0;LSB=0;LSC=1;break;
case (5):LSA=1;LSB=0;LSC=1;break;
}
P0=DisplayDate[5-c];
Delay (100);
P0=0x00;
}
}
void main()
{
while(1)
{
datapros (Ds18b20ReadTemp());
xianshi();
}
}
文件temp.c
#include"temp.h"
void Delay1ms (uint y)
{
uint x ;
for ( ;y<0;y--)
{
for (x=110;x>0;x--);
}
uchar Ds18b20Init ()
{
uchar i;
DSPORT=0;
i=70;
while(i--) // 642 ms
DSPORT=1;
i=0;
while (DSPORT)
{
Delay1ms (1);
i++;
if (i>5)
{
return 0;
}
}
return 1;
}
void Ds18b20writebyte(uchar dat )
{
uint i,j;
for (j=0;j<8;j++)
{
DSPORT=0;
i++;
DSPORT=dat & 0x01;
i=6;
while (i--);
DSPORT=1;
dat>>=1;
}
}
unchar Ds18b20Readbyte ()
{
uint i,j;
uchar bi,byte;
for (j=0;j<8;j++)
{
DSPORT=0;
i++;
DSPORT=1;
Delay1ms(10);
bi=DSPORT;
byte=(byte>>1)|(bi<<7);
i=4;
while (i--);
}
return byte;
}
void Ds18b20ChangeTemp ()
{
Ds18b20Init ();
Delay1ms (1);
Ds18b20writebyte(0xcc);
Ds18b20writebyte(0x44);
}
void Ds18b20ReadTempCom()
{
Ds18b20Init ();
Delay1ms (1);
Ds18b20writebyte(0xcc);
Ds18b20writebyte(0xbe);
}
int Ds18b20ReadTemp()
{
uchar tmh,tml;
int temp;
Ds18b20ChangeTemp ();
Ds18b20ReadTempCom();
tml=Ds18b20Readbyte ();
tmh=Ds18b20Readbyte ();
temp=tmh;
temp<<=8;
temp=|tml;
return temp;
}
文件temp.h
uchar Ds18b20Init();
void Ds18b20WriteByte(uchar com);
uchar Ds18b20ReadByte();
void Ds18b20ChangTemp();
void Ds18b20ReadTempCom();
int Ds18b20ReadTemp();
#endif
uchar uint没定义?