你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

帮忙看一下数组的const怎么用才对

[复制链接]
konway 提问时间:2016-12-24 09:11 /
本帖最后由 konway 于 2016-12-24 15:36 编辑

程序原本是51程序,移到STM32的时候有个地方报错:
unsugned char code bmp[]={
                 //0, 8 ;<<----Row count(DB format)
                 //0, 128 ;<<----Column count(DB format)
    0x00,0x00,0x00,0x10,0x61,0x06,0xE0,0x00,0x26,0x22,0x1A,0x02,0xC2,0x0A,0x12,0x32,0x06,0x02,0x00,0x10,0x10,0x10,0xFE,0x10,  
    0x10,0xFE,0x00,0x00,0xFC,0x00,0x00,0x00,0xFE,0x00,0x00,0x04,0x04,0x04,0xE4,0x24,0x24,0x25,0xFE,0x24,0x24,0x24,0x24,0xE4,  
    0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x7E,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x7E,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0xFA,0xAA,  
    0xAA,0xAA,0xFF,0xAA,0xAA,0xAA,0xFA,0x02,0x02,0x00,0x00,0x40,0x41,0xCE,0x04,0x00,0xF0,0x90,0x90,0x90,0xFF,0x90,0x90,0x90,  
    0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0xFC,0x03,0x20,0x20,0x11,0x11,0x09,0x05,0xFF,0x05,0x09,0x19,  
    0x31,0x10,0x00,0x08,0x08,0x04,0x47,0x24,0x18,0x07,0x00,0x00,0x1F,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,  
    0x00,0x00,0xFF,0x00,0x00,0x10,0x20,0x1F,0x00,0x00,0x00,0x00,0x7F,0x25,0x25,0x25,0x25,0x7F,0x00,0x00,0x7F,0x25,0x25,0x25,  
    0x25,0x7F,0x00,0x00,0x42,0x72,0x02,0x3A,0x42,0x42,0x4B,0x52,0x42,0x62,0x02,0x13,0x66,0x00,0x00,0x40,0x20,0x1F,0x20,0x40,  
    0x5F,0x48,0x48,0x48,0x4F,0x48,0x48,0x48,0x5F,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
    0x00,0xE0,0x20,0x20,0x20,0x20,0xFC,0x20,0x20,0x20,0x20,0xE0,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x88,0x48,  
    0x28,0x18,0x08,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x90,0xD0,0xB0,0x9C,0x90,0x90,0x90,0x90,0x10,0x10,0x10,0x00,0xF8,  
    0x08,0xC8,0x38,0x08,0x00,0xF8,0x28,0x28,0x28,0x28,0x28,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x38,0x10,0x00,0x00,  
    0x38,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x40,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x08,0x08,0xF8,0x00,0x00,0x00,  
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x11,0x11,0x11,0x11,0xFF,0x11,0x11,0x11,0x11,0x3F,0x00,0xC0,0x00,0x04,  
    0x04,0x04,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x06,0x04,0x00,0x08,0x04,0x02,0x01,0xFF,0x24,0x24,0x24,0xA4,  
    0x24,0x24,0xFF,0x00,0x00,0x00,0x00,0xFF,0x00,0x08,0x11,0x0E,0x00,0xFF,0x01,0x83,0x0D,0x31,0x49,0x85,0x80,0x80,0x00,0x00,  
    0x04,0x82,0xC1,0xA0,0x90,0x8E,0xC4,0x40,0x40,0x50,0xE1,0xC3,0x06,0x02,0x00,0x00,0x00,0x7E,0x12,0x12,0x12,0x12,0x12,0x12,  
    0x3E,0x00,0x80,0x00,0xFF,0x00,0x00,0x00,0xE0,0x10,0x10,0x10,0x10,0x70,0x00,0x10,0xF0,0x10,0x00,0x00,0x10,0xF0,0x10,0x10,  
    0xF0,0x10,0x10,0xD0,0x10,0x20,0x00,0x10,0xF0,0x60,0x80,0x00,0x10,0xF0,0x10,0x20,0x10,0x10,0x10,0x90,0x70,0x10,0x00,0x11,  
    0xF1,0x11,0x01,0x01,0x11,0xF1,0x10,0x10,0xF0,0x10,0x10,0xD0,0x11,0x22,0x01,0x10,0xF0,0x60,0x80,0x00,0x10,0xF0,0x10,0x00,  
    0x00,0x10,0x10,0xF3,0x10,0x10,0x00,0x10,0x11,0xF3,0x11,0x10,0x00,0x10,0xF0,0x63,0x80,0x00,0x10,0xF0,0x10,0x83,0x61,0x10,  
    0x10,0x10,0x70,0x00,0x11,0xF0,0x10,0x00,0x00,0x10,0xF1,0x10,0x10,0xF0,0x10,0x00,0x00,0x10,0xF1,0x10,0x00,0x10,0x10,0xF0,  
    0x10,0x10,0x00,0x10,0xF0,0x10,0x10,0x10,0x20,0xC0,0x00,0x11,0x10,0xF0,0x10,0x10,0x70,0x41,0x42,0x42,0x44,0x38,0x00,0x40,  
    0x7F,0x42,0x02,0x02,0x42,0x7F,0x40,0x40,0x7F,0x41,0x41,0x47,0x40,0x30,0x00,0x40,0x7F,0x40,0x01,0x0E,0x30,0x7F,0x00,0x40,  
    0x70,0x4C,0x42,0x41,0x40,0x30,0x00,0x40,0x7F,0x42,0x02,0x02,0x42,0x7F,0x40,0x40,0x7F,0x41,0x41,0x47,0x40,0x30,0x00,0x40,  
    0x7F,0x40,0x01,0x0E,0x30,0x7F,0x00,0x80,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x40,0x40,0x7F,0x40,0x40,0x00,0x40,0x7F,0x40,  
    0x01,0x0E,0x30,0x7F,0x00,0x0F,0x30,0x40,0x40,0x44,0x3C,0x04,0x40,0x7F,0x42,0x02,0x02,0x42,0x7F,0x40,0x00,0x3F,0x40,0x40,  
    0x40,0x40,0x3F,0x00,0x00,0x40,0x40,0x7F,0x40,0x40,0x00,0x40,0x7F,0x40,0x40,0x40,0x20,0x1F,0x00,0x40,0x40,0x7F,0x40,0x40,  
    0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,  
    0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,  
    0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x01,0xC1,0x31,0x09,0x08,0x08,0x38,0x00,0x00,  
    0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,  
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x08,0xF8,  
    0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,  
    0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,  
    0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,  
    0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,  
    0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,0x30,0x30,0x00,0x80,0xB0,0x70,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,0x00,  
    0x20,0x3F,0x20,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,0x30,0x30,
};
调用它的程序是:
void showpic(char *k)
{
        int i,j;
        for(i=0;i<8;i++)
        {
            
            for(j=0;j<128;j++)
        {
            write_data(*k++);
        }
        }
}

