JHD162A LCD Code
JHD162A LCD Code
JHD162A LCD Code
#include<avr/io.h>
#include<string.h>
#include <util/delay.h>
/*----------------------------------------------------------------
------------- DEFINITIONS -------------------------------------
-----------------------------------------------------------------*/
/*----------------------------------------------------------------
-------------CONTROL BITS OF LCD --------------------------------
-----------------------------------------------------------------*/
/*----------------------------------------------------------------
-----------------FUNCTION DECLARATIONS ---------------------------
-----------------------------------------------------------------*/
/*----------------------------------------------------------------
----------------MAIN FUNCTION--------------------------------------
-----------------------------------------------------------------*/
void main()
{
int len,len1,len2;
char str1[] = "Ankit Daftery"; // String to be printed in 1st line
char str2[] = "'Tronix & Proud"; // String to be printed in 2nd line
Init_Ports();
Init_Lcd();
len1=strlen(str1);
len2=strlen(str2);
/*----------------------------------------------------------------
-----------------SEND A CHARACTER TO LCD-------------------------
-----------------------------------------------------------------*/
void Lcd_Send(unsigned char a)
{
Select_DataRegister; // Declares information that follows
as data and not instruction
Write_Lcd; // Declared information is to be
written
Data_Lcd(a); // Send the character passed to the
function to LCD to write
Set_Enable; // Sets enable,
delay(5); // and then
Clear_Enable; // Clears it,
delay(5); // to be ready for next character.
}
/*----------------------------------------------------------------
-----------------FUNCTIONS TO INITIALIZE PORTS--------------------
-----------------------------------------------------------------*/
void Init_Ports(void)
{
DATA_DDR=0XFF; // Setting data port for
output
CONTROL_DDR=CONTROL_MASK; // Setting selected pins of
control port for output
CONTROL_PORT&=~(_BV(Enable)|_BV(RS )|_BV(RW)); // Setting values to 0 at
start
}
/*----------------------------------------------------------------
------------FUNCTION TO INITIATE LCD -----------------------------
-----------------------------------------------------------------*/
void Init_Lcd(void)
{
char init[10];
int i;
init[0] = 0x01; // Initialises the display
init[1] = 0x38; // 8 - Bit Operation, 2 Line Display,5*8
Dot Character Font
init[2] = 0x0e; // Turns on display and cursor
init[3] = 0x06; // Entry Mode Set
init[4] = 0x80; // Sets DDRAM address to beginning of
screen
Select_InstructionRegister;
Write_Lcd;
delay(15);
for(i=0;i<5;i++)
{
Data_Lcd(init[i]);
Set_Enable;
delay(5);
Clear_Enable;
delay(5);
}
}
/*----------------------------------------------------------------
------------FUNCTION TO GOTO NEXT LINE IN LCD --------------------
-----------------------------------------------------------------*/
void newline(void)
{
delay(5);
Select_InstructionRegister; // Declares information to follow as
instruction
Data_Lcd(0xc0); // Code to go to next line of LCD
Set_Enable; // -- Enable cycle --
delay(5); // | |
Clear_Enable; // | |
delay(5); // -- --
}