Author Topic: LCD does not working  (Read 2527 times)

0 Members and 1 Guest are viewing this topic.

Offline winsonTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
LCD does not working
« on: February 01, 2009, 09:23:04 AM »
Hello,

I was trying to write a simple LCD testing program to display "P" on 1st line and display "L" on the 2nd line, but my 16x2 LCD just show 2 line of grey square. I was using the Port C & Port D of my PIC16F877A and using 8-bits interface to display character on my LCD. I also try to put a pullup resistor to all the port's pins that used but the results is still the same. The 8 data pins of the LCD is connect to Port D and RS, RW, E is connect to the first 3 pins(RA0, RA1, RA2) of Port C.

I was using CCS C compiler, to write this testing program i was refer to the information provided in the HD44780U datasheet.

Anybody can give some suggestions regarding the error that i have make?
The testing program is shown below.

Any suggestion will be greatly appreciate.
Thanks.

Code: [Select]
#include <16F877A.h>
#fuses hs, nowdt, nolvp, noprotect   //Config
#use delay (clock = 20000000)      //20MHz Crystal

void init(void);      //Function Prototype
void busy_test(void);
void display(void);
void send_command(void);
void send_data(void);

unsigned char PORTC, TRISC, PORTD, TRISD, RS, RW, E, BF;
unsigned char command, data;

#byte PORTC = 0x07
#byte TRISC = 0x87
#byte PORTD = 0x08
#byte TRISD = 0x88

#bit RS = PORTC.0
#bit RW = PORTC.1
#bit E  = PORTC.2
#bit BF = PORTD.7

void main()
{
   init();
   display();
   while (1)
   {

   }   
}

void init()
{
   PORTC = 0x00;   //Clear Port C
   PORTD = 0x00;   //Clear Port D

   TRISC = 0x00;   //Set Port C As Output
   TRISD = 0x00;   //Set Port D As Output

   delay_ms (500);   //Power-On Delay
         //Busy Flag Valid Here

   //busy_test();   //Check Busy Flag
   command = 0x38;   //8-Bits, 2-Lines, 5x7 Dots
   send_command();   //Send Command To LCD

   delay_ms (10);

   //busy_test();   //Check Busy Flag
   command = 0x38;   //8-Bits, 2-Lines, 5x7 Dots
   send_command();   //Send Command To LCD

   delay_us (500);

   //busy_test();   //Check Busy Flag
   command = 0x38;   //8-Bits, 2-Lines, 5x7 Dots
   send_command();   //Send Command To LCD

   delay_ms (1);

   busy_test();   //Check Busy Flag
   command = 0x38;   //8-Bits, 2-Lines, 5x7 Dots
   send_command();   //Send Command To LCD

   delay_ms (1);

   busy_test();   //Check BF
   command = 0x08;   //Display Off, Cursor Off, No-Blink
   send_command();   //Send

   delay_ms (1);

   busy_test();
   command = 0x01;   //Clear Display
   send_command();

   delay_ms (5);

   busy_test();
   command = 0x06;   //Increment Cursor Position, No-Shift
   send_command();

   delay_ms (1);

   busy_test();
   command = 0x0F;   //Display On, Cursor On, Blink
   send_command();

   delay_ms (1);
}


void display()
{

   busy_test();
   command = 0x80;   //Set DDRAM Address To 0x00
   send_command();

   delay_ms (1);

   busy_test();
   data = 0x50;   //Display "P"
   send_data();

   delay_ms (1);

   busy_test();
   command = 0xC0;   //Set DDRAM Address To 0x40
   send_command();

   delay_ms (1);

   busy_test();
   data = 0x4C;   //Display "L"
   send_data();

   delay_ms (1);

}


void busy_test()
{
   while (1)
   {
      TRISD = 0xFF;      //Set Port D As Input
      //RS = 0;            //Command
      //RW = 1;            //Read Busy Flag
      PORTC = 0x02;

      delay_cycles (2);   //Control Setup Time
      //E  = 1;            //E-Line High
      PORTC = 0x06;

      delay_cycles (6);   //Wait Data Return

      if (BF == 0)
      {
         TRISD = 0x00;   //Set Port D Back To Output
         //E  = 0;         //E-Line Low
         PORTC = 0x02;
         return;
      }

      //E  = 0;            //E-Line Low
      PORTC = 0x02;
   }      //End while loop
}      //End Function


void send_command()
{   
   //RS = 0;            //Command
   //RW = 0;            //Write Instruction
   PORTC = 0x00;

   delay_cycles (2);   //Control Setup Time
   //E  = 1;            //E-Line High
   PORTC = 0x04;

   delay_cycles (3);   
   PORTD = command;   //Put Command To Port D

   delay_cycles (3);   //Data Setup Time
   //E  = 0;            //E-Line Low
   PORTC = 0x00;
   delay_cycles (1);   //Control & Data Hold Time
}


void send_data()
{
   //RS = 1;            //Data
   //RW = 0;            //Write data
   PORTC = 0x01;
   
   delay_cycles (2);   //Control Setup Time
   //E  = 1;            //E-Line High
   PORTC = 0x05;

   delay_cycles (3);
   PORTD = data;      //Put Data To Port D

   delay_cycles (3);   //Data Setup Time
   //E  = 0;            //E-Line Low
   PORTC = 0x01;
   delay_cycles (1);   //Control & Data Hold Time
}

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: LCD does not working
« Reply #1 on: February 01, 2009, 10:19:50 AM »
Hi,

