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.

LCD shift right and shift left bugs.

Status
Not open for further replies.

Armia Wagdy

Newbie level 4
Joined
Nov 14, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
38
I have made a library for LCD, and from the datasheet I read that the code 0x18 will shift the entire display to the left, but when I made that, the display disappears.
I have also read that 0x1C shifts the entire display to the right but when I made it, the entire display shifts to left.

this is my "LCD.h"
Code:
/*
 * LCD.h
 *
 * Created: 11/14/2013 7:51:54 PM
 *  Author: A R M T
 */ 


#ifndef LCD_H_
#define LCD_H_
#define F_CPU 1000000UL
#define __DELAY_BACKWARD_COMPATIBLE__
#include <util/delay.h>
#define LCD_DPRT PORTA                   //LCD DATA PORT
#define LCD_DDDR DDRA                    //LCD DATA DDR
#define LCD_DPIN PINA                    //LCD DATA PIN
#define LCD_CPRT PORTB                   //LCD COMMANDS PORT
#define LCD_CDDR DDRB                    //LCD COMMANDS DDR
#define LCD_CPIN PINB                    //LCD COMMANDS PIN
#define LCD_RS 0                         //LCD RS
#define LCD_RW 1                         //LCD RW
#define LCD_EN 2                         //LCD EN

void delay_us(unsigned int d);
void lcdCommand(unsigned char cmnd);
void lcdData(unsigned char data);
void lcd_init(void);
void lcd_gotoxy(unsigned char x, unsigned char y);
void lcd_print(char *str);

#endif /* LCD_H_ */

___________________________________________________________________________________________________________

"LCD.c"
Code:
/*
 * LCD.c
 *
 * Created: 11/14/2013 7:49:36 PM
 *  Author: A R M T
 */ 

#include <avr/io.h>
#include "LCD.h"

//*************************************************************
void delay_us(unsigned int d)
{
	_delay_us(d);
}
//*************************************************************
void lcdCommand(unsigned char cmnd)
{
	LCD_DPRT = cmnd;                   //send cmnd to data port
	LCD_CPRT &= ~(1<<LCD_RS);          //RS = 0 for command
	LCD_CPRT &= ~(1<<LCD_RW);          //RW = 0 for write
	LCD_CPRT |= (1<<LCD_EN);           //EN = 1 for H-to-l pulse
	delay_us(1);                       //Wait to make enable wide
	LCD_CPRT &= ~(1<<LCD_EN);          //EN = 1 for H-to-l pulse
	delay_us(100);                     //Wait to make enable wide
}
//*************************************************************
void lcdData(unsigned char data)
{
	LCD_DPRT = data;                    //send data to data port
	LCD_CPRT |= (1<<LCD_RS);			//RS = 1 for data
	LCD_CPRT &= ~(1<<LCD_RW);			//RW = 0 for write
	LCD_CPRT |= (1<<LCD_EN);            //EN = 1 for H-to-L pulse
	delay_us(1);						//wait to make enable wide
	LCD_CPRT &= ~(1<<LCD_EN);           //EN = 0 for H-to-L pulse
	delay_us(100);						//wait to make enable wide
}
//*************************************************************
void lcd_init(void)
{
	LCD_DDDR = 0xFF;
	LCD_CDDR = 0xFF;
	
	LCD_CPRT &= ~(1<<LCD_EN);			//LCD_EN = 0
	delay_us(15000);                    //wait for init
	lcdCommand(0x38);                   //init. LCD 2 line, 5 * 7 matrix
	lcdCommand(0x0E);					//display on, cursor on
	lcdCommand(0x01);					//clear LCD
	delay_us(2000);						//wait
	lcdCommand(0x06);					//shift cursor right
}
//*************************************************************
void lcd_gotoxy(unsigned char x, unsigned char y)
{
	unsigned char firstCharAdr[] = {0x80, 0xC0, 0x94, 0xD4};
	lcdCommand(firstCharAdr[y-1] + x - 1);
	delay_us(100);
}
//*************************************************************
void lcd_print(char *str)
{
	unsigned char i = 0;
	while (str[i] != 0)
	{
		lcdData(str[i]);
		i++;
	}
}
//*************************************************************
________________________________________________________________________

"App.c"

Code:
/*
 * main.c
 *
 * Created: 11/14/2013 7:54:02 PM
 *  Author: A R M T
 */ 
#include <avr/io.h>
#include "LCD.h"

int main(void)
{

	lcd_init();
	lcd_gotoxy(11,1);
	lcd_print("Armia");
	lcd_gotoxy(11,2);
	lcd_print("Wagdy");
	_delay_ms(1000 / 2);
	lcdCommand(0x18);     //shift the entire diplay to left
	while(1);
	return 0;
}

I meant that when I burned this code I excepected that aftr(1000 / 2) ms this output will shift to left
1.PNG

but what appear was:
2.PNG
Can any one help me in that problem please?!
 
Last edited:

I have made a library for LCD, and from the datasheet I read that the code 0x18 will shift the entire display to the left, but when I made that, the display disappears.
I have also read that 0x1C shifts the entire display to the right but when I made it, the entire display shifts to left.

this is my "LCD.h"
Code:
/*
 * LCD.h
 *
 * Created: 11/14/2013 7:51:54 PM
 *  Author: A R M T
 */ 


