微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > PCB设计问答 > PCB设计学习讨论 > 0808.C(425): error C141: syntax error near 'void'

0808.C(425): error C141: syntax error near 'void'

时间:10-02 整理:3721RD 点击:
想问问哪里错啊。
/*电子密码锁*/
#include<reg51.h>
#include<intrins.h>
#include<absacc.h>
#define uchar unsigned char
#define uint unsigned int
#define C02_write 0xa0 //c02 写地址
#define C02_read 0xa1 //c02 读地址
#define no0 0x28 //定义键码
#define no1 0x14
#define no2 0x24
#define no3 0x44
#define no4 0x12
#define no5 0x22
#define no6 0x42
#define no7 0x11
#define no8 0x21
#define no9 0x41
#define open 0x81
#define modify 0x82
#define enter 0x88
#define backspace 0x84
#define lcm_write_cmd_add XBYTE[0x80FF] //1602 控制地址
#define lcm_write_data_add XBYTE[0x81FF]
#define lcm_read_busy_add XBYTE[0x82FF]
uchar idata temp5_password[6]={0x00,0x00,0x00,0x00,0x00,0x00};
uchar idata key_code[]={no0,no1,no3,no4,no5,no6,no7,no8,no9};
sbit SCL=P3^0;
sbit SDA=P3^1;
sbit i=P3^2;
sbit led=P3^3;
sbit beep=P3^4;
bit ack;
void delay0(uchar x) // 延时函数
{
uchar i;
while(x--)
{
for (i = 0; i<13; i++);
}
}
void delayms(uchar i)
{
uchar j;
for(;i>0;i--)
for(j=124;j>0;j--);
}
void longdelay(uchar i)
{
uint j;
for(;i>0;i--)
for(j=10000;j>0;j--);
}
void keysound() //按键声音函数
{
uchar i;
for (i=0;i<180;i++)
{
delay0(5);
beep=!beep; //BEEP 取反
}
}
void alarm1() //报警函数
{
uchar k;
for (k=0; k<10; k++)keysound();
}
void lcm_wait()
{
while(lcm_read_busy_add&0x80); //读取 LCD 忙标志
}
void lcm_write_cmd(uchar lcm_cmd) //写控制字
{
lcm_wait();
lcm_write_cmd_add=lcm_cmd;
}
void lcm_write_data(uchar lcm_data) //写显示数据
{
lcm_wait();
lcm_write_data_add=lcm_data;
}
void lcm_setxy(uchar x,uchar y) //光标定位,x 定位字符位置,y 为行数
{
if(y==1) lcm_write_cmd(x|0x80); //定位第一行
if(y==2) lcm_write_cmd(x|0xc0); //定位第二行
}                                                                                               
void lcm_write_string(uchar *string) //字符串显示
{
uchar i=0;
while(string[i]!='\0')
{
lcm_write_data(string[i]);
i++;
}
}
void lcm_init() //LCD 初始化
{
delayms(20);
lcm_write_cmd_add=0x38;
delayms(4);
lcm_write_cmd_add=0x38;
delayms(1);
lcm_write_cmd_add=0x38;
lcm_write_cmd(0x38);
lcm_write_cmd(0x0f);
lcm_write_cmd(0x01);
lcm_write_cmd(0x06);
}
void I2C_start(void) //I2C 开始信号
{
SDA=1;
SCL=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SDA=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SCL=0;
_nop_();
_nop_();
}
void I2C_stop(void) //I2C 结束
{
SDA=0;
SCL=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SDA=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SCL=0;
_nop_();
_nop_();
}
void I2C_no_ackownledge(void) //发送 noack 信号
{
SDA=1;
_nop_();
_nop_();
SCL=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SCL=0;
_nop_();
_nop_();
_nop_();
}
void I2C_sendB(uchar byte) //发送一字节数据
{
uchar counter;
for(counter=0;counter<8;counter++)
{
if(byte&0x80) SDA=1;
else SDA=0;
_nop_();
SCL=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SCL=0;
_nop_();
_nop_();
byte<<=1;
}
_nop_();
_nop_();
SDA=1;
_nop_();
_nop_();
_nop_();
SCL=1;
_nop_();
_nop_();
_nop_();
if(SDA==0) ack=1;
else ack=0;
SCL=0;
_nop_();
_nop_();
}
uchar I2C_receiveB(void) //接受一字节数据
{
uchar temp;
uchar counter;
temp=0;
SDA=1;
_nop_();
_nop_();
for(counter=0;counter<8;counter++)
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SCL=1;
_nop_();
_nop_();
if(SDA==1) temp=(temp<<1)|0x01;
else temp=temp<<1;
_nop_();
_nop_();
SCL=0;
_nop_();
_nop_();
_nop_();
}
_nop_();
_nop_();
return(temp);
}
bit I2C_send_string(uchar *string,uchar no,uchar address) //发送六位密码
{
uchar counter;
for(counter=0;counter<no;counter++)
{
I2C_start();
I2C_sendB(C02_write);
if(ack==0) return(0);
I2C_sendB(address+counter);
if(ack==0) return(0);
I2C_sendB(string[counter]);
I2C_stop();
delayms(20);
}
return(1);
}
bit I2C_receive_string(uchar *string,uchar no,uchar address) //接受六位密码
{
uchar counter;
for(counter=0;counter<no;counter++)
{
I2C_start();
I2C_sendB(C02_write);
if(ack==0) return(0);
I2C_sendB(address+counter);
if(ack==0) return(0);
I2C_start();
I2C_sendB(C02_read);
if(ack==0) return(0);
*(string+counter)=I2C_receiveB();
I2C_no_ackownledge();
I2C_stop();
}
}
uchar get_key() //键盘扫描
{
uchar row_code;
uchar col_code;
P1=0xf0;
if(P1!=0xf0)
{
delayms(10);
if(P1!=0xf0)
{
row_code=0xfe;
while(row_code!=0xef)
{
P1=row_code;
if(P1!=row_code)
{ col_code=P1;
while(col_code==P1);
col_code=(col_code&0xf0)|0x0f;
return( (~col_code)|(~row_code));
}
row_code=((row_code<<1)|0x01);
}
}
}
return(0x00);
}
void convert_code(uchar *string) //密码转换
{
uchar counter=0;
for(counter=0;counter<6;counter++)
{
switch(*string)
{
case no0:
*string=0x00;
break;
case no1:
*string=0x01;
break;
case no2:
*string=0x02;
break;
case no3:
*string=0x03;
break;
case no4:
*string=0x04;
break;
case no5:
*string=0x05;
break;
case no6:
*string=0x06;
break;
case no7:
*string=0x07;
break;
case no8:
*string=0x08;
break;
case no9:
*string=0x09;
break;
default:
break;
}
string++;
}
}
bit compare_string(uchar *string1,uchar *string2) //密码比较
{
uchar counter;
for(counter=0;counter<6;counter++)
{
if(string1[counter]!=string2[counter]) return(0);
}
return(1);
}
uchar step_choose(void) //系统初始化
{
uint i;
uchar key;
do{
lcm_write_cmd(0x01);
lcm_write_cmd(0x06);
lcm_setxy(5,1);
lcm_write_string("welcome! ");
lcm_setxy(0,2);
lcm_write_string(" A:open B:modify ");
for(i=0;i<30000;i++)
{
key=get_key();
if((key==open)||(key==modify)) break;
}
}
while((key!=open)&&(key!=modify));
return(key);
}
bit input_password(uchar *password) //密码输入
{
uchar counter;
uchar key;
lcm_setxy(0,2);
for(counter=0;counter<7;counter++)
{
longdelay(3);
if(counter<6)
{
do{
key=get_key();
}
while(key==0x00);
if((key!=backspace)&&(key!=enter))
{
lcm_write_data('*');
keysound();
password[counter]=key;
}
if(key==backspace)
{
if(counter>0)
{
lcm_setxy(--counter,2);
lcm_write_data(' ');
password[counter]=0x00;
lcm_setxy(counter,2);
counter--;
keysound();
}
}
if(key==enter)
{
lcm_setxy(0,1);
keysound();
return(0);
}
}
if(counter==6)
{
do{
key=get_key();
}
while((key!=backspace)&&(key!=enter));
if(key==backspace)
{
lcm_setxy(--counter,2);
lcm_write_data(' ');
password[counter]=0x00;
lcm_setxy(counter,2);
counter--;
keysound();
}
if(key==enter)
{
keysound();
return(1);
}
}
void lock() //主函数
{
uchar key;
uchar error_counter_1;
uchar error_counter_2;
uchar idata temp1_password[6]={0,0,0,0,0,0};
uchar idata temp3_password[6]={0,0,0,0,0,0};
uchar idata temp2_password[6]={0,0,0,0,0,0};
uchar idata temp4_password[6]={0,0,0,0,0,0};
key=step_choose();
if(key==open)
{ keysound();
I2C_receive_string(temp1_password,6,0x00);
lcm_write_cmd(0x01);
lcm_write_cmd(0x06);
lcm_setxy(2,0);
lcm_write_string("input password");
if(input_password(temp2_password))
{
convert_code(temp2_password);
if(compare_string(temp1_password,temp2_password))
{
lcm_setxy(0,2);
lcm_write_string("correct! ");
led=0;
longdelay(20);
led=1;
return;
}
else
{
lcm_setxy(0,2);
lcm_write_string("error! ");
error_counter_1++ ;
if(error_counter_1<3)
{
alarm1();
}
else
{
while(1){
lcm_write_cmd(0x01);
lcm_write_cmd(0x06);
lcm_setxy(4,1);
lcm_write_string("warning! ");
keysound();
lcm_write_cmd(0x01);
lcm_write_cmd(0x06);
lcm_setxy(16,1);
lcm_write_string("");
longdelay(2);
}
}
return;
}
}
else
{
lcm_setxy(0,2);
lcm_write_string("less then 6! ");
longdelay(15);
}
}
else
{
keysound();
I2C_receive_string(temp1_password,6,0x00);
lcm_write_cmd(0x01);
lcm_write_cmd(0x06);
lcm_setxy(0,1);
lcm_write_string("input password ");
if(input_password(temp2_password))
{
convert_code(temp2_password);
if(compare_string(temp1_password,temp2_password))
{
lcm_setxy(0,2);
lcm_write_string("correct! ");
longdelay(10);
lcm_write_cmd(0x01);
lcm_write_cmd(0x06);
lcm_setxy(0,1);
lcm_write_string("new password ");
if(input_password(temp3_password))
{
lcm_write_cmd(0x01);
lcm_write_cmd(0x06);
lcm_setxy(0,1);
lcm_write_string("input again ");
if(input_password(temp4_password))
{
if(compare_string(temp3_password,temp4_password))
{
convert_code(temp3_password);
I2C_send_string(temp3_password,6,0x00);
lcm_write_cmd(0x01);
lcm_write_cmd(0x06);
lcm_setxy(2,1);
lcm_write_string("password has");
lcm_setxy(2,2);
lcm_write_string("been changed ");
longdelay(10);
return;
}
else
{
lcm_write_cmd(0x01);
lcm_write_cmd(0x06);
lcm_setxy(2,1);
lcm_write_string("twice input");
lcm_setxy(2,2);
lcm_write_string("is different! ");
longdelay(10);
return;
}
}
else
{
lcm_setxy(0,2);
lcm_write_string("less then 6 ! ");
longdelay(15);
return;
}
}
else
{
lcm_setxy(0,2);
lcm_write_string("less then 6 ! ");
longdelay(15);
return;
}
}
else
{
lcm_setxy(0,2);
lcm_write_string("error! ");
error_counter_2++ ;
if(error_counter_2<3)
{
alarm1();
}
else
{
while(1)
{
lcm_write_cmd(0x01);
lcm_write_cmd(0x06);
lcm_setxy(4,1);
lcm_write_string("warning! ");
keysound();
lcm_write_cmd(0x01);
lcm_write_cmd(0x06);
lcm_setxy(16,1);
lcm_write_string("");
longdelay(2);
}
}
return;
}
}
else
{
lcm_setxy(0,2);
lcm_write_string("less then 6 ! ");
longdelay(15);
return;
}
}
}
void int_service(void) using 0 interrupt 0 //密码初始化中断函数
{
EA=0;
EX0=0;
lcm_write_cmd(0x01);
lcm_write_cmd(0x06);
lcm_setxy(0,1);
lcm_write_string(" reset success! ");
longdelay(3);
I2C_send_string(temp5_password,6,0x00);
EA=1;
EX0=1;
return;
}
void main(void)
{
IT0=1;
EX0=1;
EA=1;
led=1;
lcm_init();
while(1)
{
lock();
}
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top