How to access a constants value

Hello everyone, I am new to imp and squirrel. I am having troubles with using the constants. I will let the code that I post speak.

const _A = 0x77;
const _B = 0xF4;
const _C = 0xE0;
const _D = 0xE6;
const _E = 0xF1;
etc…

Ok these bytes represent a binary value for turning on and off segments of a 7 segment 12 character display to give me a word(s). So I am writing a function to take the words I want to display and send them via spi to the LCD device.

so the call I make is: lcd_write (“LOW BATTERY”);

the function then has to iterate threw the letters in reverse (property of LCD).

function lcd_write( pcBuffer ) {

// initilize the lcd
init_lcd();

// Derive the number of characters to be displayed
// so that the proper position can be determined.
// Remember that the LCD starts at the right hand side,
// but our data position is from the left hand side.

nChars = strlen( pcBuffer );

// The order of the digits must be reversed going in

jj = nChars - 1; // access the last digit
for ( ii=0; ii<nChars; ++ii )
{
ucChar = “_”+pcBuffer[jj]; << ------ this is the trouble line
spi.write(ucChar);
–jj;
}

 CS.write(0);            // set CS pin to low display content

}

I need to reference the constants that have the byte value. so if the letter “A” is encountered I have to reference the constant “_A” to give me the byte 0x77. Not sure how to do this.

Any help would be appreciated.

Thanks
Brad

I guess something like this would work

`buff <- “ABCDE”;

xlate2 <- {A=0x77,B=0xF4,C=0xE0,D=0xE6,E=0xF1};

xlate <- [0x77,0xF4,0xE0,0xE6,0xF1,0x01,0x02];

for( local i=(buff.len(); i!=0; i–)
local cint = xlate2[ buff[i-1].tochar()] ;

// or

for( local i=(buff.len()); i!=0; i–)
local cint = xlate[buff[i-1]-‘A’];
`

Not really knowing anything about Squirrel I’m sure there are better.