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 CCS Technical Support

Packing Messages on 18F252

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







Packing Messages on 18F252
PostPosted: Sun Feb 23, 2003 4:57 pm     Reply with quote

I was trying to implement the following example from a previous post for the 18F252.

I had no problem making it work on the 16F876.

The output shown is all scrambled. Any suggestions on what I have to change.

Thanks in advance.




#DEFINE OK_MSG 0x1FCE
#DEFINE UNK_CMD_MSG 0x1FD0
#DEFINE LEN_ERR_MSG 0x1FD8
#DEFINE NUM_ERR_MSG 0x1FE3
#DEFINE HEX_ERR_MSG 0x1FEA
#DEFINE RNG_ERR_MSG 0x1FEF
#DEFINE UNK_ERR_MSG 0x1FF9


//------------------------------------------------------------------------------
// *** Then pack the messages up in the following fashion ***
//------------------------------------------------------------------------------

#ROM 0x1FCE = {(128*'O'+'K'), 0 } // OK

#ROM 0x1FD0 = {(128*'U'+'n'), (128*'k'+'n'), (128*'o'+'w'), (128*'n'+' '), (128*'C'+'o'),
(128*'m'+'m'), (128*'a'+'n'), (128*'d') } // Unknown Command

#ROM 0x1FD8 = {(128*'W'+'r'), (128*'o'+'n'), (128*'g'+' '), (128*'C'+'o'), (128*'m'+'m'),
(128*'a'+'n'), (128*'d'+' '), (128*'L'+'e'), (128*'n'+'g'),
(128*'t'+'h'), 0 } // Wrong Command Length

#ROM 0x1FE3 = {(128*'N'+'u'), (128*'m'+'e'), (128*'r'+'i'), (128*'c'+' '), (128*'E'+'r'),
(128*'r'+'o'), (128*'r') } // Numeric Error

#ROM 0x1FEA = {(128*'H'+'e'), (128*'x'+' '), (128*'E'+'r'), (128*'r'+'o'),
(128*'r') } // Hex Error

#ROM 0x1FEF = {(128*'N'+'u'), (128*'m'+'b'), (128*'e'+'r'), (128*' '+'o'), (128*'u'+'t'),
(128*' '+'o'), (128*'f'+' '), (128*'R'+'a'), (128*'n'+'g'),
(128*'e') } // Number out of Range

#ROM 0x1FF9 = {(128*'U'+'n'), (128*'k'+'n'), (128*'o'+'w'), (128*'n'+' '), (128*'E'+'r'),
(128*'r'+'o'), (128*'r') } // Unknown Error


//------------------------------------------------------------------------------
// *** This routine unpacks and transmits the messages ***
//------------------------------------------------------------------------------
void put_ee_text(long addr) // transmit packed messages from flash
{ int ch; // unpacked character
long adr, // program memory address
xl; // packed characters

adr = addr; // copy address

while (1) // forever
{ xl = read_program_eeprom(adr++); // get packed data, auto inc address

ch = make8(xl << 1, 1); // unpack first character

if (ch == 0) break; // if null, exit
putc(ch); // transmit first character

ch = xl & 127; // unpack second character
if (ch == 0) break; // if null, exit
putc(ch); // transmit second character
}
}

//------------------------------------------------------------------------------
// *** Typical usage from some of own software ***
//------------------------------------------------------------------------------
void send_err_msg(int err) // messages after command completion
{
switch ( err )
{ case 0: break; // no error, no message

case 1: put_ee_text(OK_MSG); // OK message only
break;

case 2: put_ee_text(UNK_CMD_MSG); // Unknown Command
break; // don't type with fingers crossed

case 3: put_ee_text(LEN_ERR_MSG); // Wrong Command Length
break; // don't lean on the keybored

case 4: put_ee_text(NUM_ERR_MSG); // Numeric Error
break; // not all digits

case 5: put_ee_text(HEX_ERR_MSG); // Hex Error
break; // the spell's gone wrong

case 6: put_ee_text(RNG_ERR_MSG); // Number out of Range
break; // cowboys on the loose

default: put_ee_text(UNK_ERR_MSG); // unknown error number
}
send_crlf();
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12041
Hans Wedemeyer
Guest







Re: Packing Messages on 18F252
PostPosted: Sun Feb 23, 2003 9:54 pm     Reply with quote

The 18F252 store two bytes per location.
Read it into a sturct/union and access one byte at a time.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12046
Keith Lockstone



Joined: 18 May 2004
Posts: 1
Location: Matfield, Kent, England.

View user's profile Send private message Send e-mail Visit poster's website

Program Available for packing strings into program memeory
PostPosted: Tue May 18, 2004 3:29 am     Reply with quote

I've done a .exe to process a text file into a .h file for #including in programs. It is designed to work with 16F887 and 18F452 processors.

Please email me if you're interested as it needs beta testing.

Keith.
(Original poster of this idea)
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