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.

Initialization routine for 16x1 LCD (KS0076B)

Status
Not open for further replies.

Kabanga

Member level 4
Joined
Oct 4, 2007
Messages
76
Helped
7
Reputation
14
Reaction score
1
Trophy points
1,288
Activity points
1,720
Hi everyone,
somebody got a working initialization routine for 16x1 LCD (KS0076B)?
I appreciate your help.

Regards
Kabanga
 

Tahmid said:
Hi,
Which language and compiler are you using?
Tahmid.

Hi Tahmid,
I'm using MPLAB C18 and programming in C language.

Best regards
Kabanga
 

Hi,
Give me some time, I will try to provide code.

Added after 21 minutes:

Code:
#include <p18f458.h>

#pragma config OSC = XT //Crystal oscillator
#pragma config WDT = OFF //Watchdog Timer off
#pragma config LVP = OFF //LVP off

void main(void);
void lcdcmd(unsigned char value);
void lcddata(unsigned char value);
void MSDelay(unsigned int time);

#define rs PORTBbits.RB0
#define rw PORTBbits.RB1
#define en PORTBbits.RB2
#define port PORTD

void main(void){
	char a;
	char b[5]={'H','E','L','L','O'};
	TRISD = 0;
	TRISB = 0;
	PORTD = 0;
	PORTB = 0;
	en = 0;
	MSDelay(250);
	lcdcmd(0x0C); //display on, cursor off
	MSDelay(15);
	lcdcmd(0x01); //clear LCD
	MSDelay(15);
	lcdcmd(0x06); //shift cursor right
	MSDelay(15);
	lcdcmd(0x80); //first row, first column
	MSDelay(15);
	for(a=0;a<5;a++){
		lcddata(b[a]);
		MSDelay(15);
	}
	while(1);
}

void lcdcmd(unsigned char value){
	port = value;
	rs = 0;
	rw = 0;
	en = 1;
	MSDelay(1);
	en = 0;
}

void lcddata(unsigned char value){
	port = value;
	rs = 1;
	rw = 0;
	en = 1;
	MSDelay(1);
	en = 0;
}

void MSDelay(unsigned int itime){
	unsigned int i, j;
	for(i=0;i<itime;i++)
		for(j=0;j<135;j++);
}
This program writes "HELLO" on LCD.
48_1263058066.gif
 

Hi,
thansks a lot for the code. I'll give it a try and will tell you the outcome.

I have a question: I'm not understanding the delay routine MSDelay(). Could explain to me how it works?

Regards
Kabanga
 

Hi,
The delay routine is made as such that with a 10MHz crystal, it will produce a delay equal to the variable value passed in milliseconds.
So, MSDelay(250) yields a delay time of approximately 250ms, although this is for rough timing as it is not most accurate. More accurate timings can be done with ASM code or internal timer modules.

Added after 1 minutes:

Hope this helps and let me know how it works out for you.
Tahmid.
 

Hi,
Im having problems with the initialization.
Since I'm using a 4MHz cristal, I must ajust the timing (MSDelay)
I need the following delays: 20ms, 5ms, 1ms, 200us and 500ns
I'm trying to figure out how to modify your MSDelay. Any help?

Regards
Kabanga
 

Hi,
With 4MHz crystal, 500ns is not possible. Instead try using the TMR modules for the different time values. You should take a look at mikroC compiler. Very helpful with internal delay routines.
Tahmid.
 

    Kabanga

    Points: 2
    Helpful Answer Positive Rating
Hi,
thanks a lot for your help!

Regars
Kabanga
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top