调用时:
showpic(bmp);
在keil 51时编译没问题。
=================================
下面看看STM32后的问题:
const unsigned char  bmp[]={
                 //0, 8 ;<<----Row count(DB format)
                 //0, 128 ;<<----Column count(DB format)
    0x00,0x00,0x00,0x10,0x61,0x06,0xE0,0x00,0x26,0x22,0x1A,0x02,0xC2,0x0A,0x12,0x32,0x06,0x02,0x00,0x10,0x10,0x10,0xFE,0x10,  
    0x10,0xFE,0x00,0x00,0xFC,0x00,0x00,0x00,0xFE,0x00,0x00,0x04,0x04,0x04,0xE4,0x24,0x24,0x25,0xFE,0x24,0x24,0x24,0x24,0xE4,  
    0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x7E,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x7E,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0xFA,0xAA,  
    0xAA,0xAA,0xFF,0xAA,0xAA,0xAA,0xFA,0x02,0x02,0x00,0x00,0x40,0x41,0xCE,0x04,0x00,0xF0,0x90,0x90,0x90,0xFF,0x90,0x90,0x90,  
    0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0xFC,0x03,0x20,0x20,0x11,0x11,0x09,0x05,0xFF,0x05,0x09,0x19,  
    0x31,0x10,0x00,0x08,0x08,0x04,0x47,0x24,0x18,0x07,0x00,0x00,0x1F,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,  
    0x00,0x00,0xFF,0x00,0x00,0x10,0x20,0x1F,0x00,0x00,0x00,0x00,0x7F,0x25,0x25,0x25,0x25,0x7F,0x00,0x00,0x7F,0x25,0x25,0x25,  
    0x25,0x7F,0x00,0x00,0x42,0x72,0x02,0x3A,0x42,0x42,0x4B,0x52,0x42,0x62,0x02,0x13,0x66,0x00,0x00,0x40,0x20,0x1F,0x20,0x40,  
    0x5F,0x48,0x48,0x48,0x4F,0x48,0x48,0x48,0x5F,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
    0x00,0xE0,0x20,0x20,0x20,0x20,0xFC,0x20,0x20,0x20,0x20,0xE0,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x88,0x48,  
    0x28,0x18,0x08,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x90,0xD0,0xB0,0x9C,0x90,0x90,0x90,0x90,0x10,0x10,0x10,0x00,0xF8,  
    0x08,0xC8,0x38,0x08,0x00,0xF8,0x28,0x28,0x28,0x28,0x28,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x38,0x10,0x00,0x00,  
    0x38,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x40,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x08,0x08,0xF8,0x00,0x00,0x00,  
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x11,0x11,0x11,0x11,0xFF,0x11,0x11,0x11,0x11,0x3F,0x00,0xC0,0x00,0x04,  
    0x04,0x04,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x06,0x04,0x00,0x08,0x04,0x02,0x01,0xFF,0x24,0x24,0x24,0xA4,  
    0x24,0x24,0xFF,0x00,0x00,0x00,0x00,0xFF,0x00,0x08,0x11,0x0E,0x00,0xFF,0x01,0x83,0x0D,0x31,0x49,0x85,0x80,0x80,0x00,0x00,  
    0x04,0x82,0xC1,0xA0,0x90,0x8E,0xC4,0x40,0x40,0x50,0xE1,0xC3,0x06,0x02,0x00,0x00,0x00,0x7E,0x12,0x12,0x12,0x12,0x12,0x12,  
    0x3E,0x00,0x80,0x00,0xFF,0x00,0x00,0x00,0xE0,0x10,0x10,0x10,0x10,0x70,0x00,0x10,0xF0,0x10,0x00,0x00,0x10,0xF0,0x10,0x10,  
    0xF0,0x10,0x10,0xD0,0x10,0x20,0x00,0x10,0xF0,0x60,0x80,0x00,0x10,0xF0,0x10,0x20,0x10,0x10,0x10,0x90,0x70,0x10,0x00,0x11,  
    0xF1,0x11,0x01,0x01,0x11,0xF1,0x10,0x10,0xF0,0x10,0x10,0xD0,0x11,0x22,0x01,0x10,0xF0,0x60,0x80,0x00,0x10,0xF0,0x10,0x00,  
    0x00,0x10,0x10,0xF3,0x10,0x10,0x00,0x10,0x11,0xF3,0x11,0x10,0x00,0x10,0xF0,0x63,0x80,0x00,0x10,0xF0,0x10,0x83,0x61,0x10,  
    0x10,0x10,0x70,0x00,0x11,0xF0,0x10,0x00,0x00,0x10,0xF1,0x10,0x10,0xF0,0x10,0x00,0x00,0x10,0xF1,0x10,0x00,0x10,0x10,0xF0,  
    0x10,0x10,0x00,0x10,0xF0,0x10,0x10,0x10,0x20,0xC0,0x00,0x11,0x10,0xF0,0x10,0x10,0x70,0x41,0x42,0x42,0x44,0x38,0x00,0x40,  
    0x7F,0x42,0x02,0x02,0x42,0x7F,0x40,0x40,0x7F,0x41,0x41,0x47,0x40,0x30,0x00,0x40,0x7F,0x40,0x01,0x0E,0x30,0x7F,0x00,0x40,  
    0x70,0x4C,0x42,0x41,0x40,0x30,0x00,0x40,0x7F,0x42,0x02,0x02,0x42,0x7F,0x40,0x40,0x7F,0x41,0x41,0x47,0x40,0x30,0x00,0x40,  
    0x7F,0x40,0x01,0x0E,0x30,0x7F,0x00,0x80,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x40,0x40,0x7F,0x40,0x40,0x00,0x40,0x7F,0x40,  
    0x01,0x0E,0x30,0x7F,0x00,0x0F,0x30,0x40,0x40,0x44,0x3C,0x04,0x40,0x7F,0x42,0x02,0x02,0x42,0x7F,0x40,0x00,0x3F,0x40,0x40,  
    0x40,0x40,0x3F,0x00,0x00,0x40,0x40,0x7F,0x40,0x40,0x00,0x40,0x7F,0x40,0x40,0x40,0x20,0x1F,0x00,0x40,0x40,0x7F,0x40,0x40,  
    0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,  
    0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,  
    0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x01,0xC1,0x31,0x09,0x08,0x08,0x38,0x00,0x00,  
    0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,  
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x08,0xF8,  
    0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,  
    0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,  
    0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,  
    0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,  
    0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,0x30,0x30,0x00,0x80,0xB0,0x70,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,0x00,  
    0x20,0x3F,0x20,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,0x30,0x30,
};

