0% found this document useful (0 votes)
8 views2 pages

LCD Control Code for C8051F340

The document is a C program for interfacing an LCD with the C8051F340 microcontroller. It includes functions for initializing the LCD, writing commands, and displaying characters on the screen. The main function demonstrates the setup and displays the word 'LUCKY' on the LCD.

Uploaded by

chanda.goma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

LCD Control Code for C8051F340

The document is a C program for interfacing an LCD with the C8051F340 microcontroller. It includes functions for initializing the LCD, writing commands, and displaying characters on the screen. The main function demonstrates the setup and displays the word 'LUCKY' on the LCD.

Uploaded by

chanda.goma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include "c8051F340.

h"
void DelayMs(unsigned int Ms);
void Write_Command_Lcd(unsigned char Command);
void Write_Data_Lcd(unsigned char Character);

sbit LCD_RS = P1^5;


sbit LCD_RW = P1^6;
sbit LCD_EN = P1^7;

void main()
{

XBR1 = 0x40; /* Enable Crossbar*/


P2MDOUT = 0xFF;
P1MDOUT = 0xE0;

Write_Command_Lcd(0x01);
DelayMs(50);
Write_Command_Lcd(0x38);
DelayMs(50);
Write_Command_Lcd(0X0C);
DelayMs(50);
Write_Command_Lcd(0X80); //NORMAL INTERFACING WITH ONCE DISPLAY 1ST Line
DelayMs(50);

Write_Data_Lcd('L');
DelayMs(50);
Write_Data_Lcd('U');
DelayMs(50);
Write_Data_Lcd('C');
DelayMs(50);
Write_Data_Lcd('K');
DelayMs(50);
Write_Data_Lcd('Y');
DelayMs(50);
//Write_Data_Lcd('R');
//DelayMs(50);

while (1);
}

void DelayMs(unsigned int Ms)


{
unsigned int n;
unsigned int i;
for (n=0; n < Ms; n++)
{
for (i=0; i < 65; i++);
}
}

void Write_Command_Lcd(unsigned char Command)


{

LCD_RS = 0;
LCD_RW = 0;
P2 = Command;
LCD_EN = 1; // EN pin high->low
DelayMs(15);
LCD_EN = 0;
}

void Write_Data_Lcd(unsigned char Character)


{

LCD_RS = 1;
LCD_RW = 0;
P2 = Character;
LCD_EN = 1; // EN pin high->low
DelayMs(15);
LCD_EN = 0;
}

You might also like