CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

const char array

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
octopuss83



Joined: 06 Nov 2011
Posts: 13

View user's profile Send private message

const char array
PostPosted: Thu Dec 20, 2012 2:15 am     Reply with quote

Hello,

I try to set up an array of ascii character for display 7 segment, this is a part of my code:
Code:

const char SMAP []= {
   0b00000000, // 032 SPACE
   0b00110000, // 033 !
   0b00100010, // 034 "
   0b01000001, // 035 #
   0b01101101, // 036 $
   0b01010010, // 037 %
   0b01111100, // 038 &
   0b00100000, // 039 '
   0b00111001, // 040 (
   0b00001111, // 041 )
   0b00100001, // 042 *
   0b01110000, // 043 +
   0b00001000, // 044 ,
   0b01000000, // 045 -
   0b00001000, // 046 .
   0b01010010, // 047 /
   0b00111111, // 048 0
   0b00000110, // 049 1
   0b01011011, // 050 2
   0b01001111, // 051 3
   0b01100110, // 052 4
   0b01101101, // 053 5
   0b01111101, // 054 6
   0b00000111, // 055 7
   0b01111111, // 056 8
   0b01101111, // 057 9
   0b01001000, // 058 :
   0b01001000, // 059 ;
   0b00111001, // 060 <
   0b01001000, // 061 =
   0b00001111, // 062 >
   0b001010011, // 063 ?
   0b001011111, // 064 @
   0b001110111, // 065 A
   0b001111100, // 066 B
   0b00111001, // 067 C
   0b01011110, // 068 D
   0b01111001, // 069 E
   0b01110001, // 070 F
   0b00111101, // 071 G
   0b01110110, // 072 H
   0b00000110, // 073 I
   0b00011110, // 074 J
   0b01110110, // 075 K
   0b00111000, // 076 L
   0b00010101, // 077 M
   0b00110111, // 078 N
   0b00111111, // 079 O
   0b01110011, // 080 P
   0b01100111, // 081 Q
   0b00110001, // 082 R
   0b01101101, // 083 S
   0b01111000, // 084 T
   0b00111110, // 085 U
   0b00011100, // 086 V
   0b00101010, // 087 W
   0b01110110, // 088 X
   0b01101110, // 089 Y
   0b01011011, // 090 Z
   0b00111001, // 091 [
   0b01100100, // 092 0bACKSLASH (0backslash character in code means line continuation)
   0b00001111, // 093 ]
   0b00100011, // 094 ^
   0b00001000, // 095 _
   0b00100000, // 096 `
   0b01110111, // 097 a
   0b01111100, // 098 b
   0b01011000, // 099 c
   0b01011110, // 100 d
   0b01111001, // 101 e
   0b01110001, // 102 f
   0b01101111, // 103 g
   0b01110100, // 104 h
   0b00000100, // 105 i
   0b00011110, // 106 j
   0b01110110, // 107 k
   0b00011000, // 108 l
   0b00010101, // 109 m
   0b01010100, // 110 n
   0b01011100, // 111 o
   0b01110011, // 112 p
   0b01100111, // 113 q
   0b01010000, // 114 r
   0b01101101, // 115 s
   0b01111000, // 116 t
   0b00111110, // 117 u
   0b00011100, // 118 v
   0b00101010, // 119 w
   0b01110110, // 120 x
   0b01101110, // 121 y
   0b01011011, // 122 z
   0b00111001, // 123 {
   0b00110000, // 124 |
   0b00001111, // 125 }
   0b01000000, // 126 ~
   0b00000000, // 127 DEL
   0b01100011  // 128 Degree symbol 
};

This is my access to array
Code:

output_b(PortB | SMAP[VDigit[0]-FirstChar] )

When I try to put this array in memory

Code:
char SMAP []= {...

it works fine.

But I can't put this on constant array, why ?

I try:

- const char SMAP []= {...
- const int8 SMAP []= {...
- char const SMAP []= {...

and many other possibilities but no constant array. In debugger, value of this array is false value.

I use a 24 bit chip PIC24FV32KA302. Is it incompatible with 8 bit constant ?

I see in this forum another example:
Code:
BYTE CONST TABLE [10]= {9,8,7,6,5,4,3,2,1,0};

and to access the table use:
Code:
x = TABLE [i];

OR
Code:

x = TABLE [5];

But not work on my microcontroller so
someone can help me?
_________________
______________________

-- Octopuss ---
Ttelmah



Joined: 11 Mar 2010
Posts: 19346

View user's profile Send private message

PostPosted: Thu Dec 20, 2012 3:09 am     Reply with quote

It has been covered many times in the past on the forum.

There are two parts to this.
It is 'historical', with much older smaller chips, not allowing direct access to the chip's ROM, so the CCS 'const' form was a 'cheat' construct, with the compiler building a program, that returned the required elements, when accessed as an array, _but did not allow pointer access to the data_.
You also have to remember the chip has two memory spaces, so that an address of '0' in the ROM, is different from an address of '0' in the RAM. Means that code has to 'know' which memory space it is dealing with.

BYTE, doesn't make any difference. It is just a 'synonym', for char, int8, etc. etc..

Possible solutions:
1) Use ROM, rather than const. This tells the compiler you want to access data using pointer constructs. This will only work if the code you are using knows it is using a ROM pointer.
2) Use the compiler instruction, '#DEVICE PASS_STRINGS=IN_RAM'. This tells the compiler to 'virtualise' accesses to string arrays, and move a copy into RAM when needed.
3) You can use '#DEVICE CONST=READ_ONLY', which then switches to using the ANSI version of 'const', as a variable that cannot be written, but this brings a huge RAM overhead, copying all your const tables into RAM.
4) Use #device PSV=16 (This is only a solution on the PIC24). Uses the PSV page to allow RAM based pointers to ROM tables. Best solution if you have a newish compiler.
5) Use #device CONST=ROM. Makes the compiler 'switch' all const accesses to use the ROM form.

You should have found a lot of threads about this, and solutions, when searching. However general 'comment', is to use the Google search, rather than the site's own search. Much more accurate, powerful, and with a better search language.

The manual is very poor on the ROM form in particular. Look at the 'readme.txt' with the compiler.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group