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.

[SOLVED] LCD 4 bit mode interfacing

Status
Not open for further replies.

hemnath

Advanced Member level 3
Joined
Jun 24, 2012
Messages
702
Helped
61
Reputation
120
Reaction score
57
Trophy points
1,308
Location
Chennai
Activity points
6,588
Hardware: PIC18F2520
Microcontroller pins B0 to B3 connected LCD DB4 to DB7;
A2 connected to RS
A1 connected to Enable

CCS C compiler program:
Code:
#include "18F2520.h" 
#fuses  INTRC_IO 
#use delay(clock=4000000) 

#define EN     PIN_A1
#define RS     PIN_A2

void lcd_init(); 
void lcd_cmd(unsigned char ); 
void lcd_data(unsigned char ); 
void disp_cmd(unsigned char ); 
void disp_data(unsigned char ); 


void main() 
{ 
   delay_ms(100); 
   lcd_init(); 
   delay_ms(100); 

   while(1) 
   { 
      disp_cmd(0x80); 
      printf(disp_data, "TESTING "); 
      delay_ms(100); 
   } 
} 

void lcd_init() 
{ 
   disp_cmd(0x02);      // To initialize LCD in 4-bit mode. 
   disp_cmd(0x20);      // To initialize LCD in 1 lines, 5x7 dots and 4bit mode. 
   disp_cmd(0x0C); 
   disp_cmd(0x01); 
   disp_cmd(0x06); 
   disp_cmd(0x80); 
} 

void lcd_cmd(unsigned char c) 
{ 
   output_b(c); 
   output_low(RS); 
   output_high(EN); 
   delay_ms(15); 
   output_low(EN); 
} 

void lcd_data(unsigned char z) 
{ 
   output_b(z); 
   output_high(RS); 
   output_high(EN); 
   delay_ms(15); 
   output_low(EN); 
} 

void disp_cmd(unsigned char cmd_value) 
{ 
   unsigned char cmd_value1; 
   cmd_value1 = ((cmd_value>>4) & 0x0F);   // Shift 4-bit and mask 
   lcd_cmd(cmd_value1);               // Send to LCD 
   cmd_value1=(cmd_value & 0x0F); 
   lcd_cmd(cmd_value1);               // Send to LCD 
} 

void disp_data(unsigned char data_value) 
{ 
   unsigned char data_value1; 
   data_value1 = ((data_value>>4) & 0x0F); 
   lcd_data(data_value1); 
   data_value1=(data_value & 0x0F); 
   lcd_data(data_value1); 
}

But the display shows nothing. Voltages are +5V. Please help .
 

Hi,

LCD drive voltage pin to adjust contrast is not connected.

Klaus
 
PIN 3 is connected to potentiometer. When Checking with 4 bit mode using PINS B4 to B7 it is working. But when I use B0 to B3 it is not working.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top