NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Support Forum » char arrays problem

January 19, 2011
by stretch_pr
stretch_pr's Avatar

Hi,

I just finished the LED ARRAY Kit and I wanted to make a scroll based of char array. I have finished everything but the code works fine when I use:

char array[5];
array[0] = 'H';
array[1] = 'E';
array[2] = 'L';
array[3] = 'L';
array[4] = 'O';

but when use:

char array[]="HELLO";

it doesn't work. Does anyone knows why?

Here is part of the code:

void scroll_message(char message[], int message_len) {
char buf[7];
uint8_t width;
uint8_t i, j, a;

for (a = 0; a < message_len; a++) {
  font_get(message[a],buf);
  width=buf[1];
  for(j=0; j<width; j++){
    for(i=0; i<ROWS; i++) {
      if( (buf[2+j] & (1<<i)) != 0) {
        ledarray_set(i,23,1);
      } else {
        ledarray_set(i,23,0);
      }
    } //end for rows
    delay_ms(250);
    ledarray_left_shift();
  } //end for cols

  // blank the next between letters
  for(i=0; i<ROWS; i++) {
    ledarray_set(i, 23, 0);
  }
  delay_ms(250);
  ledarray_left_shift();
} //end for message

// blanks to start again the message
for(a=0; a<5; a++) {
  for(i=0; i<ROWS; i++) {
    ledarray_set(i, 23, 0);
  }
  delay_ms(250);
  ledarray_left_shift();
}
}

int main() {
ledarray_init();

// activate interrupts
sei();

// init serial port
uart_init();
FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
stdin = stdout = &uart_stream;

char m[]="HELLO";

while(1){
scroll_message(m,5);
}
}
January 19, 2011
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi stretch_pr,

See this thread. Basically, you can edit your "Makefile" and remove the "-j .text" part from the avr-objcopy line. Then, recompile, and your original way of initializing the array should work.

Mike

January 20, 2011
by bretm
bretm's Avatar

Isn't the .text section the part that contains the actual program code?

You need to add "-j .data" in addition to "-j .text". Or just leave the makefile alone and use PROGMEM and pgm_read_byte.

January 20, 2011
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi bretm,

Yes, you're exactly right. However, simply removing "-j .text" and not specifying any sections makes avr-objcopy default to copying all sections.

Mike

January 20, 2011
by bretm
bretm's Avatar

Oh, that's handy. Does that imply that variables in default NerdKits sample apps don't get initialized to zeros (because .bss isn't included)?

January 20, 2011
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

I believe I recall reading that the AVR hardware actually clears the SRAM to all zeros upon reset, but I could be mistaken.

Also, variables that are local to a function scope are often allocated in registers instead of given a permanent SRAM location assignment, so these will be cleared by the program code in any case.

Post a Reply

Please log in to post a reply.

Did you know that you can connect a computer keyboard to your microcontroller? Learn more...