新手单片机,用51单片机做了一个计价显示器,但是keil调试的时候出现了重复定义的问题?
时间:10-02
整理:3721RD
点击:
代码如下:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^1;
sbit wela=P2^2;
uchar bai,shi,ge,Qian,Bai,Shi,Ge,count,num;
unsigned char seg7cc[]=
{
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
void display(uchar bai,uchar shi,uchar ge,uchar Qian,uchar Bai,uchar Shi,uchar Ge);
void delayms(uint xms);
uchar tmp,second;
uchar count;
void main()
{
EA=1;
ET0=1;
TR0=1;
TMOD=0x01;
TH0=(65560-50000)/256;
TL0=(65560-50000)%256;
while(1)
{
display (bai,shi,ge,Qian,Bai,Shi,Ge);
}
}
void display(uchar bai,uchar shi,uchar ge,uchar Qian,uchar Bai,uchar Shi,uchar Ge)
{
dula=1;
P0=seg7cc[ge];
dula=0;
wela=1;
P0=0xfe;
delayms(5);
dula=1;
P0=seg7cc[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
delayms(5);
dula=1;
P0=seg7cc[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xfc;;
delayms(5);
dula=1;
P0=seg7cc[Qian];
dula=0;
P0=0xff;
wela=1;
P0=0x7f;
delayms(5);
dula=1;
P0=seg7cc[Bai];
dula=0;
P0=0xff;
wela=1;
P0=0xbf;
delayms(5);
dula=1;
P0=seg7cc[Shi];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
delayms(5);
dula=1;
P0=seg7cc[Ge];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
delayms(5);
}
void delayms(uint xms)
{
int i,j;
for(i=xms;i>0;i--)
for(j=124;j>0;j--);
}
void T0_Timer() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==20)
{
count=0;
num++;
if(num==1000)
num=0;
bai=num/100;
shi=num/10%10;
ge=num%10;
}
if(num<=2)
{
Qian=0;
Bai=0;
Shi=0;
Ge=6;
}
else
{
num=(num-7)*1.5;
Qian=num/1000;
Bai=num/100%10;
Shi=num/10%10;
Ge=num%10;
}
}
-------------------------------------------------------------
建立文件的时候出现了下面的问题:
Build target 'Target 1'
linking...
*** ERROR L104: MULTIPLE PUBLIC DEFINITIONS
SYMBOL: GE
MODULE: ..\..\Objects\1.obj (1)
*** ERROR L104: MULTIPLE PUBLIC DEFINITIONS
SYMBOL: SHI
MODULE: ..\..\Objects\1.obj (1)
*** ERROR L104: MULTIPLE PUBLIC DEFINITIONS
SYMBOL: BAI
MODULE: ..\..\Objects\1.obj (1)
Program Size: data=43.0 xdata=0 code=1167
Target not created.
Build Time Elapsed: 00:00:01
----------------------------------------------------
我在网上查了一下需要在头文件的定义加extern,但是加了后又出现别问题了。请给位大大帮我看一下。
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^1;
sbit wela=P2^2;
uchar bai,shi,ge,Qian,Bai,Shi,Ge,count,num;
unsigned char seg7cc[]=
{
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
void display(uchar bai,uchar shi,uchar ge,uchar Qian,uchar Bai,uchar Shi,uchar Ge);
void delayms(uint xms);
uchar tmp,second;
uchar count;
void main()
{
EA=1;
ET0=1;
TR0=1;
TMOD=0x01;
TH0=(65560-50000)/256;
TL0=(65560-50000)%256;
while(1)
{
display (bai,shi,ge,Qian,Bai,Shi,Ge);
}
}
void display(uchar bai,uchar shi,uchar ge,uchar Qian,uchar Bai,uchar Shi,uchar Ge)
{
dula=1;
P0=seg7cc[ge];
dula=0;
wela=1;
P0=0xfe;
delayms(5);
dula=1;
P0=seg7cc[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
delayms(5);
dula=1;
P0=seg7cc[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xfc;;
delayms(5);
dula=1;
P0=seg7cc[Qian];
dula=0;
P0=0xff;
wela=1;
P0=0x7f;
delayms(5);
dula=1;
P0=seg7cc[Bai];
dula=0;
P0=0xff;
wela=1;
P0=0xbf;
delayms(5);
dula=1;
P0=seg7cc[Shi];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
delayms(5);
dula=1;
P0=seg7cc[Ge];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
delayms(5);
}
void delayms(uint xms)
{
int i,j;
for(i=xms;i>0;i--)
for(j=124;j>0;j--);
}
void T0_Timer() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==20)
{
count=0;
num++;
if(num==1000)
num=0;
bai=num/100;
shi=num/10%10;
ge=num%10;
}
if(num<=2)
{
Qian=0;
Bai=0;
Shi=0;
Ge=6;
}
else
{
num=(num-7)*1.5;
Qian=num/1000;
Bai=num/100%10;
Shi=num/10%10;
Ge=num%10;
}
}
-------------------------------------------------------------
建立文件的时候出现了下面的问题:
Build target 'Target 1'
linking...
*** ERROR L104: MULTIPLE PUBLIC DEFINITIONS
SYMBOL: GE
MODULE: ..\..\Objects\1.obj (1)
*** ERROR L104: MULTIPLE PUBLIC DEFINITIONS
SYMBOL: SHI
MODULE: ..\..\Objects\1.obj (1)
*** ERROR L104: MULTIPLE PUBLIC DEFINITIONS
SYMBOL: BAI
MODULE: ..\..\Objects\1.obj (1)
Program Size: data=43.0 xdata=0 code=1167
Target not created.
Build Time Elapsed: 00:00:01
----------------------------------------------------
我在网上查了一下需要在头文件的定义加extern,但是加了后又出现别问题了。请给位大大帮我看一下。
知道啦,大小写是不区分的,把“bai,shi,ge"改个名称就行了