first off:
transmit(‘Wrong command’);
The ’ character is used to indicate a character constant. So you’re likely getting a compiler warning here, since you’re trying to cram several characters into a single character constant. Look at your compiler warnings; they’re usually trying to tell you something.
Second - why would a for loop calling the same function with the same parameter print something different every time?
Here’s an example of how to do it:
1: char * mystring = "Hello World\n";
2: char * txptr = mystring;
3: while (*txptr)
4: transmit(*txptr++);
1: mystring is a pointer, which is the address, of a set of bytes; ‘H’,‘e’,‘l’,‘l’,‘o’,…‘d’,‘\n’,0
2: copy the pointer to mystring, so that we have the original pointer around if we need it later
3: While the byte that txptr points to is not 0 [there’s a trailing 0 at the end of the string]
4: tranmit the byte that txptr points to, and increment txptr [aka, move it to the next byte.
Now, this is non-optimal, because you end up using the .data section for storing your string, when it is constant. [.data is in ram, so you use up a chunk of flash to store the string, then copy it to ram on function entry]. However, putting strings in flash is a bit out of the scope of this post.
Cheers,
–David Carne
EDIT
leon_heller beat me to it. His way will work fine too; but sometimes compilers generate a bit tighter code using the pointer arithmetic method.