微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > 错误已经很明确的标出

错误已经很明确的标出

时间:10-02 整理:3721RD 点击:
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit adca=P3^4;
sbit adcb=P3^5;
sbit adcc=P3^6;
sbit adcoe=P3^1;
sbit adcst=P3^0;
sbit adceoc=P3^2;
//数码管1——10
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uint t;
uchar temp1;
uchar code discount[3]={0x00,0x00,0x00};
void delay(uint z)
{
        uint x,y;
        for(x=z;x>0;x--)
                for(y=110;y>0;y--);
}
//定时器0初始化
void init()
{
        TMOD=0x01;
        TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;
        EA=1;
        TR0=1;
        ET0=1;
}
//adc0808 模数转换初始化
void init_adc()
{
        adcst=0;
        adcoe=0;
        adca=0;
        adcb=0;
        adcc=0;
        adceoc=0;
}
//adc0808 模数转换进行
uchar adc()
{
        uchar getdata;
        adcst=1;
        delay(2);
        adcst=0;
        delay(2);
        while(!adceoc);
        adcoe=1;
        getdata=P0;
        adcoe=0;
        return getdata;
}
//数码管显示
void shumaguan(uchar temp)
{
        uint i;
        discount[0]=temp/51;                                //此处出现了问题。  C(64-65):error C183: unmodifiable lvalue   -3 Error(s),0 warning (s).
        discount[1]=temp%51*10/51;
        discount[2]=(temp)%51*10%51*10/51;
        if(t==10);
        t=0;
        for(i=0;i<3;i++)
        {
                P1=_crol_(temp1,i);
                P2=discount[i];
        }
               
}
//主函数
void main()
{
        temp1=0xfe;
        init();
        init_adc();
        while(1)
        {
                shumaguan(adc());
        }
}
//定时0中断
void timer0() interrupt 1
{
        TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;
        t++;
}

uchar code discount[3]={0x00,0x00,0x00};你使用用code关键字,说明这些值是保存在代码区的,是不能进行修改的,即常量数组。你后面对它进行赋值当然是不行的!你应该定义为变量,去掉那个code关键字!

受教了,以后会更加注意细节。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top