单片机矩阵键盘扫描出现错误,求解答,在线等
#include<reg52.h>#defineucharunsignedchar#defineuintunsignedint#defineON0#defineOFF1s...
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define ON 0
#define OFF 1
sbit du=P2^6; //定义端口
sbit we=P2^7;
uchar code table[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,
0x79,0x71,0x00};
void delay(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=112;j>0;j--); //时间函数
}
void display(uchar num)
{
P0=table[num];
du=1;
du=0;
}
void keyscan4x4()
{
uchar temp,key;
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
swith(temp)
{
case 0xee;
key=0;
break;
case 0xde;
key=1;
break;
case 0xbe;
key=2;
break;
case 0x7e;
key=3;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
dispaly(key);
}
}
}
void main()
{
P0=0;
we=1;
we=0;
while(1)
{
keyscan4x4();
}
}
Build target 'Target 1'
compiling main.c...
MAIN.C(43): warning C206: 'swith': missing function-prototype
MAIN.C(43): error C267: 'swith': requires ANSI-style prototype
MAIN.C(44): error C141: syntax error near '{'
MAIN.C(45): error C141: syntax error near ';'
MAIN.C(47): error C171: 'break': missing enclosing loop
MAIN.C(49): error C141: syntax error near ';'
MAIN.C(51): error C171: 'break': missing enclosing loop
MAIN.C(53): error C141: syntax error near ';'
MAIN.C(55): error C171: 'break': missing enclosing loop
MAIN.C(57): error C141: syntax error near ';'
MAIN.C(59): error C171: 'break': missing enclosing loop
Target not created 展开
#define uchar unsigned char
#define uint unsigned int
#define ON 0
#define OFF 1
sbit du=P2^6; //定义端口
sbit we=P2^7;
uchar code table[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,
0x79,0x71,0x00};
void delay(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=112;j>0;j--); //时间函数
}
void display(uchar num)
{
P0=table[num];
du=1;
du=0;
}
void keyscan4x4()
{
uchar temp,key;
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
swith(temp)
{
case 0xee;
key=0;
break;
case 0xde;
key=1;
break;
case 0xbe;
key=2;
break;
case 0x7e;
key=3;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
dispaly(key);
}
}
}
void main()
{
P0=0;
we=1;
we=0;
while(1)
{
keyscan4x4();
}
}
Build target 'Target 1'
compiling main.c...
MAIN.C(43): warning C206: 'swith': missing function-prototype
MAIN.C(43): error C267: 'swith': requires ANSI-style prototype
MAIN.C(44): error C141: syntax error near '{'
MAIN.C(45): error C141: syntax error near ';'
MAIN.C(47): error C171: 'break': missing enclosing loop
MAIN.C(49): error C141: syntax error near ';'
MAIN.C(51): error C171: 'break': missing enclosing loop
MAIN.C(53): error C141: syntax error near ';'
MAIN.C(55): error C171: 'break': missing enclosing loop
MAIN.C(57): error C141: syntax error near ';'
MAIN.C(59): error C171: 'break': missing enclosing loop
Target not created 展开
3个回答
展开全部
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define ON 0
#define OFF 1
sbit du=P2^6; //定义端口
sbit we=P2^7;
uchar code table[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,
0x79,0x71,0x00};
void delay(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=112;j>0;j--); //时间函数
}
void display(uchar num)
{
P0=table[num];
du=1;
du=0;
}
void keyscan4x4()
{
uchar temp,key;
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:key=0;break;
case 0xde:
key=1;
break;
case 0xbe:
key=2;
break;
case 0x7e:
key=3;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
display(key);
}
}
}
void main()
{
P0=0;
we=1;
we=0;
while(1)
{
keyscan4x4();
}
}
只是把错误改了 switch 不是swith case 要加冒号 display 不是dispaly
#define uchar unsigned char
#define uint unsigned int
#define ON 0
#define OFF 1
sbit du=P2^6; //定义端口
sbit we=P2^7;
uchar code table[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,
0x79,0x71,0x00};
void delay(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=112;j>0;j--); //时间函数
}
void display(uchar num)
{
P0=table[num];
du=1;
du=0;
}
void keyscan4x4()
{
uchar temp,key;
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:key=0;break;
case 0xde:
key=1;
break;
case 0xbe:
key=2;
break;
case 0x7e:
key=3;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
display(key);
}
}
}
void main()
{
P0=0;
we=1;
we=0;
while(1)
{
keyscan4x4();
}
}
只是把错误改了 switch 不是swith case 要加冒号 display 不是dispaly
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
case 0xee;这个标点符号不对啊,要冒号的。
swith这个也拼错了吧?
switch(表达式){
case 常量表达式1: 语句1;
case 常量表达式2: 语句2;
…
case 常量表达式n: 语句n;
default: 语句n+1;
}
swith这个也拼错了吧?
switch(表达式){
case 常量表达式1: 语句1;
case 常量表达式2: 语句2;
…
case 常量表达式n: 语句n;
default: 语句n+1;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
……
temp=P3;
swith(temp)--是 switch...
{
……
temp=P3;
swith(temp)--是 switch...
{
……
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询