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.

A good LCD code library

Status
Not open for further replies.

RollingEEE

Full Member level 3
Joined
Mar 25, 2006
Messages
165
Helped
8
Reputation
16
Reaction score
7
Trophy points
1,298
Location
Bangladesh
Activity points
2,406
16x04 lcd display

Hi,
I need some LCD codes for 8051 and AVR microcontrollers in C. The code should be very portable, and the delays should also be independent of oscillator frequency to ensure portability. and the library should have all standard C functions like printf, puts, gotoxy, as well as additional functions like cursor on . . .

N.B. I actually want to make the library, so if any one is interested, we can do it together
 


    RollingEEE

    Points: 2
    Helpful Answer Positive Rating
download library 8051io.h

yes nice. now I want a 8051 based lcd library.
 

lcdwritestring avr

this 8051 code is good, but the ports are almost fixed, not flexible without drastically changing the code. I tried to use it with S52, 16x04 LCD display, and Raisonace IDE (RIDE) but it did not work
 

avrlib.zip pascal stang

Would you like to attach your Raisonace 8051 LCD driver source code? I'll check it
 

    RollingEEE

    Points: 2
    Helpful Answer Positive Rating
8051 code library

example library using MicroC

/***************************************************************************
;
; This module is presented here only to serve as a sample for
; 8051 program development. BiPOM Electronics provides this module as is and
; does not guarantee its functionality or suitability for a particular purpose.
; Please e-mail any questions and suggestions to info@bipom.com;
;
; Module: LCD.C
;
; Revision: 1.01
;
; Description: Interface routines for driving a alphanumeric
; Liquid Crystal Display module using 8051 micro-controller.
; LCD is driven by only 4 data lines ( 4-bit mode )
;
; This program is written using Micro-C Compiler from
; Dunfield Development Systems.
;
*/


#include <8051io.h>
#include <8051bit.h> /* Bit set/clear macros */
#include <8051reg.h>



#define READ P3.5 /*READ=SET & WRITE=RESET*/
#define STROBE P3.4 /*DATA STROBE (ENABLE)*/
#define CTRL P3.7 /*CONTROL BIT (CONTROL=RESET & DATA=SET)*/



void InitLCD();
void WriteCtrl( unsigned char value );
void WriteData( unsigned char value );
void WriteCommon( unsigned char value );
void WriteLCD( unsigned char* message );
void CursorHome();
void CursorSet( unsigned char pos );


main()
{
/* Initialize the LCD as the very first thing */
InitLCD();

/* Write a simple message to the LCD */
CursorHome();
WriteLCD( "Hello" );

/* Keep the message for 2 seconds ( 1 second on MINI-MAX/51-C ) */
delay(2000);

/* Clear the LC display */
CursorHome();
WriteLCD( " " );

/* Example of writing to anywhere on the display */
CursorSet(5);
WriteData( 'x' );
WriteData( 'y' );
WriteData( 'z' );
}


/***************************************************************************
; Function: InitLCD
;
; Description: Initializes the LCD
;
; Inputs: none
;
; Returns: nothing
;**************************************************************************/
void InitLCD()
{
/* Wait a bit after power-up */
delay(200);

/* Initialize the LCD to 4-bit mode */
WriteCtrl(3);
delay(50);

WriteCtrl(3);
delay(10);

WriteCtrl(3);
delay(10);

WriteCtrl(2);
delay(10);

/* Function Set */
WriteCtrl(2);
delay(10);

WriteCtrl(8);
delay(10);

/* Display OFF */
WriteCtrl(0);
delay(10);

WriteCtrl(8);
delay(10);

/* Display ON */
WriteCtrl(0);
delay(10);

WriteCtrl(0x0F);
delay(10);

/* Entry mode */
WriteCtrl(0);
delay(10);

WriteCtrl(6);
delay(10);

/* Clear Screen */
WriteCtrl(0);
delay(10);

WriteCtrl(1);
delay(100);

/* Cursor home */
WriteCtrl(0);
delay(10);

WriteCtrl(2);
delay(100);
}


void CursorSet( unsigned char pos )
{
WriteCtrl(8);
delay(1);

WriteCtrl(pos);
delay(1);
}

void CursorHome()
{
/* Cursor home */
WriteCtrl(0);
delay(1);

WriteCtrl(2);
delay(1);
}

void WriteLCD( unsigned char* message )
{
unsigned char i;

for( i=0; i<20; i++ )
{
if( !message )
break;

WriteData(message);
}
}

void WriteCtrl( unsigned char value )
{
clrbit(CTRL);

WriteCommon( value );
}