调用的子程序:
void showpic1(unsigned char *k)
{
        int i,j;
        for(i=0;i<8;i++)
        {
            
            for(j=0;j<128;j++)
                {
                        write_data(*k++);
                }
        }  
}

按以下写法调用时报错。
提示:../Src/main.c(175): error:  #167: argument of type "const unsigned char *" is incompatible with parameter of type "unsigned char *"
===============================================

showpic(bmp);
===================
把const去掉,编译就OK,可是我又想把这个数组放在FLASH里,该怎么写才正确??
收藏 1 评论3 发布时间:2016-12-24 09:11

举报

3个回答
wenyangzeng 回答时间:2016-12-24 10:24:24
void showpic1((const unsigned char *)k)

评分

参与人数 1ST金币 +2 收起 理由
zero99 + 2

查看全部评分

霹雳之火 回答时间:2016-12-24 13:05:52
可以按楼上的修改试试
konway 回答时间:2016-12-24 15:36:11
wenyangzeng 发表于 2016-12-24 10:24
void showpic1((const unsigned char *)k)

that is ok,TKS!

所属标签

相似问题

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32Cube扩展软件包
意法半导体边缘AI套件
ST - 理想汽车豪华SUV案例
ST意法半导体智能家居案例
STM32 ARM Cortex 32位微控制器
关注我们
st-img 微信公众号
st-img 手机版