8051 interfacing LCD in C

Thread Starter

Dritech

Joined Sep 21, 2011
901
Hi all,

I am sending a string to be displayed on an LCD. To detect end of string, I am using a while loop as follows:

Code:
void uart_string(unsigned char string[])
{
   unsigned char index; 

   while (string[index] != '\0')
   {
        uart_send(string[index]);
        index++;
   }
}
Why is the program not exiting the while loop please?
 

ErnieM

Joined Apr 24, 2011
8,377
Strings in C terminate with a zero by definition and tradition. Make sure the strings you create follow this.

You do need to initialize the index variable. I did this below, as well as a few tweaks that may or may not result in a bit smaller generated code:

Code:
void uart_string(unsigned char string[])
{
   unsigned char index = 0;
 
   while (string[index])
   {
        uart_send(string[index++]);
   }
}
 

Thread Starter

Dritech

Joined Sep 21, 2011
901
Another quick question.
I am using a switch to trigger external interrupt. Do I have to use a pull-up resistor? There are examples with pull-ups and others with the switch connected to the ground only.
Also, do I have to declare the interrupt pin as input?
 

Papabravo

Joined Feb 24, 2006
21,225
Port 0 is the only port on the standard 8051 with open drain outputs. This means an external resistor must be used for the port pins to be inputs AND you need to write 1's to the output data latch to turn the sinking drivers off. This lets the external pullup hold the pin high.
 
Top