Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LCD Only Working Partially...

Status
Not open for further replies.

bsodmike

New Member
Today I got the LCD to fire up after I sorted out the high/low nibble swap code for 4bit operation.

Problem 1:
------------

Right now I have to send characters as follows:

snd_char(ASCII Hex value);

Sadly, snd_char("A"); does not work. Is there anyway to perform an ASCII to Hex conversion?

Problem 2:
------------

If the LCD is powered up (with no PIC) only 8 blocks light up of the 16 available blocks, as it is a 1x16 LCD.

As I continue to send characters to the screen, after the 8th character nothing appears...

Does this mean that the LCD is defective or is there away to let it carry on writing ?

This would help me greatly, thanks!

--Mike
 
1) try snd_char('A');
in C, "A" is a single-character string, 'A' is a character.

2) when the LCD powers up, it always fills up the first row with black blocks, until the LCD is initialized. it sounds like your LCD may be organized such that the first 8 characters are the "first row" and the second 8 characters are the "second row"... rather weird, but who knows. try putting in an endless loop to see if the other locations get filled eventually... I believe 0x40 is the address for the first char of the second row in most LCD's, so if you keep printing characters it should eventually get to that location. if it does fill it eventually, then you'll just have to access the LCD as if it were 2 rows instead of one.
 
Thanks for that tip, I'll try 'A' :)

I tried sending '0xc0' which supposedly means goto next line, but is a valid command for 2-line lcds so hrm.

I'll try and shift the 'cursor' to the 9th position via addressing and see if I have any luck.

How would one step through the letters of a Character string?

So I would want to do something like:

for (i=0; i < strlen(data);++i){
snd_char(data);
}

I'm guessing some sort of array then or? This way I could do snd_string("Weee!");

Thanks, Mike
 
send a pointer to a const char array.

Code:
void printf(const char * s)
{
    while(*s)
        snd_char(*s++);
}

the C compiler should automatically treat a string passed as the argument as a constant character array, so you can just do printf("hello world");
 
looking over some LCD stuff today, it turns out my suspicion might be correct...
look at the table near the middle of https://www.myke.com/lcd.htm

according to that, for some 1x16 LCD's, the 9th character position is in fact at memory address 0x40, normally the second row of 2-row LCD's. so try moving the cursor to address 0x40 and you should be able to write to the rest of your row.
 
Strange, I infact tried writing to '0xC0', but I'll try again. That's 0x80 + 0x40...

I'll also try writing to 0x89, see which works...I think 0x89 would work if it *had* the support chip.

Thanks a lot, I'll try that function for sending strings to it. Need to see how to incorporate the 'send 8 chars', shift to 0xc0, 'send the balance' as well.
 
We did this last month in my microcontrollers class...which compiler are you using? Hopefully something better than the CCS-pic compiler.

But anyhoo, writing a 0x80 should put the cursor to the first char. in the first line and 0xC0 should go to the second line.
Also, how are you initializing the lcd?
 
bsodmike said:
Need to see how to incorporate the 'send 8 chars', shift to 0xc0, 'send the balance' as well.

you just have to keep track of the current cursor position whenever it changes, and have a couple IF statements scattered around as needed to handle shifting back and forth between 0x00-0x07 and 0x40-0x47... for instance if you just wrote a character to 0x07, you would tell the LCD to move the cursor to 0x40, and update your cursor position variable to match.
 
I now know why my command of 0xc0 didn't work. I didn't wait 5Ms, for the instruction to complete (as I am *not* polling the busy flag) - will let you guys know in a couple hours :)

LCD Init: in 4-bit mode, connected to a shift register for 3-wire mode, therefore initialised in 4-bit mode and data is sent to the SR as two nibbles, upper first, lower after. The status of 'R/S' is loaded before the data for each nibble to notify the LCD if it is a command or character.

Thanks,

--Mike
 
Haha, got it to work, had to 'define' it as a two line LCD...

Code:
void snd_string(const char *s)
{
	int pos;
	pos = 0;

	snd_cls();

    while(*s)
	{
		if (pos > 7)
		{	
		Mode_cmd();
		snd_char(0xc0+(pos - 8)); // Already in the 8th position.
		DelayMs(5);
		}
	Mode_char();
	snd_char(*s++);
	pos++;
	}
}


Thanks a lot dude! :D

--Mike
 
I want to try the following:

snd_string(centre("Hello World!"));

Got a bit lost here:

Code:
char centre(const char *t)
{
int length, i, buffer;
char string[16];

	while(*t)
	{
	length++;
	}

buffer = 16 - length;

	if ((buffer % 2) == 0)
	{	
		for(i=0;i<(buffer/2);++i)
		{
		strcpy(string," ");
		}
	strcat(string,t);
		for(i=0;i<(buffer/2);++i)
		{
		strcpy(string," ");
		}
	}

//return(string);
}

Thanks, Mike
 
instead of trying to adjust the string so that it is centered (with white spaces on either side), why not just calculate where you need to put the cursor to get it centered then just use a simple instruction write to the LCD?
seems like it'd be alot easier that way.
 
Of course! Ta, I think my brain had reached its limit at that point, and it was 2pm and I hadn't even had bfast :p

Will give it a shot later on :)

Also the LCD I have is a 1x16 with no LEDs actually soldered on. The spots for LEDs to be soldered on are there - but should I just bend some LEDs over and solder 'em in, or do special '90 degree SMDs' or something go there?

I'm thinking some 3mm's bent would do the job, and ultrabrights too :)

--Mike
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top