0% found this document useful (0 votes)
7 views5 pages

E Signal Must Go High

Uploaded by

ibrahim94091521
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)
7 views5 pages

E Signal Must Go High

Uploaded by

ibrahim94091521
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/ 5

//=================================================================

// E signal must go High-to-Low in order for LCD to latch

//=================================================================

void epulse ()

PORTC |= (1 << E); // E High

my_delay(5);

PORTC &= ~( 1 << E); // E Low

my_delay(5);

//=================================================================

// Send Single Byte to LCD Display Function

//=================================================================

void SendChar (char D)

// Send 4 MSb

PORTC &= 0xF0;

PORTC |= (D >> 4);

epulse();

// Send 4 LSb

PORTC &= 0xF0;

PORTC |= (D & 0x0F);

epulse();

}
void ResetLCD ()

PORTC &= ~(1 << RS); // Switch to Command Mode

SendChar(0x03); // RESET: 0x03 should be


transferred thrice

SendChar(0x03);

SendChar(0x03);

SendChar(0x02); // Bus width: 0x03 --> 8-bit


mode, 0x02 4-bit mode

PORTC |= (1 << RS); // Switch to Data mode

//=================================================================

// Initialize LCD

//=================================================================

void InitLCD ()

PORTC &= ~(1 << RS); // Switch to Command mode

SendChar(0x28); // 1 Data length{0:4-bit mode}


Number of lines{1:2 lines} Font type{0:5x8 dots}

SendChar(0x0C); // Don't display cursor, don't blink (1


Display Cursor Blink)

SendChar(0x06); // 1 Increment
automatically(i.e. move cursor to the right) No display shift
PORTC |= (1 << RS); // Switch to Data mode

//=================================================================

// Clear LCD

//=================================================================

void ClearDisplay ()

PORTC &= ~(1 << RS); // Switch to Command mode

SendChar(0x01); // Clear LCD Display

PORTC |= (1 << RS); // Switch to Data mode

//=================================================================

// Display text on desired line (16 x 2)

//=================================================================

void DisplayText (char string[16], char LineNo)

int len,count;

PORTC &= ~( 1 << RS); // Switch to Command mode

if (LineNo == 1)

SendChar(0x80); //Move cursor to Line 1

else

SendChar(0xC0); //Move cursor to Line 2


PORTC |= (1 << RS); // Switch to Data mode

len = strlen(string);

for (count = 0; count < len; count++)

SendChar(string[count]);

//=================================================================

// Test LCD Function

//=================================================================

void TestLCD ()

// Set the direction of Port C (See slide 12)

DDRC = 0x03F;

// Wait for 10ms until the LCD boots

my_delay(10);

// Reset and initialize the LCD

ResetLCD();

InitLCD();

// Display your first name on the 1st line

DisplayText("Your Name", 1);


// Display your ID on the 2nd line

DisplayText("12345", 2);

You might also like