P. 1
JHD162A LCD Code

JHD162A LCD Code

3.67

|Views: 4,177|Likes:
Published by Ankit Daftery

More info:

Published by: Ankit Daftery on Jul 26, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less

07/29/2013

pdf

text

original

/*----------------------------------------------------------------

-------------------- HEADER FILES -------------------------------
-----------------------------------------------------------------*/
#include<avr/io.h>
#include<strin.h>
#include <util/dela!.h>
/*----------------------------------------------------------------
------------- DEFI"I#I$"S -------------------------------------
-----------------------------------------------------------------*/
#de%ine DA#A&DDR DDR' // E"#ER #HE ($R# )HI'H '$"#R$LS
#de%ine DA#A&($R# ($R#' // #HE DA#A (I"S D* #$ D+
#de%ine '$"#R$L&DDR DDRD // E"#ER #HE ($R# )HI'H '$"#R$LS
#de%ine '$"#R$L&($R# ($R#D // #HE '$"#R$L (I"S
#de%ine Ena,le - // 'o""E'#I$" $F E"A.LE #$ (I" $F A.$/E ($R#
#de%ine RS * // 'o""E'#I$" $F ReisterSelect #$ (I" $F A.$/E
($R#
#de%ine R) 0 // 'o""E'#I$" $F Read/1)rite #$ (I" $F A.$/E
($R#
#de%ine '$"#R$L&2AS3 *4*+ // 'HA"5E #HIS /AL6E '$"SIDERI"5 #HE (I"S A.$/E
AS HI5H
/*----------------------------------------------------------------
-------------'$"#R$L .I#S $F L'D --------------------------------
-----------------------------------------------------------------*/
#de%ine Set&Ena,le '$"#R$L&($R# 78&./9Ena,le: //
#HE 2A'R$S HERE ARE
#de%ine 'lear&Ena,le '$"#R$L&($R# ;81&./9Ena,le:
//SELF E4(LA"A#$R<
#de%ine )rite&Lcd '$"#R$L&($R# ;81&./9R): //
#de%ine Read&Lcd '$"#R$L&($R# 78&./9R): //
#de%ine Select&InstructionReister '$"#R$L&($R# ;81&./9RS: //
#de%ine Select&DataReister '$"#R$L&($R# 78&./9RS: //
#de%ine Data&Lcd9,: DA#A&($R#8, //
#de%ine dela!9,: &dela!&=s9,: //
/*----------------------------------------------------------------
-----------------F6"'#I$" DE'LARA#I$"S ---------------------------
-----------------------------------------------------------------*/
void Init&(orts9void:> // Initialise (orts ? "ecessar! %or
selectin in@ut out@ut @ins in the 2'6
void Init&Lcd9void:> // Initialise L'D ? "ecessar! %or startin
and clearin L'D screen
void Lcd&Send9unsined char a:> // For sendin a character to the L'D
void neAline9void:> // For @rintin characters on the neBt line
in the L'D
/*----------------------------------------------------------------
----------------2AI" F6"'#I$"--------------------------------------
-----------------------------------------------------------------*/
void =ain9:
C
int len?len0?len->
char str0DE 8 FAnGit Da%ter!F> // Strin to ,e @rinted in 0st line
char str-DE 8 FH#roniB ; (roudF> // Strin to ,e @rinted in -nd line
Init&(orts9:>
Init&Lcd9:>
len08strlen9str0:>
len-8strlen9str-:>
%or 9len8*>len<len0>lenII: // (rintin the %irst strin
Lcd&Send9str0DlenE:>
neAline9:> // 5o to neA line
%or 9len8*>len<len->lenII: // (rintin the -nd strin
Lcd&Send9str-DlenE:>
J
/*----------------------------------------------------------------
-----------------SE"D A 'HARA'#ER #$ L'D-------------------------
-----------------------------------------------------------------*/
void Lcd&Send9unsined char a:
C
Select&DataReister> // Declares in%or=ation that %olloAs
as data and not instruction
)rite&Lcd> // Declared in%or=ation is to ,e
Aritten
Data&Lcd9a:> // Send the character @assed to the
%unction to L'D to Arite
Set&Ena,le> // Sets ena,le?
dela!9K:> // and then
'lear&Ena,le> // 'lears it?
dela!9K:> // to ,e read! %or neBt character.
J

/*----------------------------------------------------------------
-----------------F6"'#I$"S #$ I"I#IALILE ($R#S--------------------
-----------------------------------------------------------------*/
void Init&(orts9void:
C
DA#A&DDR8*4FF> // Settin data @ort %or
out@ut
'$"#R$L&DDR8'$"#R$L&2AS3> // Settin selected @ins o%
control @ort %or out@ut
'$"#R$L&($R#;819&./9Ena,le:7&./9RS :7&./9R)::> // Settin values to * at
start
J
/*----------------------------------------------------------------
------------F6"'#I$" #$ I"I#IA#E L'D -----------------------------
-----------------------------------------------------------------*/
void Init&Lcd9void:
C
char initD0*E>
int i>
initD*E 8 *B*0> // Initialises the dis@la!
initD0E 8 *BMN> // N - .it $@eration? - Line Dis@la!?K*N
Dot 'haracter Font
initD-E 8 *B*e> // #urns on dis@la! and cursor
initDME 8 *B*O> // Entr! 2ode Set
initDPE 8 *BN*> // Sets DDRA2 address to ,einnin o%
screen
Select&InstructionReister>
)rite&Lcd>
dela!90K:>
%or9i8*>i<K>iII:
C
Data&Lcd9initDiE:>
Set&Ena,le>
dela!9K:>
'lear&Ena,le>
dela!9K:>
J
J
/*----------------------------------------------------------------
------------F6"'#I$" #$ 5$#$ "E4# LI"E I" L'D --------------------
-----------------------------------------------------------------*/
void neAline9void:
C
dela!9K:>
Select&InstructionReister> // Declares in%or=ation to %olloA as
instruction
Data&Lcd9*Bc*:> // 'ode to o to neBt line o% L'D
Set&Ena,le> // -- Ena,le c!cle --
dela!9K:> // 7 7
'lear&Ena,le> // 7 7
dela!9K:> // -- --
J

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->