Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/23/08 11:22
Modified:
  02/23/08 11:37

Read: times


 
#151326 - string concatenate
Responding to: ???'s previous message
Hold the phrases for each line on a single string.
In the phrase_N() subroutine, access to this combined string using the line number as the index.
Then, the phrase_N() subroutines are converted into single subroutine, put_phrase( line_no ).
It reduces the code size so much.

As for the definition of the string for the phrases, string concatenate gives you convenient representation for maintenance.

In the usual coding, you may write down the phrases in a single string straightly.
                                 // 12345678901234567890
    unsigned char code phrases[] = "CALIBRATE L. TURBINE";


Using string concatenate, these two phrases are split into two strings.
Compiler interprets these separate strings into single one.
No null character is inserted between the strings.

    unsigned char code phrases[] = "CALIBRATE " "L. TURBINE";


And there is no problem even if new line and comment are inserted between the strings.
                                 // 1234567890
    unsigned char code phrases[] = "CALIBRATE "    // line  1
                                   "L. TURBINE";   // line  2



Using these technique, your code is revised as follows.

Tsuneo


#define MAX_LINES          35
#define MAXCHARS_ON_LINE   10
#define CHAR_MASK          0xBF

// You must ensure that there are 10 chars INCLUDING WHITE SPACE per line
// and phrase must be written in UPPERCASE LETTERS
// or else garbage will show up on display!!!!

unsigned char code phrases[] =
// 1234567890
  "CALIBRATE "	             // line  1
  "L. TURBINE"	             // line  2
  "R. TURBINE"	             // line  3
  "CMB       "	             // line  4
  "R. TURBINE"	             // line  5
  "R. TURBINE"	             // line  6
  ...
  "R. TURBINE";              // line 35

void put_phrase( unsigned char line_no )
{
   unsigned char idx;
                             // Parse the data array for 10 array elements
   for ( idx = 0; idx < MAXCHARS_ON_LINE; idx++ ) {
      P0 = phrases[ idx + line_no * MAXCHARS_ON_LINE ] & CHAR_MASK;
                             // Must strobe the write pin on the rising edge
                             // to latch char into memory position
                             // for each char in array
      write_enable();
   }
}		

void main( void )            // Main program
{
                             // clear any startup junk incase of a power cycle glitch
                             // or who the hell knows what else during a power cycle
                             // > recurring function
   clear_display();

   for(;;)                   // Loop this process forever
   {
      unsigned char line_no;
      for ( line_no = 0; line_no < MAX_LINES; line_no++ ) {
         clear_display(); put_phrase( line_no ); word_delay();
      }
      ...




List of 54 messages in thread
TopicAuthorDate
Best way to consolidate....out of memory            01/01/70 00:00      
   isn't this the classical gotcha?            01/01/70 00:00      
   There was a hint here....            01/01/70 00:00      
      Not const            01/01/70 00:00      
         Not necessarily            01/01/70 00:00      
            Hmmm...            01/01/70 00:00      
               Hmmm, indeed            01/01/70 00:00      
               Why?            01/01/70 00:00      
                  One reason ... and the prolly the original intent            01/01/70 00:00      
                     Obviously            01/01/70 00:00      
                        Speed            01/01/70 00:00      
                           Rogue programs?            01/01/70 00:00      
                              Yes. And stupid programmers            01/01/70 00:00      
                                 True            01/01/70 00:00      
                           cases            01/01/70 00:00      
                        The Obvious...            01/01/70 00:00      
                           Fair enough            01/01/70 00:00      
                              make sure the developer doesn't do something stupi            01/01/70 00:00      
                              Const to Code EPROM or FLASH,,,            01/01/70 00:00      
                           const and volatile - for optimization            01/01/70 00:00      
                  consts in other than CODE space            01/01/70 00:00      
                     Use the extended keywords            01/01/70 00:00      
                        'const' and 'volatile'            01/01/70 00:00      
   Unreadable code!            01/01/70 00:00      
      It really was all Keils fault....;)            01/01/70 00:00      
   You don't want to start from here!            01/01/70 00:00      
      Previously, on 8052.com...            01/01/70 00:00      
      Array of string            01/01/70 00:00      
         Yes, my mistake            01/01/70 00:00      
   string concatenate            01/01/70 00:00      
      Comments            01/01/70 00:00      
         Wow......LOL            01/01/70 00:00      
            Not a C vs ASM thing            01/01/70 00:00      
               From your perspective, it may make sense            01/01/70 00:00      
      I went this direction....code padding removal?            01/01/70 00:00      
         For but one byte added to the array...            01/01/70 00:00      
         With proper ordering in source file...            01/01/70 00:00      
         Putting it all together            01/01/70 00:00      
            Spectacular Russ.....            01/01/70 00:00      
   THINK            01/01/70 00:00      
      that is surely needed            01/01/70 00:00      
      A bit easier to read?            01/01/70 00:00      
         easy to read???            01/01/70 00:00      
      typedef vs #define            01/01/70 00:00      
      I think not            01/01/70 00:00      
         Tks Russ.            01/01/70 00:00      
            THINK(ing)            01/01/70 00:00      
               ???            01/01/70 00:00      
                  Objectives.            01/01/70 00:00      
                     I beg your pardon?!            01/01/70 00:00      
                     I see            01/01/70 00:00      
   Best way to consolidate....out of memory            01/01/70 00:00      
   Why specify CODE for functions?            01/01/70 00:00      
      there is so much stuff            01/01/70 00:00      

Back to Subject List