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.

Looking for a sample code for using LCD module with a LC60 microcontroller

Status
Not open for further replies.

NPstudent123

Newbie level 3
Joined
Jun 23, 2009
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Singapore
Activity points
1,322
hi im trying to get my LCD working.. but so far nothing seems to be working..
im using a LC60 microcontroller and my LCD module is 164A-BC-BC from displaytech. can anybody help me? jus post a sample prog so that i can at least get 1word or so.. and my program debugger is codewarrior. THKS so much
 

smple code for lcd

search on google you will find it easy. most of the LCDs are compatible.
 

lcd_read-data

dats the damn prob.. i search on google and i cant find a shit.. can some 1 plz help me out.. im gonna fail my final year project if this goes on =/
 

codewarrior delay100us

apparently it doesnt help.. the lcd, mcu and compiler used are all different... =(
 

lm044l

No one will work entirely for you. You'll have to understand the things suggested by others & you'll have to modify them according to your needs. What CMOS has given you i think is more than sufficient. Still I'm sending you the direct link for the same site he suggested.
https://mcu-programming.blogspot.com/2006/09/lcd-interfacing.html

there are two files on the page
lcd.h
test_lcd.c

Download them. Read them & understand & then implement them accordingly.
 

sample code for lcd

apparently i tried it but it still doesnt work.. my lcd seems to be running via internal reset circuit.. and none of my commands seem to go through it.. let me show my code.. hope some 1 can help.. im using codewarrior as my c compiler

LCD.c
void LCD_writeData(unsigned char ucUsrData) {
LCD_RS = 1; //Data mode
LCD_dataout(ucUsrData); //Send out user data
LCD_RW = 0; //Write mode
LCD_E=0;
LCD_E = 1; //E clock goes high
LCD_E = 0; //E clock goes low
LCD_RW = 1; //Set back to read mode
}

void LCD_readData(unsigned char ucUsrData) {
LCD_RS = 1; //Data mode
LCD_dataout(ucUsrData); //Send out user data
LCD_RW = 1; //Read mode
LCD_E = 0;
LCD_E = 1; //E clock goes high
LCD_E = 0; //E clock goes low
LCD_RW = 0; //Set back to write mode
}

void LCD_writeCmd(unsigned char ucUsrCmd) {
LCD_RS = 0; //Command mode
LCD_dataout(ucUsrCmd); //Send out user data
LCD_RW = 0; //Write mode
LCD_E = 1; //E clock goes high
LCD_E = 0; //E clock goes low
LCD_RW = 1; //Set back to read mode
LCD_RS = 1; //Set back to data mode
}

void LCD_Init(void) {
delay100us(160);
LCD_writeCmd(0x30);
delay100us(42);
LCD_writeCmd(0x30);
delay100us(1);
LCD_writeCmd(0x30);
delay100us(1);
LCD_writeCmd(0x38); //Function Set
delay100us(1);
LCD_writeCmd(0x08); //Display Off
delay100us(1);
LCD_writeCmd(0x01); //Display Clear
delay100us(1);
LCD_writeCmd(0x02); //Return Home
delay100us(1);
LCD_writeCmd(0x06); //Entry Mode Set
delay100us(1);
LCD_writeCmd(0x0F); //Display On
delay100us(1);
LCD_writeCmd(0x14); //Shift
delay100us(1);
LCD_writeCmd(0x38); //Function Set
delay100us(1);
LCD_writeCmd(0x40); //CG Ram Address
delay100us(1);
LCD_writeCmd(0x80); //DD Ram Address
}

void LCD_puts(unsigned char *lcd_string) {
while (*lcd_string) {
LCD_writeData(*lcd_string++);
}
}
main.c
void main(void){
SOPT1_COPE=0; //0=disable watchdog timer
LCD_hardwarePortInit(); //initalise ports required to operate LCD
LCD_Init(); //initialise LCD
LED1_init();
LED8_init();
for(;;) {
LCD_row1();
LCD_puts("Hello LCD");
LCD_row2();
LCD_puts("< Line 2: OK >");
} /* loop forever */
 

Re: sample code for LCD

What is your MCU clock frequency?
May be you need some NOP delays between transition of Enable pin.
 

Re: sample code for LCD

Here is complete working code of LCD LM044L interfaced with ATmega32 and simulated in Proteus:

Code:
//ICC-AVR application builder : 5/29/2009 5:58:38 PM
// Target : M32
// Crystal: 7.3728Mhz
// one instruction cycle =insc=0.13563368055555555555555555555556 usec
// 8insc=1.08usec
#include <iom32v.h>
#include <macros.h>

 /* defining pins for control signals */
 #define  RS  	     0x01             /* register select DR/IR: 1/0*/
 #define  RW  	     0x02	          /* read/write: 1/0 */
 #define  E   	     0x04             /* enable/disable:: 1/0*/
 #define  busyCheck  0x80             /* busy checking bit */
 
 
/******************************  defining commands to run  ************************************/
 unsigned char spec         = 0x38;	  // for specifications as lines and char pixels i.e 5x8
 unsigned char LcdCur_ON    = 0x0E;	  // Cursor ON/OFF:: 1/0
 unsigned char Lcd_Clr      = 0x01;	  // Clear LCD
 unsigned char Curser_Right = 0x06;     // cursor movement to right direction
 unsigned char Curser_HOME  = 0x02;	  // Move cursor to home location
/*********************************************************************************************/ 
/* text to display on LCD */
 //unsigned char *text = " Muhammad Yasir     ";
 //unsigned char *engr = " Manager Technical";
 
 unsigned char *text = " Engineer           ";
 unsigned char *engr = " Muhammad Yasir";

 unsigned int j=0,k=0;
 /* signatures of the function being to used*/
 void init(void);			/* LCD initialization function */
 void writeCmd( unsigned char );		/* function to run the commands on LCD*/
 void getReady(void);		/* function to check either LCD free or in process i.e busy */
 void writeString(unsigned char *);	/* function to write data/text to LCD. geting a pointer parameter.*/
 /***********************************************************************************************/
 delay_1uSec(unsigned int);
 
 delay_1uSec(unsigned int m) // approximately m*1uSec Delay
 {
    for(j=0;j<m;j++)
	{
	   for(k=0;k<8;k++)
	   asm("nop");
    }
 }
 
 
void port_init(void)
{
 	 PORTA = 0x00;
 	 DDRA  = 0x00;
 	 PORTB = 0x00;
 	 DDRB  = 0x00;
 	 PORTC = 0x00; 
 	 DDRC  = 0xFF;
 	 PORTD = 0x00;
 	 DDRD  = 0xFF;
}

//TIMER0 initialize - prescale:8
// WGM: Normal
// desired value: 8KHz
// actual value:  8.021KHz (0.3%)
void timer0_init(void)
{
 	 TCCR0 = 0x00; //stop
 	 TCNT0 = 0x45; //set count
 	 OCR0  = 0xBB;  //set compare
 	 TCCR0 = 0x02; //start timer
}

#pragma interrupt_handler timer0_ovf_isr:iv_TIM0_OVF
void timer0_ovf_isr(void)
{
 	 TCNT0 = 0x45; //reload counter value
}



//call this routine to initialize all peripherals
void init_devices(void)
{
 	 //stop errant interrupts until set up
 	 CLI(); //disable all interrupts
 	 port_init();
 	 timer0_init();

 	 MCUCR = 0x00;
 	 GICR  = 0x00;
 	 TIMSK = 0x00; //timer interrupt sources
 	 SEI(); //re-enable interrupts
 	 //all peripherals are now initialized
}

//
void main(void)
{
 	 init_devices();
 	 //insert your functional code here...
	 for(;;)
	 {
	  	init();		         /* call to initialization function*/
 		//delay_1uSec(1);
		writeString(text);	 /*sending text to lcd by calling writeString() function */
 		//delay_1uSec(1);
		
		writeString(engr);   /*sending text to lcd by calling writeString() function */
 	 
	 }
	 
}

void init()			 /* init() function defination. this funcatin sends commnads to the LCD for */
{				     /* initialization by calling the writeCmd(bit8) function.*/
	 writeCmd(spec);
	 delay_1uSec(1);
	 writeCmd(LcdCur_ON);
	 delay_1uSec(1);
	 writeCmd(Lcd_Clr);
	 delay_1uSec(1);
	 writeCmd(Curser_Right);
	 delay_1uSec(1);
	 writeCmd(Curser_HOME);
	 delay_1uSec(1);
}

/* function defination for writeCmd(bit8) */
void writeCmd(unsigned char cmd)
{
 	 getReady();		 /* function for checking either is LCD not busy?*/
 	 //E = 0;            /* make sure LCD not selected. that not be during initializing process*/
 	 delay_1uSec(1);
	 PORTC &= ~E;        /* make sure LCD not selected. that not be during initializing process*/
	 //P3 = cmd;		 /* sending commmand to port3 bcz lcd conneted to..... */
	 delay_1uSec(1);
	 PORTD = cmd;		 /* sending commmand to port3 bcz lcd conneted to..... */
 	 //RS = 0;	         /*Select instruction register*/
	 delay_1uSec(1);
	 PORTC &= ~RS;	     /*Select instruction register*/
 	 //RW = 0;	  		 /* Write select control */
	 delay_1uSec(1);
	 PORTC &= ~RW;	  	 /* Write select control */
 	 //E = 1;
	 delay_1uSec(1);
	 PORTC |= E;
 	 //E = 0;
	 delay_1uSec(1);
	 PORTC &= ~E;
	 delay_1uSec(1);
}

/* Check busy bit7 of the port3: function defination */

void getReady()
{
    //E = 0;  				 /* make sure lcd is not selected */
	PORTC &= ~E;  				 /* make sure lcd is not selected */
	//busyCheck = 1;  	         /*  Make input Bit */
	delay_1uSec(1);
	PORTD |=busyCheck;  	         /*  Make input Bit */
	//RS = 0;				 /*  Command Register select */
	delay_1uSec(1);
	PORTC &= ~RS;				 /*  Command Register select */
	//RW = 1;	 			 /*  Read from LCD */
	delay_1uSec(1);
	PORTC |= RW;	 			 /*  Read from LCD */
	//while (busyCheck != 0)
	delay_1uSec(1);
	while ( (PIND & busyCheck) != 0x80) 
	{
		//E = 0;
		PORTC &= ~E;
		delay_1uSec(1);
		//E = 1;
		PORTC |= E;
		delay_1uSec(1);
	}
  //E = 1;
  PORTC |= E;
  delay_1uSec(1);
}
 /* function defination to display data on LCD*/
void writeString(unsigned char *str)
{
 unsigned char i;
	unsigned int j;
	getReady();
	// E = 0;   			 /* make sure lcd is not selected	*/
	delay_1uSec(1);
	PORTC &= ~E;   			 /* make sure lcd is not selected	*/
	delay_1uSec(1);
	for(i=0;str[i]!='\0';i++)
		{
			//P3=str[i];
			PORTD=str[i];
			delay_1uSec(1);
			//RS = 1;
			PORTC |= RS;
			delay_1uSec(1);
			//RW = 0;
			PORTC &= ~RW;
			delay_1uSec(1);
			//E = 1;
			PORTC |= E;
			delay_1uSec(1);
			//E = 0;
			PORTC &= ~E;
			
			//for(j = 0; j<25000; j++)
			delay_1uSec(2000);
			
	    }
 }


The clock frequency of the Crystal Oscillator is 7.3728MHz.The schematic diagram is also attached with this post

regards
m.yasir
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top