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

LCD Flex LCD 420 PRGM

This code initializes a 16F877 microcontroller and connects it to a LCD display. It tests various functions for writing to and reading from the LCD like clearing the screen, writing to each line, positioning the cursor, and backspacing. It displays text, characters, and numbers on the LCD and tests that it can read bytes written to different positions on the screen.

Uploaded by

Remigild Peter
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)
116 views2 pages

LCD Flex LCD 420 PRGM

This code initializes a 16F877 microcontroller and connects it to a LCD display. It tests various functions for writing to and reading from the LCD like clearing the screen, writing to each line, positioning the cursor, and backspacing. It displays text, characters, and numbers on the LCD and tests that it can read bytes written to different positions on the screen.

Uploaded by

Remigild Peter
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
You are on page 1/ 2

Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#include <Flex_LCD420.c>
//===================================
void main()
{
int8 i;
int8 b1, b2, b3, b4;
// The lcd_init() function should always be called once,
// near the start of your program.
lcd_init();
// Clear the LCD.
printf(lcd_putc, "\f");
delay_ms(500);
while(1)
{
// Test the clear screen and newline commands.
// Also test that we can write to all 4 lines.
printf(lcd_putc, "\fThis is the 1st line");
printf(lcd_putc, "\nNext is the 2nd line");
printf(lcd_putc, "\nThis is the 3rd line");
printf(lcd_putc, "\nFinally the 4th line");
delay_ms(3000);
// Test some additional characters.
printf(lcd_putc, "\fABCDEFGHIJKLMNOPQRST");
printf(lcd_putc, "\nabcdefghijklmnopqrst");
printf(lcd_putc, "\n12345678901234567890");
printf(lcd_putc, "\n!@#$^&*(){}[]:;<>?/=");
delay_ms(3000);
// Clear the LCD.
printf(lcd_putc, "\f");
delay_ms(500);
// Test that lcd_gotoxy() works. Go to each of
// the four corners and put a number in each one,
// in a clockwise direction, starting with the upper
// left corner.
lcd_gotoxy(4, 2);
printf(lcd_putc, "Put a number in");
lcd_gotoxy(4, 3);
printf(lcd_putc, "each corner.");
lcd_gotoxy(1, 1);
printf(lcd_putc, "1");
lcd_gotoxy(20, 1);
printf(lcd_putc, "2");
lcd_gotoxy(20, 4);
printf(lcd_putc, "3");
lcd_gotoxy(1, 4);

printf(lcd_putc, "4");
delay_ms(3000);
//
//
//
//
//
//
//
//

Read the character that was written in each corner


of the LCD and display it. This tests the lcd_getc()
function.
The following test can only be done if we can read
from the LCD. If the RW pin is not used, then the
LCD is in write-only mode, and we can't do this test.
The #ifdef statement will prevent the code from
being compiled, in that case.

#ifdef USE_RW_PIN
// Test if lcd_getc() can read
// a byte from each corner.
b1 = lcd_getc(1,1);
b2 = lcd_getc(20,1);
b3 = lcd_getc(20,4);
b4 = lcd_getc(1,4);
lcd_gotoxy(1, 1);
printf(lcd_putc, "\fRead these bytes\n");
printf(lcd_putc, "from the 4 corners:\n\n");
printf(lcd_putc, "
%c %c %c %c", b1, b2, b3, b4);
delay_ms(3000);
#endif
// Type some characters and backspace over them.
printf(lcd_putc, "\fType characters and\n");
printf(lcd_putc, "backspace over them.");
delay_ms(2000);
// Go to end of 2nd line.
lcd_gotoxy(20, 2);
// Backspace over 2nd line.
for(i = 0; i < 20; i++)
{
printf(lcd_putc," \b\b");
delay_ms(150);
}
// Go to end of first line.
lcd_gotoxy(20, 1);
// Backspace over first line.
for(i = 0; i < 20; i++)
{
printf(lcd_putc," \b\b");
delay_ms(150);
}
}
}

You might also like