我是一名学生,现在在自学的单片机,我遇到了一些问题希望可以有大神帮我解决一些非常感谢!
下面的程序 是控制一个16*16点阵显示屏,但程序在编译的时候总是显示编译错误,我想知道哪里错了
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit A=P0^0; //定义154脚管
sbit B_=P0^1;
sbit C=P0^2;
sbit D=P0^3;
sbit G=P0^7;
sbit SI=P0^6; //定义595
sbit RCK=P0^4;
sbit SCK=P0^5;
sbit N=P1^0;
uchar i=1,j=0;
uchar K=0;
void zhonduan();
void fir595();
void Write(uchar temp);
void write(uchar data1, uchar date2);
void QD(uchar Z );
void delay();
uchar code hanz[]={0x40,0x00,0x40,0x00,0x20,0x00,0x20,0xFE,0x50,0x42,0x48,0x42,0x44,0x42,0x43,0x42,
0x44,0x42,0x48,0x42,0x50,0x42,0x20,0xFE,0x20,0x00,0x40,0x00,0x40,0x00,0x00,0x00,/*"合",0*/
0x00,0x80,0x00,0x60,0xFE,0x1F,0x22,0x42,0x22,0x82,0xFE,0x7F,0x00,0x00,0xFE,0x3F,
0x82,0x40,0x82,0x40,0xFE,0x40,0x82,0x40,0x82,0x40,0xFE,0x41,0x00,0x70,0x00,0x00}/*"肥",1*/
uchar code shuz[]={ 0x00,0x00,0x00,0x00,0x10,0x20,0x10,0x20,0xF8,0x3F,0x00,0x20,0x00,0x20,0x00,0x00,
0x00,0x00,0x70,0x30,0x08,0x28,0x08,0x24,0x08,0x22,0x08,0x21,0xF0,0x30,0x00,0x00,
0x00,0x00,0x30,0x18,0x08,0x20,0x08,0x21,0x08,0x21,0x88,0x22,0x70,0x1C,0x00,0x00,
0x00,0x00,0x00,0x06,0x80,0x05,0x40,0x24,0x30,0x24,0xF8,0x3F,0x00,0x24,0x00,0x24}
uchar code tp[]={0x00,0x00,0x00,0x00,0xFC,0x00,0x84,0x01,0x04,0x03,0x04,0x04,0x08,0x08,0x10,0x10,
0x10,0x10,0x08,0x08,0x04,0x04,0x04,0x02,0x84,0x01,0xFC,0x00,0x00,0x00,0x00,0x00}//爱心
void zhonduan()//复位和选择
{
if(N==0)
{
delay();
if(N==0)
{
K++;
if(K>=3)
{
K=0;
fir595();
i=1;
j=0;
X=0;
while(!N);
}
}
}
}
void main()
{
while(1);
{
fir595();
if(N==0)//显示图片
{
for (j=0;j<2;j++)
{
for(i=1;i<17;i++)
{
write(hanz[i*2], hanz[i*2-1]);//显示一列或者一行
QD(i);
delay();
G=0;
fir595();
}
}
}
else if(N==0)//显示文字
{
for (j=0;j<2;j++)
{
for(i=1;i<17;i++)
{
write(shuz[i*2], shuz[i*2-1]);//显示一列或者一行
QD(i);
delay();
G=0;//关闭
fir595();
}
}
}
else if(N==0) //显示图片
{
for (j=0;j<2;j++)
{
for(i=1;i<17;i++)
{
write(tp[i*2], tp[i*2-1]);//显示一列或者一行
QD(i);
delay();
G=0;
fir595();
}
}
}
}
}
void fir595() //595芯片初始化
{
SI=1;
SCK=0;
RCK=0;
}
void Write(uchar temp)//595写入驱动
{
uchar i,data_=temp;
G=1;
for(i=0;i<8;i++)//进行传值
{
if(data_&0x01==0x01)
SI=1;
else
SI=0;
SCK=0;//产生上升沿
SCK=1;
SCK=0;
data_>>=1;
}
RCK=0;//显示
RCK=1;
RCK=0;
}
void write(uchar data1, uchar date2)//显示一列或者一行
{
Write(date2);
Write(date1);
}
void QD(uchar Z )//154芯片写入驱动 满足条件的开启对应的行
{
G=0;
switch(Z)
{
case 16 :
{
A=1;
B_=1;
C=1;
D=1;
break;
}
case 15 :
{
A=0;
B_=1;
C=1;
D=1;
break;
}
case 14 :
{
A=1;
B_=0;
C=1;
D=1;
break;
}
case 13 :
{
A=0;
B_=0;
C=1;
D=1;
break;
}
case 12 :
{
A=1;
B_=1;
C=0;
D=1;
break;
}
case 11 :
{
A=0;
B_=1;
C=0;
D=1;
break;
}
case 10 :
{
A=1;
B_=0;
C=0;
D=1;
break;
}
case 9 :
{
A=0;
B_=0;
C=0;
D=1;
break;
} case 8 :
{
A=1;
B_=1;
C=1;
D=0;
break;
}
case 7 :
{
A=0;
B_=1;
C=1;
D=0;
break;
} case 6 :
{
A=1;
B_=0;
C=1;
D=0;
break;
} case 5 :
{
A=0;
B_=0;
C=1;
D=0;
break;
} case 4 :
{
A=1;
B_=1;
C=0;
D=0;
break;
} case 3 :
{
A=0;
B_=1;
C=0;
D=0;
break;
} case 2 :
{
A=1;
B_=0;
C=0;
D=0;
break;
} case 1 :
{
A=0;
B_=0;
C=0;
D=0;
break;
}
}
}
void delay()//延时
{
uchar a=5000;
while(a--);
}
评论
查看更多