利用单片机AT89C518只数码管闪烁显示的C语言,谁能告诉我哪错了
来源:百度知道 编辑:UC知道 时间:2024/06/27 07:12:04
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code DSY_CODE[]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
};
uchar code DSY_IDX[]=
{
0x01;0x02;0x04;0x08;0x10;0x20;0x40;0x80
}
void DelayMS(uint x)
{
uchar t;
while(x--)
{
for(t=120;t>0;t--);
}
}
void main()
{
uchar k,m;
P0=0xff;
P2=0x00;
while(1)
{
for(k=0;k<30;k++)
{
for(m=0;m<8;m++)
{
P2=code DSY_IDX[k];
P0=DSY_CODE[m];
DelayMS(2);
}
}
P2=0x00;
DelayMS(1000);
}
}
#define uchar unsigned char
#define uint unsigned int
uchar code DSY_CODE[]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
};
uchar code DSY_IDX[]=
{
0x01;0x02;0x04;0x08;0x10;0x20;0x40;0x80
}
void DelayMS(uint x)
{
uchar t;
while(x--)
{
for(t=120;t>0;t--);
}
}
void main()
{
uchar k,m;
P0=0xff;
P2=0x00;
while(1)
{
for(k=0;k<30;k++)
{
for(m=0;m<8;m++)
{
P2=code DSY_IDX[k];
P0=DSY_CODE[m];
DelayMS(2);
}
}
P2=0x00;
DelayMS(1000);
}
}
P2=code DSY_IDX[k];
P0=DSY_CODE[m];
code DSY_IDX 是个啥东西 吧code去掉
uchar code DSY_IDX[]=
{
0x01;0x02;0x04;0x08;0x10;0x20;0x40;0x80
}
里面的分号改成逗号,最后的花括号后加分号
code DSY_IDX 把code去掉,语法有误
for(k=0;k<30;k++)
{
for(m=0;m<8;m++)
{
P2=DSY_IDX[k];
DSY_IDX[]里面没有30个数据,会溢界,改成for(k=0;k<10;k++)
DelayMS(2)似乎太短,如果LED全亮,就加大这个延时。
P2=code DSY_IDX[k];
P0=DSY_CODE[m];
改为:P2=code DSY_IDX[m];
P0=DSY_CODE[m];