Problems sending char arrays to an LCD
2010-10-07 by Brewski
I'm trying to send a character array to an LCD display and am having problems. An individual character works but the array does not.
Here is what I have tried out trying to find the problem.
Given the following C++ and C code on a Ubuntu computer using the GNU C++ and AVR GCC compilers.
// a.cpp
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char str[] = "Linux";
char a;
for(int i = 0; i < strlen(str); i++) {
a = str[i];
cout << "Character " << i << ", at str[" << i << "] is, " << a << "\n";
}
cout << "Length of the char array \'str\' containing, \"" << str << "\", is "<< strlen(str) << " plus a null terminator.\n";
return 0;
}
The above prints correctly on the monitor, at least what I expect it to print on the screen.
The following lights the LEDs on a STK500 indicating an ASCII 'a'.
// atest.c
#define F_CPU 4000000
#include <avr/io.h>
#include <string.h>
int main (void)
{
DDRB = 0xff;
PORTB = 'a'; // LEDs light indicate an 'a' was sent
}
The following light no LEDs on the stk500 indicating 0xFF was sent.
// atest.c
#define F_CPU 4000000
#include <avr/io.h>
#include <string.h>
int main (void)
{
char str[] = "ab";
DDRB = 0xff;
PORTB = str[0]; // All LED's are off indicating 0xFF was sent
}
It seems to me that the GNU 'C' software is messed up. That I find hard to believe. It is most likely me doing something wrong. Try a as I may, I have not been able to figure it out. Can someone tell me the errors of my ways?
Thanks,
Mike Bronosky