本帖最后由 why812182493 于 2013-12-23 20:15 编辑
实验板用的是TX-1C
单片机:STC89C52RC
代码如下:
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uchar code num[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void key(){
uint i,j;
uchar temp;
for(i=0;i<4;i++){ //矩阵键盘的四行,循环四次
temp=0xfe;
temp=_crol_(temp,i); //计算出P3口初值
P3=temp; //给P3口赋值
temp=P3; //读回P3口的值
if(temp&0xf0!=0xf0){ //判断是否有键被按下
temp=_crol_(temp,-4); //将高四位移动到低四位
for(j=0;temp%2!=0;temp/=2,j++); //判断低四位中哪一位是零
dula=1;
P0=num[j+i*4]; //设置段选
dula=0;
}
}
}
void main(){
wela=1;
P0=0; //初始化位选
wela=0;
while(1){
key();
}
}
编译提示:
Build target 'Target 1'
compiling temp.c...
temp.c(22): warning C294: unreachable code
linking...
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?CO?TEMP
Program Size: data=11.0 xdata=0 code=77
creating hex file from "temp"...
"temp" - 0 Error(s), 2 Warning(s).
请问两个警告具体是什么原因?
还有,我的代码有什么其他错误吗?
多谢了 |