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] PIC 16F877 interface with LCD 2 x 16

Status
Not open for further replies.

WStevens_sa

Member level 2
Joined
Jan 5, 2011
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
South Africa
Activity points
1,695
Hi all

Trying to figure out how to send info to LCD 2x16. Running a bit into a snag. The code below I found on the web. I am trying to understand the methods of communication with an LCD using f877. I am using Real Pic Simulator 1.3 to simulate.

First problem On compiling "MikroC"
8 393 'lcd_cmd' Identifier redefined LCD 2 x 6.c

Second problem I cannot Identify which pins from the f877 go to where on the LCD. I have a feeling that the pins are already configured somewhere else and this is why it complains about the "Identifier redefined"

int k;
char ch;

void delay_ms()
{
for(k=0;k<100;k++);
}
void lcd_cmd(ch)
{
PORTD=ch; //sending character element on port
PORTC=0x04;
delay_ms(100); //to wait for character to write on lcd
PORTC=0x00;
}
void lcd_data(char ch)
{
PORTD=ch;
PORTC=0x05;
delay_ms(100);
PORTC=0x01;
}
void init_lcd()
{
lcd_cmd(0x3); // function set (set interface length)
lcd_cmd(0x0E); //enable cursor display
//lcd_cmd(0x01); //clear display
//lcd_cmd(0x06); //entry mode set
//lcd_cmd(0x1C); //move cursor

}

void main(void)
{
char str[] = "Welcome";
int len;
int i;
TRISC=0;
TRISD=0;
init_lcd();

len=sizeof(str);
for( i=0;i<=len;i++) //for sending commands character by character
{
lcd_data(str);
}
lcd_cmd(0x0c);
lcd_cmd(0x02);
}




 

Hi all

Trying to figure out how to send info to LCD 2x16. ...................................
First problem On compiling "MikroC"
8 393 'lcd_cmd' Identifier redefined LCD 2 x 6.c

Second problem I cannot Identify which pins from the f877 go to where on the LCD. I have a feeling that the pins are already configured somewhere else and this is why it complains about the "Identifier redefined"

I think problem … built in functions you are redefined.


sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

void main(){
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,"Hi WStevens_sa ");
Lcd_Out(2,1,"It's Simple");

}

 
You are 100% right Denshil. Thanks for the help.

I found this with the pin outs. If anybody else has this problem. This is the most basic of connecting LCD to 887.

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

char txt1[] = "mikroElektronika";
char txt2[] = "EasyPIC6";
char txt3[] = "Lcd4bit";
char txt4[] = "example";

char i; // Loop variable

void Move_Delay() { // Function used for text moving
Delay_ms(500); // You can change the moving speed here
}

void main(){

ADCON1=6;

Lcd_Init(); // Initialize LCD

Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,6,txt3); // Write text in first row

Lcd_Out(2,6,txt4); // Write text in second row
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display

Lcd_Out(1,1,txt1); // Write text in first row
Lcd_Out(2,5,txt2); // Write text in second row

Delay_ms(2000);

// Moving text
for(i=0; i<4; i++) { // Move text to the right 4 times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}

while(1) { // Endless loop
for(i=0; i<8; i++) { // Move text to the left 7 times
Lcd_Cmd(_LCD_SHIFT_LEFT);
Move_Delay();
}

for(i=0; i<8; i++) { // Move text to the right 7 times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}
}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top