单片机 数码管动态显示代码

来源:百度知道 编辑:UC知道 时间:2024/05/10 13:23:45
我编了个单片机驱动数码管从000.0到999.9计数的程序
可是出现了在C程序在KEIL上运行的时候出现了这个错误error C213: left side of asn-op not an lvalue为什么???
我写的程序是这样的:

#include<at89x51.h>
void delay(void)
{
unsigned char m,n,s;
for(m=20;m>0;m--)
for(n=20;n>0;n--)
for(s=248;s>0;s--);
}

void main()
{
unsigned char i,j;
unsigned char led[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char Countnum[4]={0,0,0,0};
P0=0xff;
P2=0xff;
while(1)
{
i=0;
for(j=0;j<100;j++)
{
i=++i%4;
P2=~(1<<i);
if(i==2)
P1=led[0]=0x80;
else
P1=led[0];
delay();
P1|=0xff;
}

Countnum[0]=Countnum[1]=Countnum[2]=Countnum[3]=0;
while(1)
{
if(Countnum[3]++=9)
{
Countnum[3]=0;
if(Countnum[2]++=9)
{
Countnum[2]=0;
if(C

if(Countnum[3]++=9) 单片机里面判断是否相等是用==的而不是=
你应该写成if(Countnum[3]++==9)
而且你的写法和不规范,这个写法的意思是Countnum[3]是否等于9,然后Countnum[3]加1

其它的错误也是一样

我帮你修改后的程序编译结果0错误、0警告,,,我这里是修改语法、不检查你的逻辑功能,程序如下:
//------------------------------------------------------------------//
#include<at89x51.h>

void delay(void)
{
unsigned char m,n,s;
for(m=20;m>0;m--)
for(n=20;n>0;n--)
for(s=248;s>0;s--);
}

void main()
{
unsigned char i,j;
unsigned char led[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char Countnum[4]={0,0,0,0};
P0=0xff;
P2=0xff;
while(1)
{
i=0;
for(j=0;j<100;j++)
{
i=++i%4;
P2=~(1<<i);
if(i==2)
P1=led[0]=0x80;
else
P1=led[0];
delay();
P1|=0xff;
}
Co