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.

Microcontroller Programming » I can send char as "0xff" or 'f', but if *str = "f", I can't send *str

April 29, 2012
by jeffspc88mx
jeffspc88mx's Avatar

I'm making progress getting my Noritake VFD to respond thanks to all of your help, but now...

I can send individual char as either hex ("0xff") or char ('f'), but when I try to send through the pointer (*str), I get garbage out. I'm sifting through my K&R and using Noritake's own example code, but no luck. Here's what I'm doing

const char *luv = "LOVE";

while (*love) //*love = "LOVE"
    write_2VFD_char(*love++); //print each char in "LOVE"

love = (love - 4); //reset pointer to the beginning of "LOVE"
write_2VFD_char(*love++); //and just for kicks try again without the loop
write_2VFD_char(*love++);
write_2VFD_char(*love++);
write_2VFD_char(*love++);

The output is garbage, if anything, and not always four characters of garbage. I thought it would print the same garbage twice (because I'm basically sending the string twice), but the garbage changes (although it is longer with two rather than one).

Now sending and ('L'), then an ('O'), then a ('V'), and so on works just fine, as does sending the hex equivalents of each character ("0xAB"). But this pointer/array thing is broken. Any ideas?

April 29, 2012
by jeffspc88mx
jeffspc88mx's Avatar

Oops - forgot to change "luv" to "love" - it's a typo in the post, they're the same label in my code - that's not the problem with the code.

April 30, 2012
by hevans
(NerdKits Staff)

hevans's Avatar

Hi jeffspc88mx,

I'm fairly certain this is happening because of the strings in program memory vs ram issue. There is a good library article about it. Make sure you follow the links at the bottom to the relevant threads, they are full of very good info.

Post a Reply

Please log in to post a reply.

Did you know that our kits have shipped to hobbyists in 40 countries? Learn more...