0% found this document useful (0 votes)
5 views

LCD Interface

The document provides a C code implementation for driving an LCD using a microcontroller. It includes functions for initializing the LCD, writing commands and data, clearing the display, and positioning the cursor. The main function demonstrates displaying a string and a number on the LCD screen.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

LCD Interface

The document provides a C code implementation for driving an LCD using a microcontroller. It includes functions for initializing the LCD, writing commands and data, clearing the display, and positioning the cursor. The main function demonstrates displaying a string and a number on the LCD screen.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

LCD Interface

// LCD Driving //
#include <REGX51.H>

#define clr_lcd 1 //00000001b


#define cur_home 3 //00000011b
#define char_en 6 //00001100b
#define disp_on 15 //00001111b
#define disp_off 11 //00001011b
#define cur_hide 12 //00001100b
#define cur_show 13 //00001101b
#define uline_off 13 //00001101b
#define blink_off 14 //00001110b

#define cur_right 20 //00010100b


#define cur_left 16 //00010000b

#define rot_right 28 //00011100b


#define rot_left 24 //00011000b

#define mode_lcd 56 //00111000b 8bit 2line 7rows


#define oneline 52 //00110100b 8bit 1line 7rows

#define lcd_pos 128 //10000000b


/*-------------------------------------------------------------------------*/
#ifndef LCD_PINS
#define rs_lcd P2_7
#define rw_lcd P2_6
#define en_lcd P2_5
#define LCD_PINS P0
#define D7_lcd P0_7
#endif
////////////////////////////////////////////////
#define endchar '\0'
#define FirstLine 0
#define SecondLine 0x40
#define ThirdLine 0x14
#define FourthLine 0x54
void lcd_gotoXY(unsigned char ,unsigned char );
code unsigned char vertical[4]={0,0x40,0x14,0x54};

/*=======================================================================*/
void delay_lcd(unsigned int i)
{
en_lcd = 1; //start LCD command
while(i>0)i--;
}

/*=======================================================================*/
void busy_lcd()
{
D7_lcd=1;
rs_lcd=0; // set register select to Command
rw_lcd=1; // Set RW to Read mode
while(D7_lcd!=0) // Wait for LCD to get new command
{
en_lcd=0;
en_lcd=1;
}
}
/*=======================================================================*/
/**** Writing command to LCD ****
/*=======================================================================*/
void wrcom_lcd(unsigned char val_lcd)
{
busy_lcd();
LCD_PINS=val_lcd; // Send
rs_lcd=0; // set register select to Command
rw_lcd=0; // Set RW to Write mode
en_lcd=1; // Enable for Data Input
delay_lcd(1); // Give some Delay
en_lcd=0; // Reset Enable
}
/*=======================================================================*/
/**** Writing data on LCD ****
/*=======================================================================*/
void wrdta_lcd(unsigned char val_lcd)
{
busy_lcd();
LCD_PINS=val_lcd;
rs_lcd=1; // set register select to Data Mode
rw_lcd=0; // Set RW to Write mode
en_lcd=1; // Enable for Data Input
delay_lcd(1); // Give some Delay
en_lcd=0; // Reset Enable
}
/*=======================================================================*/
void clear_lcd()
{
wrcom_lcd(clr_lcd);
}
/*=======================================================================*/
void init_lcd()
{
wrcom_lcd(mode_lcd); //0X38);
wrcom_lcd(disp_on);
wrcom_lcd(cur_hide);
wrcom_lcd(0X01);
wrcom_lcd(0X06);
clear_lcd();
}
/*=======================================================================*/
void lcd_gotoXY(unsigned char X,unsigned char Y)
{
if(Y!=0 && Y<5) // Recheck for Maximum 4 lines
wrcom_lcd(128+X+vertical[Y-1]); // Set command for specific location
else // othervise
wrcom_lcd(128+X+Y); // Set location to initial of LCD
}
/*-------------------------------------------------------------------------*/
void print_lcd(unsigned char *Go) //Display 'x' Terminated String
{
do
{
switch (*Go)
{
case '\f' : wrcom_lcd(clr_lcd); break;
case '\n' : wrcom_lcd(192); break;
default : wrdta_lcd(*Go); break;
}
Go++;
delay_lcd(30);
}
while(*Go!= endchar);
}
/*=======================================================================*/
void print_lcdnum(unsigned char val_lcd)
{
if(val_lcd < 10) // if Number is not in ASCII format
wrdta_lcd(val_lcd + 48); // Make Ascii Number
else // otherwise
wrdta_lcd(val_lcd); // Print as sent nimber
}
/*=======================================================================*/
void main(void)
{
unsigned char a = 15;
init_lcd();

while(1)
{
lcd_gotoXY(0,0);
print_lcd(" Electronics \n");
print_lcd(" 14-60xx Najeeb\n");
lcd_gotoXY(10,3);
print_lcdnum(a/10);
print_lcdnum(a%10);
while(1);
}
}
/*===========================END===========================================
Build target 'LCD'
assembling STARTUP.A51...
compiling LCD Display.c...
linking...

Program Size: data=10.0 xdata=0 code=348

creating hex file from "LCD Display"...


"LCD Display" - 0 Error(s), 0 Warning(s).
/*=======================================================================*/
Rebuild target 'LCD'
compiling LCD Display.c...
linking...
Program Size: data=10.0 xdata=0 code=338
creating hex file from "LCD Display"...
"LCD Display" - 0 Error(s), 0 Warning(s).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy