如题:
#include <reg51.h>
//数据及端口定义模块
typedef unsigned char u8;
typedef unsigned int u16;
#define DATA P0
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
//延时模块
void delay(u16 num)
{
u16 x,y;
for(x=num;x>0;x--)
for(y=110;y>0;y--);
}
//共阴数码管_码表数组
u8 code seg_tab[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00
};
//74LS138译码
void bit_sel(u8 num)
{
switch(num)
{
case(1):
LSA=0;LSB=0;LSC=0; break;
case(2):
LSA=1;LSB=0;LSC=0; break;
case(3):
LSA=0;LSB=1;LSC=0; break;
case(4):
LSA=1;LSB=1;LSC=0; break;
case(5):
LSA=0;LSB=0;LSC=1; break;
case(6):
LSA=1;LSB=0;LSC=1; break;
case(7):
LSA=0;LSB=1;LSC=1; break;
case(8):
LSA=1;LSB=1;LSC=1; break;
}
}
//bit,DATA函数封装
void digdisplay(u8 bits,u8 datas)
{
for(bits=1;bits<9;bits++)
{
bit_sel(bits);
DATA=seg_tab[datas];
delay(1);
DATA=0x00;
}
}
//按键检测
u8 anjian(void)
{
u8 temp,temp2;
P1=0xf0;
temp=P1;
if(temp!=0xf0)
{
delay(5);
temp=P1;
if(temp!=0xf0)
{
temp2=temp & 0xf0;
P1=0x0f;
delay(5);
temp=P1;
temp2 |= temp;
return temp2;
}
}
}
//按键码表
void anjian_biao(u8 cod)
{
u8 num;
switch(cod)
{
case 0xee:num=0; break;
case 0xde:num=1; break;
case 0xbe:num=2; break;
case 0x7e:num=3; break;
case 0xed:num=4; break;
case 0xdd:num=5; break;
case 0xbd:num=6; break;
case 0x7d:num=7; break;
case 0xeb:num=8; break;
case 0xdb:num=9; break;
case 0xbb:num=10; break;
case 0x7b:num=11; break;
case 0xe7:num=12; break;
case 0xd7:num=13; break;
case 0xb7:num=14; break;
case 0x77:num=15; break;
default : break;
} //返回num的值
}
//主程序
void main(void)
{
u8 cod,num;
DATA=0xff;
P1=0xff;
while(1)
{
cod = anjian();
num=anjian_biao(cod);
digdisplay(1,num);
}
}
报错如下:
Build target 'Target 1'
compiling 模板.c...
模板.c(112): error C193: '=': illegal type conversion from/to 'void'
Target not created
请指点,
此帖出自
小平头技术问答
一周热门 更多>