Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help with LCD interfacing

Status
Not open for further replies.

superdude34

Newbie level 3
Joined
May 8, 2011
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,307
Hi,

Im fairly new to microcontrollers and im working on my first project, a temperature sensor. When I come to the LCD, I initialized everything fine except I am stuck when it comes to setting the DDRAM address. I am working in Assembly with the GNU compiler on a Keil MCB2300. I know that the DDRAM address specifies the position of the cursor on the LCD, however, the LCD is connected via a 4 bit interface (D4 - D7) with my MCU. So my question is, what exactly must I write to these pins to set the DDRAM Address?

This is the LCD I am using

**broken link removed**

Thanks
 

Thanks for that but how do I write 80 HEX if I only have 4 data lines (D7 to D4) connected to the LCD?
 

write upper nibble first and then lower nibble.

check this and u will get the idea.
(a part of working code for LCD in 4bit mode)
Code:
void LCD_STROBE(void)
 {
EN = 1;
__delay_us(0.5);
EN = 0;
}
////////////////////////////////////////////////////////////////////
 void data(unsigned char c)
{ 
RS=1;
__delay_us(40); PORTD = ( c >> 4 );LCD_STROBE();
PORTD = ( c );LCD_STROBE(); 
}
//////////////////////////////////////////////////////////////////
void cmd(unsigned char c)
{
 RS=0;
__delay_us(40); PORTD = ( c >> 4 );LCD_STROBE();
PORTD = ( c  );LCD_STROBE();

}
///////////////////////////////////////////////////////////////// 
void clear(void)
{
 cmd(0x01);
__delay_ms(2);
}
/////////////////////////////////////////////////////////////////
void lcd_init()
{ __delay_ms(20);
cmd(0x30);
__delay_us(200);
cmd(0x30);
__delay_us(200);
cmd(0x30); 
cmd(0x28 ); // Function set (4-bit interface, 2 lines, 5*7Pixels)
cmd(0x28 ); // Function set (4-bit interface, 2 lines, 5*7Pixels)
cmd(0x28 ); // Function set (4-bit interface, 2 lines, 5*7Pixels)
cmd(0x0c); // Make cursorinvisible
clear();
clear(); // Clear screen 
cmd(0x6); // Set entry Mode
}




I connected my LCD in lower 4 bits of PORTD.

But in your case, since u had connected LCD to msb bits of PORTD, data and command write function,
u need to make some change in the shift operation as below.

Code:
void data(unsigned char c)
{ 
RS=1;
__delay_us(40); PORTD = ( c  );LCD_STROBE();
PORTD = ( c <<4);LCD_STROBE(); 
}
//////////////////////////////////////////////////////////////////
void cmd(unsigned char c)
{
 RS=0;
__delay_us(40); PORTD = ( c );LCD_STROBE();
PORTD = ( c <<4 );LCD_STROBE();

}
 
Last edited:

OK I think I got the idea. If I where to do this in Assembly, would I need to write the upper nibble to the 4 GPIO pins, assign a delay, then write the lower nibble to the same 4 GPIO pins? What does the function LCD_STROBE() do in your code?
 

**broken link removed**
 

RS pin of LCD is the register select pin. Inside LCD controller there is a command register and data register. So while RS=1 then data register is selected. Then we introduce a 4 bit data (MSB nibbe of 8 bit original data). Then to take that data to the selected register(now data register) we should give a clock pulse to EN (enable) pin in LCD. Then we introduce the lower 4 bits and then strobe ..Thus the 8 bit data is now inside the LCD controller. Now it will be displayed in the LCD. Similarly to controll the LCD we have to select the command register first. So we make RS =0. Then we want to give command similar to that of data given. Thats all about LCD..... I hope you understood...
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top