void WriteData( unsigned char value )
{
setbit(CTRL);

WriteCommon( value >> 4 );
WriteCommon( value );
}

void WriteCommon( unsigned char value )
{
clrbit(READ);

value = value & 0x0F;

value = value << 2;
value |= 0xC3;

P1 = value;

setbit(STROBE);
delay(1);
clrbit(STROBE);
setbit(READ);

delay(1);
}

regards
 

budhy said:
Would you like to attach your Raisonace 8051 LCD driver source code? I'll check it


#include <reg52x2.h>


/*****************************************************************************
* LCD control functions.
* lcd.c
* © 2004,2006 ASP Digital. All rights reserved. * Andy Peters, ASP Digital
* devel@latke.net
*
* various functions to support the usual sort of LCD display.
* Created: 19 Jul 2004
* Modified:
* 11 Dec 2006: Add LcdWriteCGRAM().
****************************************************************************/
#include "lcd.h"
#include "lcdcmd.h"

/*
* Private prototypes:
*/
void LcdWriteCmd(unsigned char cmd);
bit isLcdBusy(void);
void waitUntilDone(void);


sbit LCD_E = P1^0;
sbit LCD_RW = P1^1;
sbit LCD_RS = P1^2;

sbit BUSY = P3^7;

/*
* Fetch LCD's busy flag.
* Put P1 into read mode before attempting to read!
*/
bit isLcdBusy(void) {
bit retbit;

retbit = 0;

LCD_RW = 1;
LCD_RS = 0;
LCD_E = 1;
P3 = 0xFF;
retbit = P3^7;
LCD_E = 0;
LCD_RW = 0;
return (retbit);
} // isLcdBusy

void waitUntilDone(void)
{
bit retbit = 1;
P3 = 0xFF;
LCD_RW = 1;
LCD_RS = 0;
while (retbit == 1)
{
LCD_E = 1;
retbit = BUSY;
LCD_E = 0;
} //while retbit == 1

LCD_RW = 0;
} // waitUntilDone()

/*
* Write a character to the display at the current cursor position.
*/
void LcdWriteChar(unsigned char dval)
{
LCD_RW = 0;
LCD_RS = 1;
LCD_E = 1;
P3 = dval;
LCD_E = 0;
waitUntilDone();
} // LcdWriteChar()

/*
* Write a string to the display, starting at the current cursor position.
*/
void LcdWriteString(unsigned char *str)
{
while (*str != '\0')
{
LcdWriteChar(*str);
++str;
}
} // LcdWriteString

/*
* Move the cursor to the specified row and column.
*/
void LcdMoveCursor(unsigned char row, unsigned char col)
{
LcdWriteCmd(LCD_MOVEDISPLAY | (row << 6) | col);
} // LcdMoveCursor

/*
* Write a command to the LCD.
*/
void LcdWriteCmd(unsigned char cmd)
{
LCD_RW = 0;
LCD_RS = 0;
LCD_E = 1;
P3 = cmd;
LCD_E = 0;
waitUntilDone();
} // LcdWriteCmd


/*
* Initialize the LCD.
*/

void LcdInit(void)
{

LCD_RW = 0;
LCD_RS = 0;
LCD_E = 0;

LcdWriteCmd(0x30);
LcdWriteCmd(0x30);
LcdWriteCmd(0x30);
LcdWriteCmd(LCD_SETIFLEN | LCD_SETIFLEN_N | LCD_SETIFLEN_DL);

// should be initialized here.

LcdWriteCmd(LCD_DISPEN); // display off, cursor off, no blink
LcdWriteCmd(LCD_CLEAR);
LcdWriteCmd(LCD_DISPEN | LCD_DISPEN_DISP); // | LCD_DISPEN_CURSOR);
LcdWriteCmd(LCD_MOVEDIR | LCD_MOVEDIR_ID);
} // LcdInit

/*
* Clear the LCD.
*/
void LcdClear(void)
{
LcdWriteCmd(LCD_CLEAR);
} // LcdClear()

/*
* Write the given pattern to the CGRAM at the given address.
*/
void LcdWriteCGRAM(unsigned char addr, unsigned char pattern)
{
// First, move the cursor into the CGRAM area:
LcdWriteCmd(LCD_MOVERAM | addr);
// Then write the pattern to that location:
LcdWriteChar(pattern);
} // LcdWriteCGRAM())



void delay (unsigned int i)
{
while (i--);
}

void main(void)
{
LcdInit();
delay (500);
LcdWriteChar('A');
P2_0 = 0;
P2_1 = 1;


while(1)
{
P2_0 = ~ P2_0;
P2_1 = ~ P2_1;
LcdInit();
LcdWriteChar('A');
delay (50000);
}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top