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.

16x2 4 bit LCD Display 18f4520 (picdem 2 plus)

Status
Not open for further replies.

sam217

Newbie level 3
Newbie level 3
Joined
Jun 27, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,315
Hi,
This is my program to interface LCD with PIC DEM 2 plus (18f4520 pic microcontroller).when i m trying tgo display single charcter then its working fine but wen i want to display string some jumbled dchars r being displayed.plz help me.


#include <p18f4520.h>

#pragma config WDT=OFF
#define LCD_RS LATDbits.LATD4 // Register select
#define LCD_EN LATDbits.LATD6 // Enable
#define LCD_RW LATDbits.LATD5 // Read write
#define LCD_D4 LATDbits.LATD0 // Data bits
#define LCD_D5 LATDbits.LATD1 // Data bits
#define LCD_D6 LATDbits.LATD2 // Data bits
#define LCD_D7 LATDbits.LATD3 // Data bits

#define LCD_STROBE ((LCD_EN = 1),(LCD_EN=0))

void lcd_write(unsigned char);
void lcd_clear(void);
void lcd_puts(unsigned char * );
void lcd_putch(unsigned char );
void lcd_goto1(unsigned char );
void lcd_goto2(unsigned char );
void lcd_init(void);
void Delay(unsigned int);
unsigned int j=0;


/* write a byte to the LCD in 4 bit mode */

void lcd_write(unsigned char c)
{

PORTD = (PORTD & 0xF0) | (c >> 4);
LCD_STROBE;
PORTD = (PORTD & 0xF0) | (c & 0x0F);
LCD_STROBE;
Delay(400);
}

/*
* Clear the LCD
*/

void lcd_clear(void)
{
LCD_RS = 0;
LCD_RW=0;
lcd_write(0x1);
Delay(2);
}

/* write a string of chars to the LCD */




void lcd_puts(unsigned char * s)
{
LCD_RS = 1; // write characters
while(*s)
lcd_write(*s++);
}



/* write one character to the LCD */

void lcd_putch(unsigned char c)
{
LCD_RS =1; // write characters

lcd_write(c);
}



/*void lcd_puts(char str[15]) {
char d;
while(str!='\0') {
d = str ;
lcd_write(d);
}
}
*/



/*
* Go to the specified position in line 1
*/

void lcd_goto1(unsigned char pos)
{
LCD_RS = 0;

lcd_write(0x80 + pos);
}

/*
* Go to the specified position in line 2
*/

void lcd_goto2(unsigned char pos)
{
LCD_RS = 0;

lcd_write(0xC0 + pos);
}
/* initialise the LCD - put into 4 bit mode */

void lcd_init(void)
{
LCD_RS = 0; // write control bytes

Delay(150);// power on delay

LCD_D4 = 1; // init!
LCD_D5 = 1; //
LCD_STROBE;
Delay(50);

LCD_STROBE; // init!
Delay(1000);

LCD_STROBE; // init!
Delay(50);

LCD_D4 = 0; // set 4 bit mode
LCD_STROBE;
Delay(400);

lcd_write(0x28);// 4 bit mode, 1/16 duty, 5x8 font, 2lines
lcd_write(0x0C);// display on
lcd_write(0x06);// entry mode
lcd_write(0x01);// clear display and reset cursor
}

void main()
{

TRISD=0X00; //port D as o/p
PORTD=0X00; //clear port D

lcd_init(); //initialize lcd
lcd_goto1(1);

lcd_putch('H');/*Hi ! is being displayed
lcd_putch('i');
lcd_putch('!');

lcd_puts("Welcome"); //but lcd_puts is not working garbage datas are being dislayed

for(;;);


}


void Delay(unsigned int i)
{
unsigned int j;
for(j=0;j<i;j++);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top