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 code for 4-bit LCD

Status
Not open for further replies.

abhay1581

Newbie level 2
Joined
Aug 18, 2006
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,293
hi friends.
i'm interfacing LCD with 89S8252 n i'm using that LCD in 4-bit mode.
can anybody tell me the exact initialization code for LCD?[/b]
 

4 bit lcd init

For an exact initialization code it's important to know the exact LCD controller type.
 

gui lenh lcd 4 bit

Here is init routine for LCD 4-bit and Using PIC. Compiler is CCS

// lcd_lib_4bit.c
#include <stddef.h>

#define LCD_RS PIN_D2
//#define LCD_RW PIN_A1
#define LCD_EN PIN_D3

#define LCD_D4 PIN_D4
#define LCD_D5 PIN_D5
#define LCD_D6 PIN_D6
#define LCD_D7 PIN_D7

// misc display defines-
#define Line_1 0x80
#define Line_2 0xC0
#define Clear_Scr 0x01

// prototype statements
#separate void LCD_Init ( void );// ham khoi tao LCD
#separate void LCD_SetPosition ( unsigned int cX );//Thiet lap vi tri con tro
#separate void LCD_PutChar ( unsigned int cX );// Ham viet1kitu/1chuoi len LCD
#separate void LCD_PutCmd ( unsigned int cX) ;// Ham gui lenh len LCD
#separate void LCD_PulseEnable ( void );// Xung kich hoat
#separate void LCD_SetData ( unsigned int cX );// Dat du lieu len chan Data
// D/n Cong
#use standard_io ( B )
#use standard_io (A)

//khoi tao LCD**********************************************
#separate void LCD_Init ( void )
{
LCD_SetData ( 0x00 );
delay_ms(200);
output_low ( LCD_RS ); // Command mode
LCD_SetData ( 0x03 ); //
LCD_PulseEnable();
LCD_PulseEnable();
LCD_PulseEnable();
LCD_SetData ( 0x02 );
LCD_PulseEnable();
LCD_PutCmd ( 0x2C );
LCD_PutCmd ( 0b00001100);
LCD_PutCmd ( 0x06 );
LCD_PutCmd ( 0x01 );
}

#separate void LCD_SetPosition ( unsigned int cX )
{
/* this subroutine works specifically for 4-bit Port A */
LCD_SetData ( swap ( cX ) | 0x08 );
LCD_PulseEnable();
LCD_SetData ( swap ( cX ) );
LCD_PulseEnable();
}

#separate void LCD_PutChar ( unsigned int cX )
{
/* this subroutine works specifically for 4-bit Port A */
output_high ( LCD_RS );
LCD_PutCmd( cX );
output_low ( LCD_RS );
}

#separate void LCD_PutCmd ( unsigned int cX )
{
/* this subroutine works specifically for 4-bit Port A */
LCD_SetData ( swap ( cX ) ); /* send high nibble */
LCD_PulseEnable();
LCD_SetData ( swap ( cX ) ); /* send low nibble */
LCD_PulseEnable();
}
#separate void LCD_PulseEnable ( void )
{
output_high ( LCD_EN );
delay_us ( 3 ); // was 10
output_low ( LCD_EN );
delay_ms ( 3 ); // was 5
}

#separate void LCD_SetData ( unsigned int cX )
{
output_bit ( LCD_D4, cX & 0x01 );
output_bit ( LCD_D5, cX & 0x02 );
output_bit ( LCD_D6, cX & 0x04 );
output_bit ( LCD_D7, cX & 0x08 );
}

Gft from vietnam
www.dientuvietnam.net

Added after 5 minutes:

For AT89 and AVR is the same routine
 

    abhay1581

    Points: 2
    Helpful Answer Positive Rating
bit swapping 4bit

thanks linhnc308.............................
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top