??? 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(); } ... |