Probably you didn't initialize the LCD properly, else you didn't adjust the contrast (but the former sounds most likely).
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline winsonTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: LCD does not working
« Reply #2 on: February 03, 2009, 05:26:10 AM »
Hi friends,

Finally the LCD is WORKING!

The problem is in the power supply. The 5V Vdd supply voltage drop to 4.33V when it is connect to the LCD. I was using a battery for the LCD, due to high supply current of the 9V battery, thus have to put a current limiting resistor to limit the current that goes into the LCD, And i think because of the LCD consist of certain amount of internal resistance(from calculation it is around 23.23K ohms), this resistance will form a voltage divider with my current limiting resistor and make the supply voltage to the LCD drop to 4.33V. Normally, for LCD it's Vdd range is from 4.5V to 5.5V in order for it to work correctly. I think my problem is when the voltage does not reach 4.5V then the LCD may not initialize or not working.

After adjust the value of the current limiting resistor to get back a Vdd which is around 4.6V then the LCD work nicely. Besides, for the Vo of the LCD i was directly connect it to ground to get maximum contrast, this is to avoid the variable resistor(pot) that use to control the contrast from disturbing the voltage value of the Vdd.

For the send_command() and send_data() function i was modify the code to first load the data to the Port D then toggle the E signal from low to high then goes back to low again. I think it also work by set the E signal to high first then load data to Port D and after that set E to low, but since the LCD is working then i will follow the modified code.

Thanks
« Last Edit: February 03, 2009, 05:27:52 AM by winson »

Offline ArcMan

  • Supreme Robot
  • *****
  • Posts: 519
  • Helpful? 4
  • Mmmm... Plasma
Re: LCD does not working
« Reply #3 on: February 03, 2009, 01:42:51 PM »
It sounds like you could potentially learn an electronics lesson here.
Don't use resistors to form some kind of voltage divider to supply voltage to devices.  Use a voltage regulator.  Voltage will be maintained regardless of load.

Offline winsonTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: LCD does not working
« Reply #4 on: February 08, 2009, 04:59:46 AM »

Sorry for late reply, just busy for the next part of my project which is making infrared communication for UART transmission.

Thanks for your suggestion.
Yes i'm using a LM7805 IC to regulate the power supply to the entire board(this is what i forget to tell in my previous reply). For the LM7805 IC it just able to limit it's output current to a range of 700mA to 1000mA, and this value of current is consider very large for the Vdd of an LCD which is in the range of 1.5mA to 3mA and no choice for me to put a current limiting resistor to the Vdd pin.

I was thinking is it possible just fed a 700mA to the Vdd pin of an LCD(to avoid using current limiting resistor), so anybody have any suggestion, is it possible?

From my point of view, the LCD may be can act as a resistor and just withdraw the current that it need although there are 700mA giving to it, like the 8 data pins of the LCD we do not put any resistor when connect it the PIC i/o pin which can supply 25mA to the LCD, it is something like the pins of the LCD having some high impedance. But anyway i still not try to directly give 700mA to LCD(afraid the LCD will damage).

The Vdd pin of a PIC16F877A can accept 5A of current and it does not damaged, this is my experience when i accidently forget to put a current limiting resistor to the output of the LM7805 IC.(Just measure again the 9V battery that i'm using, it's current already become weak a bit but still maintain in 2A.)

Can anybody give some comment on this?

Thanks

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: LCD does not working
« Reply #5 on: February 08, 2009, 04:16:24 PM »
Hi,

You have no reason to limit current to a normal functioning device, it will suck whatever it needs and not a bit more. If an LCD goes ape on the current, consider it broken (or perhaps you connected something else to it that's sucking current like crazy?

If it's for experimental purposes, you should have a lab-supply with a variable current limiter - not hard to build for a 5V supply.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline winsonTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: LCD does not working
« Reply #6 on: February 09, 2009, 02:03:26 AM »
Hi Soeren,

Wow! This really a good news! By throwing away the current limiting resistor then all the headache on supply voltage will also disappear together. :D By the way i think it should be need a current limiting resistor for the LED backlight of the LCD as LED may burn by excess of current.

Erm..., i haved remember i got some little experience on a 20ohms resistor(not in my LCD circuit), it is like this, the 20ohms resistor get heated and then give out some smoke when i give a large current to that resistor, just doubt that will a LCD become hot when we supply large current for it to suck the amount that it need for displaying? LCD may also act as a resistor and withdraw the current that needed but a resistor will get heat up when withdrawing.

The reason why i using a battery for my LCD circuit is because it is part of my remote control project which is power by a 9V battery, but i does try the LCD on a lab-supply and what funny is the LCD cant display except the square box. After that when switch back to power by a battery then the LCD function nicely. May be the problem is in the internal resistance of lab-supply, again form a volatge divider with my current limiting resistor and make the voltage presented to Vdd to drop.

 


Get Your Ad Here