标题: 求知,数码管程序编写时数组定义问题 [打印本页]

作者: 暮云雨    时间: 2015-3-25 16:36
标题: 求知,数码管程序编写时数组定义问题
#include<reg51.h>

unsigned char  code table1[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char  code table2[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char  code data[8];

void main()
{
        unsigned char code data[8];
        unsigned char i;
        unsigned int j;
                for(i=0;i<8;i++)
                {
                        data[i]=table2[i]
                }
                while(1)
                {
                        unsigned char a;
                        for(a=0;a<8;a++)
                        {
                                P1=table1[i];
                                P0=data[i];
                                j=10;
                                while(j--);
                                P0=0x00;
                }
        }
}

错误

compiling led1.c...
LED1.C(5): error C141: syntax error near 'data'
LED1.C(5): error C141: syntax error near '['
LED1.C(9): error C141: syntax error near 'data'
LED1.C(9): error C141: syntax error near '['
LED1.C(9): error C141: syntax error near ']'
LED1.C(10): error C141: syntax error near 'unsigned'
LED1.C(10): error C202: 'i': undefined identifier
LED1.C(11): error C141: syntax error near 'unsigned'
LED1.C(11): error C202: 'j': undefined identifier
LED1.C(12): error C202: 'i': undefined identifier
LED1.C(14): error C141: syntax error near '['
LED1.C(14): error C202: 'i': undefined identifier
LED1.C(15): error C141: syntax error near '}'
LED1.C(21): error C202: 'i': undefined identifier
LED1.C(22): error C141: syntax error near 'data'
LED1.C(22): error C202: 'i': undefined identifier
LED1.C(24): error C202: 'j': undefined identifier
Target not created



作者: liaolinhui    时间: 2015-3-26 00:29
unsigned char  code data[8];
这个不能用code,code是存在ROM里面的,不能改变值,而你这个是需要改变的,所以要去掉code
作者: 野强强    时间: 2015-3-26 14:17
楼上言之有理。。。
作者: 安阳市新世纪    时间: 2015-5-23 14:54
楼上说的是呀,通常来说常量都是放在单片机ROM里的,为了区别常量变量,51单片机code及存放在单片机ROM里




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1