#ifndef LCD_H_
#define LCD_H_
#define F_CPU 1000000UL
#define __DELAY_BACKWARD_COMPATIBLE__
#include <util/delay.h>
#define LCD_DPRT PORTA                   //LCD DATA PORT
#define LCD_DDDR DDRA                    //LCD DATA DDR
#define LCD_DPIN PINA                    //LCD DATA PIN
#define LCD_CPRT PORTB                   //LCD COMMANDS PORT
#define LCD_CDDR DDRB                    //LCD COMMANDS DDR
#define LCD_CPIN PINB                    //LCD COMMANDS PIN
#define LCD_RS 0                         //LCD RS
#define LCD_RW 1                         //LCD RW
#define LCD_EN 2                         //LCD EN

void delay_us(unsigned int d);
void lcdCommand(unsigned char cmnd);
void lcdData(unsigned char data);
void lcd_init(void);
void lcd_gotoxy(unsigned char x, unsigned char y);
void lcd_print(char *str);

#endif /* LCD_H_ */

___________________________________________________________________________________________________________

"LCD.c"
Code:
/*
 * LCD.c
 *
 * Created: 11/14/2013 7:49:36 PM
 *  Author: A R M T
 */ 

#include <avr/io.h>
#include "LCD.h"

//*************************************************************
void delay_us(unsigned int d)
{
	_delay_us(d);
}
//*************************************************************
void lcdCommand(unsigned char cmnd)
{
	LCD_DPRT = cmnd;                   //send cmnd to data port
	LCD_CPRT &= ~(1<<LCD_RS);          //RS = 0 for command
	LCD_CPRT &= ~(1<<LCD_RW);          //RW = 0 for write
	LCD_CPRT |= (1<<LCD_EN);           //EN = 1 for H-to-l pulse
	delay_us(1);                       //Wait to make enable wide
	LCD_CPRT &= ~(1<<LCD_EN);          //EN = 1 for H-to-l pulse
	delay_us(100);                     //Wait to make enable wide
}
//*************************************************************
void lcdData(unsigned char data)
{
	LCD_DPRT = data;                    //send data to data port
	LCD_CPRT |= (1<<LCD_RS);			//RS = 1 for data
	LCD_CPRT &= ~(1<<LCD_RW);			//RW = 0 for write
	LCD_CPRT |= (1<<LCD_EN);            //EN = 1 for H-to-L pulse
	delay_us(1);						//wait to make enable wide
	LCD_CPRT &= ~(1<<LCD_EN);           //EN = 0 for H-to-L pulse
	delay_us(100);						//wait to make enable wide
}
//*************************************************************
void lcd_init(void)
{
	LCD_DDDR = 0xFF;
	LCD_CDDR = 0xFF;
	
	LCD_CPRT &= ~(1<<LCD_EN);			//LCD_EN = 0
	delay_us(15000);                    //wait for init
	lcdCommand(0x38);                   //init. LCD 2 line, 5 * 7 matrix
	lcdCommand(0x0E);					//display on, cursor on
	lcdCommand(0x01);					//clear LCD
	delay_us(2000);						//wait
	lcdCommand(0x06);					//shift cursor right
}
//*************************************************************
void lcd_gotoxy(unsigned char x, unsigned char y)
{
	unsigned char firstCharAdr[] = {0x80, 0xC0, 0x94, 0xD4};
	lcdCommand(firstCharAdr[y-1] + x - 1);
	delay_us(100);
}
//*************************************************************
void lcd_print(char *str)
{
	unsigned char i = 0;
	while (str[i] != 0)
	{
		lcdData(str[i]);
		i++;
	}
}
//*************************************************************
________________________________________________________________________

"App.c"

Code:
/*
 * main.c
 *
 * Created: 11/14/2013 7:54:02 PM
 *  Author: A R M T
 */ 
#include <avr/io.h>
#include "LCD.h"

int main(void)
{

	lcd_init();
	lcd_gotoxy(11,1);
	lcd_print("Armia");
	lcd_gotoxy(11,2);
	lcd_print("Wagdy");
	_delay_ms(1000 / 2);
	lcdCommand(0x18);     //shift the entire diplay to left
	while(1);
	return 0;
}

I meant that when I burned this code I excepected that aftr(1000 / 2) ms this output will shift to left
View attachment 98523

but what appear was:
View attachment 98524
Can any one help me in that problem please?!

Put this command on the init section....


Code:
lcdCommand(0x18);
 

Did you mean that the function init in LCD.c will be like that
Code:
"LCD.c"
[CODE]
/*
 * LCD.c
 *
 * Created: 11/14/2013 7:49:36 PM
 *  Author: A R M T
 */ 

#include <avr/io.h>
#include "LCD.h"
/******************************************************
void lcd_init(void)
{
	LCD_DDDR = 0xFF;
	LCD_CDDR = 0xFF;
	
	LCD_CPRT &= ~(1<<LCD_EN);			//LCD_EN = 0
	delay_us(15000);                    //wait for init
	lcdCommand(0x38);                   //init. LCD 2 line, 5 * 7 matrix
	lcdCommand(0x0E);					//display on, cursor on
	lcdCommand(0x01);					//clear LCD
	delay_us(2000);						//wait
	lcdCommand(0x06);					//shift cursor right
        delay_us(2000);
        lcdCommand(0x18);                                      
}

I have tried it and it doesn't work, nothing is appeared on the LCD :(
 

I want to shift the entire display just one position to left using 0x18 :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top