LCD (Liquid Crystal Display) is a viewer module that is widely used because it looks interesting. LCDs are the most widely used today is of type M1632 LCD 16 × 2 because the price is quite cheap. M1632 LCD 16 × 2 LCD module to display a 2 × 16 (2 rows x 16 columns) with low power consumption. The module is equipped with a microcontroller specifically designed to control LCD.
For interfacing circuit, LCD 16 × 2 does not require a lot of supporting components. Only takes a variable resistor to provide a voltage contrast on the LCD matrix.
By using AVR CodeVision, programming to show the character or string to the LCD 16 × 2 is very easy because it is supported libraries provided by CodeVision AVR itself. We do not have to understand in depth the characteristics of the LCD, write and initialization commands already provided by the library of CodeVision AVR.
16 × 2 LCD Programming Using CodeVision AVR
Create a new project in CodeVision AVR. Setting the chip AVR ATmega8535 and 11.059200 MHz clock, then setting the LCD as shown below:
After that Generate file, save, and exit.
Consider the following program blocks:
The meaning of the above instruction block is set LCD on PORT C which will then link to lcd.h library in which there are instructions to access the LCD directly.
For initialization simply by following instructions:
Instructions In LCD Library
unsigned char lcd_init (unsigned char lcd_columns);
This instruction is used to initialize the LCD and then followed by the elimination of the LCD display and position the cursor at line 0, column 0. lcd_columns must have a value that corresponds to the type of LCD, eg 16. This function must be called first before calling any functions other LCDs.
example:
unsigned char lcd_read_byte (unsigned char addr);
For interfacing circuit, LCD 16 × 2 does not require a lot of supporting components. Only takes a variable resistor to provide a voltage contrast on the LCD matrix.
By using AVR CodeVision, programming to show the character or string to the LCD 16 × 2 is very easy because it is supported libraries provided by CodeVision AVR itself. We do not have to understand in depth the characteristics of the LCD, write and initialization commands already provided by the library of CodeVision AVR.
16 × 2 LCD Programming Using CodeVision AVR
Create a new project in CodeVision AVR. Setting the chip AVR ATmega8535 and 11.059200 MHz clock, then setting the LCD as shown below:
After that Generate file, save, and exit.
Consider the following program blocks:
... // Alphanumeric LCD Module functions #asm .equ __lcd_port=0x15 ;PORTC #endasm #include <lcd.h> ...
The meaning of the above instruction block is set LCD on PORT C which will then link to lcd.h library in which there are instructions to access the LCD directly.
For initialization simply by following instructions:
...// LCD module initializationlcd_init(16);...
Instructions In LCD Library
unsigned char lcd_init (unsigned char lcd_columns);
This instruction is used to initialize the LCD and then followed by the elimination of the LCD display and position the cursor at line 0, column 0. lcd_columns must have a value that corresponds to the type of LCD, eg 16. This function must be called first before calling any functions other LCDs.
example:
lcd_init(16);
unsigned char lcd_read_byte (unsigned char addr);
This instruction reads a character from the LCD RAM.
example:
lcd_clear void (void);
These instructions will clear the LCD display and place the cursor at column 0 and row 0
example:
lcd_gotoxy void (unsigned char x, unsigned char y);
These instructions are to place the cursor on the column x and row y.
Example:
lcd_putchar void (char c);
These instructions for displaying a character on the current cursor position.
example:
cd_putsf void (char flash * str);
This instruction is used to display the string in the current cursor position.
example:
lcd_puts void (char * str);
This instruction serves to show that the previous string stored in SRAM. Before calling this instruction, before the string has been placed in SRAM. These instructions require stdio.hex library.
example:
example:
Ch=lcd_read_byte(0x10);
lcd_clear void (void);
These instructions will clear the LCD display and place the cursor at column 0 and row 0
example:
lcd_clear();
lcd_gotoxy void (unsigned char x, unsigned char y);
These instructions are to place the cursor on the column x and row y.
Example:
lcd_gotoxy(4,1);//placing the cursor in column 4 and row 1
lcd_putchar void (char c);
These instructions for displaying a character on the current cursor position.
example:
lcd_gotoxy(5,0); lcd_putchar(0x41); //charakter display A //see tabel charakter LCD //Can also be written lcd_putchar ('A');
cd_putsf void (char flash * str);
This instruction is used to display the string in the current cursor position.
example:
lcd_gotoxy(0,1); lcd_putsf(“Hello Eko”); //displays the string Hello Eco
lcd_puts void (char * str);
This instruction serves to show that the previous string stored in SRAM. Before calling this instruction, before the string has been placed in SRAM. These instructions require stdio.hex library.
example:
... #include <mega8535> #include <stdio.h> //add library ... //Declare your global variable here char buf[33];//declaration of a string variable to store data //LCD module initialization lcd_init(16); lcd_gotoxy(0,1); sprint(buf,”Angka %d”, 14);//SRAM to store strings lcd_puts(buf); //display to LCD