MIAOBIAO.C(51): error C231: 'rs': redefinition
MIAOBIAO.C(51): error C231: 'rs': redefinition
MIAOBIAO.C(52): error C231: 'rw': redefinition
MIAOBIAO.C(52): error C231: 'rw': redefinition
MIAOBIAO.C(53): error C231: 'P0': redefinition
MIAOBIAO.C(53): error C202: 'm': undefined identifier
MIAOBIAO.C(53): error C231: 'P0': redefinition
MIAOBIAO.C(54): error C141: syntax error near '1'
MIAOBIAO.c - 11 Error(s), 1 Warning(s).我感觉程序应该没有错啊,想实现按K1开始K6倒计时,k2记录K3清零,K4/K5上下翻,求助啊
错在哪里
程序是
#include<reg52.h>
sbit k1=P3^0;
sbit k2=P3^1;
sbit k3=P3^2;
sbit k4=P3^3;
sbit k5=P3^4;
sbit k6=P3^5;
sbit en=P2^2;
sbit rs=P2^0;
sbit rw=P2^1;
unsigned int num1=0;
unsigned int num0=0;
unsigned char i=0;
unsigned char j=0;
unsigned char dat3=0;
unsigned char dat4=0;
unsigned char Sec[4]={0,0,0,0};
#define uchar unsigned char
#define uint unsigned int
delay1ms(uint t)
{
uint a,b;
for(a=0;a<t;a++)
for(b=0;b<1000;b++);
}
void lcd_init()
{
lcd_wcom(0x38);
lcd_wcom(0x0c);
lcd_wcom(0x06);
lcd_wcom(0x01);
}
void lcd_wdat(uchar dat)
{
rs=1;
rw=0;
P0=dat;
delay1ms(1);
en=1;
en=0;
}
void scan()
{ dat4=num1/10;
dat3=num1%10;
lcd_wcom(0x80+0x40);
lcd_wdat(0x30+dat4);
lcd_wdat(0x30+dat3);
}
void lcd_wcom(uchar mm);
{
rs=0;
rw=0;
P0=m;
delay1ms(1);
en=1;
en=0;
}
void reset_T0()
{
TMOD=0x11;
TL0=0xfb;TH0=0xd8;
EA=1,ET0=1,ET1=1;
}
void test()
{
if(k1==0)
{
delay1ms(10);
if(!k1)
{
while(!k1)
{;}
TR0=!TR0;
TR1=0;
}
}
if(k2==0)
{
delay1ms(10);
if(!k2)
{
num1=0;
TR0=0;
TR1=0;
}
}
if(k3==0)
{
delay1ms(10);
if(!k3)
{
if(i==4)
{TR0=0;TR1=0;
}
Sec[i]=num1;
i++;
}
}
if(k4==0)
{
delay1ms(10);
if(!k4)
{
TR0=0;TR1=0;
num1=Sec[j];
j++;
}
}
if(k5==0)
{
delay1ms(10);
if(!k5){
j=3;num1=Sec[j];j--;
}
}
if(k6==0)
{delay1ms(10);
if(!k6)
{TR1=!TR1;
TR0=0;
}
}
}
void main()
{
lcd_init();
reset_T0();
EX0=0;
EA=1;
EX1=0;
TR0=0;
TR1=0;
while(1)
{
scan();
test();
}
}
void T0_time() interrupt 1
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
num0++;
if(num0==20)
{
num0=0;
if(num1==0)
num1=99;
num1-=1;
}
}
void T1_time() interrupt 3
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num0++;
if(num0==20)
{
num0=0;
if(num1==99)
num1=0;
num1+=1;
}
}
6 个解决方案
#1
上程序员大本营之类的,大把多,
#2
void lcd_wcom(uchar mm);
{
rs=0;
rw=0;
P0=m;
delay1ms(1);
en=1;
en=0;
}
函数体内用的是m,传参是mm用的mm。
#3
好像你定义rs rw是bit变量,赋值时默认的是int,前面加个显式转换吧
rs=(bit)0;
rs=(bit)0;
#4
void lcd_wcom(uchar mm);
多了一个标点符号
#5
全都是语法错误,大四了怎么还犯这些错误
#6
#include<reg52.h>
sbit k1=P3^0;
sbit k2=P3^1;
sbit k3=P3^2;
sbit k4=P3^3;
sbit k5=P3^4;
sbit k6=P3^5;
sbit en=P2^2;
sbit rs=P2^0;
sbit rw=P2^1;
unsigned int num1=0;
unsigned int num0=0;
unsigned char i=0;
unsigned char j=0;
unsigned char dat3=0;
unsigned char dat4=0;
unsigned char Sec[4]={0,0,0,0};
#define uchar unsigned char
#define uint unsigned int
void lcd_wcom(uchar); //在这里声明了
void delay1ms(uint t)
{
uint a,b;
for(a=0;a<t;a++)
for(b=0;b<1000;b++);
}
void lcd_init()
{
lcd_wcom(0x38); //调用前要声明的
lcd_wcom(0x0c);
lcd_wcom(0x06);
lcd_wcom(0x01);
}
void lcd_wdat(uchar dat)
{
rs=1;
rw=0;
P0=dat;
delay1ms(1);
en=1;
en=0;
}
void scan()
{ dat4=num1/10;
dat3=num1%10;
lcd_wcom(0x80+0x40);
lcd_wdat(0x30+dat4);
lcd_wdat(0x30+dat3);
}
void lcd_wcom(uchar mm)//;
{
rs=0;
rw=0;
P0=mm; //这个m应该是mm吧
delay1ms(1);
en=1;
en=0;
}
void reset_T0()
{
TMOD=0x11;
TL0=0xfb;TH0=0xd8;
EA=1,ET0=1,ET1=1;
}
void test()
{
if(k1==0)
{
delay1ms(10);
if(!k1)
{
while(!k1)
{;}
TR0=!TR0;
TR1=0;
}
}
if(k2==0)
{
delay1ms(10);
if(!k2)
{
num1=0;
TR0=0;
TR1=0;
}
}
if(k3==0)
{
delay1ms(10);
if(!k3)
{
if(i==4)
{TR0=0;TR1=0;
}
Sec[i]=num1;
i++;
}
}
if(k4==0)
{
delay1ms(10);
if(!k4)
{
TR0=0;TR1=0;
num1=Sec[j];
j++;
}
}
if(k5==0)
{
delay1ms(10);
if(!k5){
j=3;num1=Sec[j];j--;
}
}
if(k6==0)
{delay1ms(10);
if(!k6)
{TR1=!TR1;
TR0=0;
}
}
}
void main()
{
lcd_init();
reset_T0();
EX0=0;
EA=1;
EX1=0;
TR0=0;
TR1=0;
while(1)
{
scan();
test();
}
}
void T0_time() interrupt 1
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
num0++;
if(num0==20)
{
num0=0;
if(num1==0)
num1=99;
num1-=1;
}
}
void T1_time() interrupt 3
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num0++;
if(num0==20)
{
num0=0;
if(num1==99)
num1=0;
num1+=1;
}
}
总共错误就3处,一个是没声明,一个是多一个;,还有一个m应该是mm,在我这里允许正常,没有错误,没有警告 。。。
sbit k1=P3^0;
sbit k2=P3^1;
sbit k3=P3^2;
sbit k4=P3^3;
sbit k5=P3^4;
sbit k6=P3^5;
sbit en=P2^2;
sbit rs=P2^0;
sbit rw=P2^1;
unsigned int num1=0;
unsigned int num0=0;
unsigned char i=0;
unsigned char j=0;
unsigned char dat3=0;
unsigned char dat4=0;
unsigned char Sec[4]={0,0,0,0};
#define uchar unsigned char
#define uint unsigned int
void lcd_wcom(uchar); //在这里声明了
void delay1ms(uint t)
{
uint a,b;
for(a=0;a<t;a++)
for(b=0;b<1000;b++);
}
void lcd_init()
{
lcd_wcom(0x38); //调用前要声明的
lcd_wcom(0x0c);
lcd_wcom(0x06);
lcd_wcom(0x01);
}
void lcd_wdat(uchar dat)
{
rs=1;
rw=0;
P0=dat;
delay1ms(1);
en=1;
en=0;
}
void scan()
{ dat4=num1/10;
dat3=num1%10;
lcd_wcom(0x80+0x40);
lcd_wdat(0x30+dat4);
lcd_wdat(0x30+dat3);
}
void lcd_wcom(uchar mm)//;
{
rs=0;
rw=0;
P0=mm; //这个m应该是mm吧
delay1ms(1);
en=1;
en=0;
}
void reset_T0()
{
TMOD=0x11;
TL0=0xfb;TH0=0xd8;
EA=1,ET0=1,ET1=1;
}
void test()
{
if(k1==0)
{
delay1ms(10);
if(!k1)
{
while(!k1)
{;}
TR0=!TR0;
TR1=0;
}
}
if(k2==0)
{
delay1ms(10);
if(!k2)
{
num1=0;
TR0=0;
TR1=0;
}
}
if(k3==0)
{
delay1ms(10);
if(!k3)
{
if(i==4)
{TR0=0;TR1=0;
}
Sec[i]=num1;
i++;
}
}
if(k4==0)
{
delay1ms(10);
if(!k4)
{
TR0=0;TR1=0;
num1=Sec[j];
j++;
}
}
if(k5==0)
{
delay1ms(10);
if(!k5){
j=3;num1=Sec[j];j--;
}
}
if(k6==0)
{delay1ms(10);
if(!k6)
{TR1=!TR1;
TR0=0;
}
}
}
void main()
{
lcd_init();
reset_T0();
EX0=0;
EA=1;
EX1=0;
TR0=0;
TR1=0;
while(1)
{
scan();
test();
}
}
void T0_time() interrupt 1
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
num0++;
if(num0==20)
{
num0=0;
if(num1==0)
num1=99;
num1-=1;
}
}
void T1_time() interrupt 3
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num0++;
if(num0==20)
{
num0=0;
if(num1==99)
num1=0;
num1+=1;
}
}
总共错误就3处,一个是没声明,一个是多一个;,还有一个m应该是mm,在我这里允许正常,没有错误,没有警告 。。。
#1
上程序员大本营之类的,大把多,
#2
void lcd_wcom(uchar mm);
{
rs=0;
rw=0;
P0=m;
delay1ms(1);
en=1;
en=0;
}
函数体内用的是m,传参是mm用的mm。
#3
好像你定义rs rw是bit变量,赋值时默认的是int,前面加个显式转换吧
rs=(bit)0;
rs=(bit)0;
#4
void lcd_wcom(uchar mm);
多了一个标点符号
#5
全都是语法错误,大四了怎么还犯这些错误
#6
#include<reg52.h>
sbit k1=P3^0;
sbit k2=P3^1;
sbit k3=P3^2;
sbit k4=P3^3;
sbit k5=P3^4;
sbit k6=P3^5;
sbit en=P2^2;
sbit rs=P2^0;
sbit rw=P2^1;
unsigned int num1=0;
unsigned int num0=0;
unsigned char i=0;
unsigned char j=0;
unsigned char dat3=0;
unsigned char dat4=0;
unsigned char Sec[4]={0,0,0,0};
#define uchar unsigned char
#define uint unsigned int
void lcd_wcom(uchar); //在这里声明了
void delay1ms(uint t)
{
uint a,b;
for(a=0;a<t;a++)
for(b=0;b<1000;b++);
}
void lcd_init()
{
lcd_wcom(0x38); //调用前要声明的
lcd_wcom(0x0c);
lcd_wcom(0x06);
lcd_wcom(0x01);
}
void lcd_wdat(uchar dat)
{
rs=1;
rw=0;
P0=dat;
delay1ms(1);
en=1;
en=0;
}
void scan()
{ dat4=num1/10;
dat3=num1%10;
lcd_wcom(0x80+0x40);
lcd_wdat(0x30+dat4);
lcd_wdat(0x30+dat3);
}
void lcd_wcom(uchar mm)//;
{
rs=0;
rw=0;
P0=mm; //这个m应该是mm吧
delay1ms(1);
en=1;
en=0;
}
void reset_T0()
{
TMOD=0x11;
TL0=0xfb;TH0=0xd8;
EA=1,ET0=1,ET1=1;
}
void test()
{
if(k1==0)
{
delay1ms(10);
if(!k1)
{
while(!k1)
{;}
TR0=!TR0;
TR1=0;
}
}
if(k2==0)
{
delay1ms(10);
if(!k2)
{
num1=0;
TR0=0;
TR1=0;
}
}
if(k3==0)
{
delay1ms(10);
if(!k3)
{
if(i==4)
{TR0=0;TR1=0;
}
Sec[i]=num1;
i++;
}
}
if(k4==0)
{
delay1ms(10);
if(!k4)
{
TR0=0;TR1=0;
num1=Sec[j];
j++;
}
}
if(k5==0)
{
delay1ms(10);
if(!k5){
j=3;num1=Sec[j];j--;
}
}
if(k6==0)
{delay1ms(10);
if(!k6)
{TR1=!TR1;
TR0=0;
}
}
}
void main()
{
lcd_init();
reset_T0();
EX0=0;
EA=1;
EX1=0;
TR0=0;
TR1=0;
while(1)
{
scan();
test();
}
}
void T0_time() interrupt 1
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
num0++;
if(num0==20)
{
num0=0;
if(num1==0)
num1=99;
num1-=1;
}
}
void T1_time() interrupt 3
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num0++;
if(num0==20)
{
num0=0;
if(num1==99)
num1=0;
num1+=1;
}
}
总共错误就3处,一个是没声明,一个是多一个;,还有一个m应该是mm,在我这里允许正常,没有错误,没有警告 。。。
sbit k1=P3^0;
sbit k2=P3^1;
sbit k3=P3^2;
sbit k4=P3^3;
sbit k5=P3^4;
sbit k6=P3^5;
sbit en=P2^2;
sbit rs=P2^0;
sbit rw=P2^1;
unsigned int num1=0;
unsigned int num0=0;
unsigned char i=0;
unsigned char j=0;
unsigned char dat3=0;
unsigned char dat4=0;
unsigned char Sec[4]={0,0,0,0};
#define uchar unsigned char
#define uint unsigned int
void lcd_wcom(uchar); //在这里声明了
void delay1ms(uint t)
{
uint a,b;
for(a=0;a<t;a++)
for(b=0;b<1000;b++);
}
void lcd_init()
{
lcd_wcom(0x38); //调用前要声明的
lcd_wcom(0x0c);
lcd_wcom(0x06);
lcd_wcom(0x01);
}
void lcd_wdat(uchar dat)
{
rs=1;
rw=0;
P0=dat;
delay1ms(1);
en=1;
en=0;
}
void scan()
{ dat4=num1/10;
dat3=num1%10;
lcd_wcom(0x80+0x40);
lcd_wdat(0x30+dat4);
lcd_wdat(0x30+dat3);
}
void lcd_wcom(uchar mm)//;
{
rs=0;
rw=0;
P0=mm; //这个m应该是mm吧
delay1ms(1);
en=1;
en=0;
}
void reset_T0()
{
TMOD=0x11;
TL0=0xfb;TH0=0xd8;
EA=1,ET0=1,ET1=1;
}
void test()
{
if(k1==0)
{
delay1ms(10);
if(!k1)
{
while(!k1)
{;}
TR0=!TR0;
TR1=0;
}
}
if(k2==0)
{
delay1ms(10);
if(!k2)
{
num1=0;
TR0=0;
TR1=0;
}
}
if(k3==0)
{
delay1ms(10);
if(!k3)
{
if(i==4)
{TR0=0;TR1=0;
}
Sec[i]=num1;
i++;
}
}
if(k4==0)
{
delay1ms(10);
if(!k4)
{
TR0=0;TR1=0;
num1=Sec[j];
j++;
}
}
if(k5==0)
{
delay1ms(10);
if(!k5){
j=3;num1=Sec[j];j--;
}
}
if(k6==0)
{delay1ms(10);
if(!k6)
{TR1=!TR1;
TR0=0;
}
}
}
void main()
{
lcd_init();
reset_T0();
EX0=0;
EA=1;
EX1=0;
TR0=0;
TR1=0;
while(1)
{
scan();
test();
}
}
void T0_time() interrupt 1
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
num0++;
if(num0==20)
{
num0=0;
if(num1==0)
num1=99;
num1-=1;
}
}
void T1_time() interrupt 3
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num0++;
if(num0==20)
{
num0=0;
if(num1==99)
num1=0;
num1+=1;
}
}
总共错误就3处,一个是没声明,一个是多一个;,还有一个m应该是mm,在我这里允许正常,没有错误,没有警告 。。。