16 x 2 LCD 4 bit mode need help...!!

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

16 x 2 LCD 4 bit mode need help...!!

Jump to solution
2,360 Views
HussainAftab
Contributor I

Hi i am using MC9S08QG8 with 16 x 2 LCD.

i am using lcd in 4 bit mode.

it is only showing boxes in the first line.

i have grounded D0,1,2,3 and sending 0x30 3 times in the initialization but still can't see any thing

i am attaching the code and schematic please help me...

Labels (1)
0 Kudos
1 Solution
643 Views
peg
Senior Contributor IV

Hello Hussain,

 

After a quick scan through your code...

The module powers up in 8-bit mode

The first write needs to be an 8-bit one

the top nibble needs to be 0x02, then you toggle E

Now you are in 4-bit mode

Then you do a 4-bit write to the same register of 0x28 to set 4-bit again and two line

then carry on setting the other registers in 4-bit mode.

 

You seem to have two errors initially (I have not bothered to look further)

1. you make the first write in 4-bit style

2. you send 0x38 rather than 0x28

 

 

 

View solution in original post

0 Kudos
8 Replies
643 Views
bigmac
Specialist III

Hello Hussain,

 

Perhaps https://community.freescale.com/message/51860#51860may be of interest.

 

Incidently, I do not consider the "sprinkling" of unconnected components on a sheet to represent what I would call a schematic drawing.  While your circuit board program may be able to derive a net list from this conglomeration, what you have shown does not fullfil the requirements of a schematic drawing that is readable by a human, i.e. a graphical representation of the interconnections of the various components.

 

Regards,

Mac

 

0 Kudos
644 Views
peg
Senior Contributor IV

Hello Hussain,

 

After a quick scan through your code...

The module powers up in 8-bit mode

The first write needs to be an 8-bit one

the top nibble needs to be 0x02, then you toggle E

Now you are in 4-bit mode

Then you do a 4-bit write to the same register of 0x28 to set 4-bit again and two line

then carry on setting the other registers in 4-bit mode.

 

You seem to have two errors initially (I have not bothered to look further)

1. you make the first write in 4-bit style

2. you send 0x38 rather than 0x28

 

 

 

0 Kudos
643 Views
HussainAftab
Contributor I

Thanks Ludin i will consider your suggestions in my code.

 

Peg said that i am doing the first write in 4 bit mode.

he said i have to send 0x02 first in 8 bit style.

I mean how could i send 0x02 in 8 bit style with 4 of the lower bits are permenantly grounded..?

and if i do it like first higher nibble then lower then again it is the 4 bit style...

 

if i do like this will it be ok..?

    RS = 0;
    D7 = 0;      
    D6 = 0;      
    D5 = 1;     // 0x20
    D4 = 0;
    for(i = 0; i < 3; i++)
    {
      
      LCD_Enable = 1;                               // High to Low pulse on Enable Pin for 1 ms
      Delay_1ms(1);
      LCD_Enable = 0;
      Delay_1ms(15);
    }

LCD_Cmd(0x28);

0 Kudos
643 Views
peg
Senior Contributor IV

Hello,

 

What I meant was your first write was a high nibble of the command write to the high nibble of the port followed by a low nibble of the command write to the high nibble of the port.

The first write needs to be an 8-bit write so you just do the high nibble of the command to the high nibble of the port (0x2) and the low nibble will be zero, set by the grounded connection. Now it is in 4-bit mode so you write to it high nibble then low nibble.

What you have shown should achieve this.

You should write to all the registers to be sure of your setup. I notice you don't seem to be doing a display on either.

 

Note: There are many comments that could be made about your methods and coding style etc but these are perhaps best left until the bugs are ironed out given the small amount of code involved.

 

0 Kudos
643 Views
HussainAftab
Contributor I

Now i have changed the initialize method as follows but still cant see anything.

I read somewhere that donot ground D0,1,2,3 of LCD left them unconnected i also tried that but no use

 

  void LCD_Init(void)
  {
    unsigned char  i = 0;
    SetIO(Lcd);
    LCD_Enable = 0;
    RS = 0;
    D7 = 0;
    D6 = 0;
    D5 = 1;
    D4 = 0;
    
    for(i = 0; i < 3; i++)
    {
      
      LCD_Enable = 1;                               // High to Low pulse on Enable Pin for 1 ms
      Delay_1ms(25);
      LCD_Enable = 0;
      Delay_100ms(1);
    }

    LCD_Cmd(0x28);         
      Delay_1ms(15);
    LCD_Cmd(0x01);       // Clear display
      Delay_1ms(15);
    LCD_Cmd(0x0F);       // Display on cursor blinking
      Delay_1ms(15);
  }

0 Kudos
643 Views
peg
Senior Contributor IV

Hello,

 

If you just power up one of these displays without initialising it you will get "black boxes" or all the segments on - on the top row. If this is what you are seeing then you are not initialising it properly.

It can be quite a delay from when your MPU is running to when the LCD is ready to recieve its first command.

Are your delays correct? Maybe just make them all a lot bigger.

0 Kudos
643 Views
HussainAftab
Contributor I

Finally my lcd worked..

Peg was right the sequence he suggested in his first reply works fine.

there were some hardware connection problem which were disturbing the lcd signals.

i also fixed my delay as ludin correctly said that there is no relation between the time you call delay function and the overfolw of timer. Now i feed watchdog from the while loop rather than feeding it from the interrupt routine.

I thank you all for helping me out.

 

0 Kudos
643 Views
Lundin
Senior Contributor IV

Here are some bugs:

 

- Never feed the watchdog from an interrupt routine! Doing so defeats the whole purpose of having a watchdog. If your code goes haywire the interrupts will still keep the watchdog happy. Instead, feed the watchdog from the infinite while(1) loop in main().

 

- DelayCount must be declared volatile or the entire program may behave randomly with optimizer enabled.

 

- There is no relation between the time where your delay functions are called and the time when the timer reaches interrupt. Your delays will be highly inaccurate. If the delay of 1ms is critcal to the LCD, then I suspect this may be the cause of your problems.  Instead, restart the timer before every delay.

 

0 Kudos