本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
程序如下,它老是显示 error C237: 'main': function already has a body,请牛人看看
#include<reg52.h>
#include<I2C.h>
#define key_point P3
#define disp_point P0
#define shu_1 P2^5
#define shu_2 P2^6
#define shu_3 P2^7
#define DA P1
sbit speaker=P2^3;
sfr WDTRST = 0xA6;
static bit select=0; static bit save=0; static bit read_bit=0;static bit fengmin=0;
unsigned char led_0[10]={0xa0,0xbb,0x62,0x2a,0x39,0x2c,0x24,0xba,0x20,0x28};
unsigned char led_1[10]={0x80,0x9b,0x42,0x0a,0x19,0x0c,0x04,0x9a,0x00,0x08};
unsigned char dispbuf[3];
static unsigned char bit_judge=0;
static unsigned char num=0;
static unsigned char num1=0;
static unsigned char num2=0;
static unsigned char num3=0;
static unsigned char msecond=0;
static unsigned char second=0;
void delay10ms(void);
void cancel(void);
void num_key(unsigned char shuma);
void ledwork(void);
void key(void);
unsigned char buchang(unsigned char caozuoshu);
main(void)
{
speaker=1;
WDTRST=0x1E;
WDTRST=0xE1;
TMOD=0x11;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=0;
DA=0;
while(1)
{
WDTRST=0x1E;
WDTRST=0xE1;
key();
}
}
void delay10ms(void)
{ unsigned char i,j;
for(i=10;i>0;i--)
for(j=248;j>0;j--);
}
void cancel(void)
{unsigned char temp;
temp=num;
num1=temp/100;
temp=num;
num2=temp/10%10;
temp=num;
num3=temp%10;
}
unsigned char buchang(unsigned char caozuoshu)
{ if(caozuoshu>50&&caozuoshu<60)caozuoshu++;
if(caozuoshu>73&&caozuoshu<75)caozuoshu+=2;
if(caozuoshu>82&&caozuoshu<140)caozuoshu+=3;
if(caozuoshu>141&&caozuoshu<200)caozuoshu+=5;
if(caozuoshu>201)caozuoshu+=8;
return caozuoshu;
}
void num_key(unsigned char shuma)
{if(select)
{if(++bit_judge>=4)bit_judge=1;
switch(bit_judge)
{case 1: num1=shuma;break;
case 2: num2=shuma;break;
case 3: num3=shuma;break;
}
}
else if(save)
{write(shuma,num);
save=0;
fengmin=1;
speaker==0;
}
else {read_bit=1;
num=read(shuma);
cancel();
}
}
void ledwork(void)
{unsigned char i;
shu_1=1;
shu_2=1;
shu_3=1;
switch(i)
{case 0:{if(select==1)
{if(bit_judge==0||bit_judge==3&&msecond<5)shu_1=1;
else shu_1=0;}
else if(save&&msecond>15)shu_1=1;
else if(read_bit&&msecond>15)shu_1=1;
else shu_1=0;
disp_point=led_0[dispbuf];}
break;
case 1:{if(select)
{if(bit_judge<2||bit_judge==3&&msecond<5)shu_2=1;
else shu_2=0;}
else if(save&&msecond>15)shu_2=1;
else if(read_bit&&msecond>15)shu_2=1;
else shu_2=0;
disp_point=led_1[dispbuf];}
break;
case 2:{if(select)
{if(bit_judge<3||bit_judge==3&&msecond<5)shu_3=1;
else shu_3=0;}
else if(save&&msecond>15)shu_3=1;
else if(read_bit&&msecond>15)shu_3=1;
else shu_3=0;
disp_point=led_0[dispbuf];}
break;
}
if(++i>=3)i=0;
}
void key(void)
{unsigned char X,Y,Z,temp;
key_point=0xff;
key_point=0x0f;
if(key_point!=0x0f)
{delay10ms();
if(key_point!=0x0f)
{
X=key_point;
key_point=0xf0;
Y=key_point;
Z=X|Y;
}
}
else Z=0;
key_point=0x0f;
while(key_point!=0x0f)
{WDTRST=0x1E;
WDTRST=0xE1;}
delay10ms();
TR1=1;
switch(Z)
{case 0x00: break;
case 0xee: num_key(0); break;
case 0xde: num_key(1); break;
case 0xbe: num_key(2); break;
case 0x7e: num_key(3); break;
case 0xed: num_key(4); break;
case 0xdd: num_key(5); break;
case 0xbd: num_key(6); break;
case 0x7d: num_key(7); break;
case 0xeb: num_key(8); break;
case 0xdb: num_key(9); break;
case 0xbb: if(read_bit==0&&save==0)
{select=1;bit_judge=0;}break;
case 0x7b: {select=0;
read_bit=0;
if(num1<3)
if(num1!=2||num2<5)
{temp=num1;
num=temp*100;
temp=num2;
num+=temp*10;
temp=num3;
num+=temp;
temp=num;
DA=buchang(temp);
speaker=0;
fengmin=1;}
cancel();}break;
case 0xe7: {if(num>0&&save==0)
{temp=--num;
DA=buchang(temp);}
cancel();
TR1=0;}break;
case 0xd7: {if(num<240&&save==0)
{temp=++num;
DA=buchang(temp);}
cancel();
TR1=0;}break;
case 0xb7: if(select==0&&read_bit==0)save=1;break;
case 0x77: while(1);break;
}
}
void disp(void) interrupt 1
{TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
dispbuf[0]=num1;
dispbuf[1]=num2;
dispbuf[2]=num3;
ledwork();
}
void time(void) interrupt 3
{TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
if(++msecond>=21)msecond=0;
if(fengmin)
if(++second>=6){second=0;fengmin=0;speaker=1;TR1=0;}
}
#ifndef _I2C_H_
#define _I2C_H_
sbit a0=ACC^0;
sbit a1=ACC^1;
sbit a2=ACC^2;
sbit a3=ACC^3;
sbit a4=ACC^4;
sbit a5=ACC^5;
sbit a6=ACC^6;
sbit a7=ACC^7;
sbit scl=P2^2;
sbit sda=P2^0;
unsigned char rd24(void) ;
void write(unsigned char address,unsigned char dd);
void s24(void);
void p24(void);
void clock();
void wd24(unsigned char dd);
unsigned char read(unsigned char address);
#endif
void somenop(void)
{_nop_();_nop_();_nop_();_nop_();_nop_();}
void s24(void) {
EA=0;somenop();scl=0;sda=1;scl=1;somenop();sda=0;somenop();scl=0;
}
void p24(void)
{
sda=0;scl=1;somenop();sda=1;EA=1;
}
unsigned char rd24(void)
{
sda=1;
scl=1;a7=sda;scl=0;
scl=1;a6=sda;scl=0;
scl=1;a5=sda;scl=0;
scl=1;a4=sda;scl=0;
scl=1;a3=sda;scl=0;
scl=1;a2=sda;scl=0;
scl=1;a1=sda;scl=0;
scl=1;a0=sda;scl=0;
sda=1;scl=1;scl=0;
return(ACC);
}
void wd24(unsigned char dd)
{
ACC=dd;
sda=a7;scl=1;scl=0;
sda=a6;scl=1;scl=0;
sda=a5;scl=1;scl=0;
sda=a4;scl=1;scl=0;
sda=a3;scl=1;scl=0;
sda=a2;scl=1;scl=0;
sda=a1;scl=1;scl=0;
sda=a0;scl=1;scl=0;
sda=1;scl=1;
}
void clock()
{
unsigned char i=0;
scl=1; somenop();
while ((sda==1)&&(i<255))i++;
scl=0; somenop();
}
unsigned char read(unsigned char address)
{
unsigned char dd;
s24();wd24((address<<1)|0x01);clock();dd=rd24();p24();return(dd);
}
void write(unsigned char address,unsigned char dd)
{
s24();wd24((address<<1)&0xfe);clock();wd24(dd);clock();p24();
} |