.1. Re ister declarations 4.1.2.2. !iteral declarations 4.1.2.". Procedure declarations / librar# interface 4.1.". Code 4.1.".1. !C$ initialisation 4.1.".2. Bus# fla 4.1.".". Clear displa# 4.1.".4. Cursor %ome 4.1.".&. 'ntr# mode 4.1.".(. $ispla# mode 4.1.".). *et c%aracter enerator R+, address 4.1.".-. *et displa# data R+, address 4.1."... Get address counter contents 4.1.".1/. 0rite c%aracter 4.1.".11. 0rite command 4.1.".12. $ela# loops o 4.2. +d1anced control software 4.2.1. 2ser defined c%aracters ... o 4.". +1ailabilit# o 4.4. 3ar et %ardware 4.4.1 Controller 4.4.2 Interface o 4.&. $e1elopment en1ironment 4.&.1. *oftware 4.&.2. 4ardware
4. PIC example
35C
35C 4.1.1. Requirements features 9 4$44)-/9based :industr#9standard; c%aracter9!C$< all software in t%is c%apter is based on it6s instruction9set. 9 PIC1(C-4 runnin on a 4,4= cr#stal< some code is based on t%is frequenc#. 9 -9bit interface between microcontroller and !C$9module. 35C 4.1.!. Glo"al #eclarations 3o et t%in s wor>in . 35C 4.1.!.1. Re$ister #eclarations
Purpose: - Tells MPASM which ports and registers (files) to use. Code: LCD_DATA LCD_DATA_T$'S LCD_CT$L LCD_T MP D LA, ._D LA, !" !" !" !" !" !" P#$T% T$'S% P#$TA ()(*( ()(*()(*/ & LCD data lines interface & LCD control lines interface & LCD su+routines internal use & "sed in D LA,))) routines & "sed in ._D LA,))) routines
* 2 (
& LCD na+le control line & LCD $ead31rite control line & LCD $egister-Select control line
*ince ,P!IB and ,P!I7? are not #et a1ailable< no declarations are needed. 35C 4.1.&. Co#e 35C 4.1.&.1. %C( initialisation
Purpose: - LCD initialisiation code to +e e)ecuted after power-up (i.e.4 before an5 other su+routines are used). - Should +e 6odified to 5our needs (i.e. displa5 t5pe7 cursor on3off7 etc.) Code: LCD'8'T CL$: M#;L1 CALL M#;L1 CALL M#;L1 CALL CALL M#;L1 CALL M#;L1 CALL $ T"$8 LCD_CT$L ()(2 ._D LA,<(( ()(-? LCDP"TCMD ()((( LCDDM#D LCDCL A$ ()((/ LCDDM#D ()((* LCD M#D & %us5-flag is not 5et 9alid & ALL P#$T output should output Low. & power-up dela5 & -( = (.<6S > 2<6S & %us5 :lag should +e 9alid fro6 here & ?-+it-interface7 *-lines & disp.off7 curs.off7 no-+lin@ & disp.on7 curs.off & auto-inc (shift-cursor)
STAT"S7$P( ()(:: LCD_DATA_T$'S STAT"S7 $P( LCD_CT$L7 LCD_$S LCD_CT$L7 LCD_$1 LCD_CT$L7 LCD_ LCD_DATA7 1 LCD_CT$L7 LCD_
& Select $egister page 2 & Set P#$T% for input & & & & & & Select $egister page ( Set LCD for co66and 6ode Setup to read +us5 flag LCD -line Aigh $ead +us5 flag B DDra6 address LCD -line Low
A8DL1 %T:SS D#T# LCD8#T%"S, %C: %S: M#;L1 M#;1: %C: $ T"$8
()?( STAT"S7 C LCD%"S, LCD_CT$L7 LCD_$1 STAT"S7 $P( ()((( LCD_DATA_T$'S STAT"S7 $P(
& Select $egister page 2 & Set P#$T% for output & Select $egister page (
()((2 LCDP"TCMD
()((* LCDP"TCMD
()((-
()((/ LCDP"TCMD
+e set in 1 off7 2 > cursor +lin@ on (if +2 > 2) 2 > cursor on 2 > displa5 on (displa5 data re6ains in DD-
()(?( LCDP"TCMD
STAT"S7$P( ()(:: LCD_DATA_T$'S STAT"S7 $P( LCD_CT$L7 LCD_$S LCD_CT$L7 LCD_$1 LCD_CT$L7 LCD_ LCD_DATA7 1 LCD_CT$L7 LCD_ ()(E: LCD_CT$L7 LCD_$1 STAT"S7 $P( ()((( LCD_DATA_T$'S STAT"S7 $P(
& Select $egister page 2 & Set P#$T% for input & & & & & & & Select $egister page ( Set LCD for co66and 6ode Setup to read +us5 flag LCD -line Aigh $ead +us5 flag B $AM address LCD -line Low Strip upper +it
& Select $egister page 2 & Set P#$T% for output & Select $egister page (
Character to send is in 1 1ait for LCD to +e read5 Set LCD in read 6ode Set LCD in data 6ode LCD -line Aigh
Co66and to send is in 1 1ait for LCD to +e read5 Set LCD in read 6ode Set LCD in co66and 6ode LCD -line Aigh
a dela5 of F1F = <((6S B2 step2 step* stepB* 2 c5cle wait <((uSec 2 c5cle * c5cles * c5cles
35C
!C$9PIC.@IP :1)<).( b#tes;A an example usin some of t%e abo1e subroutines :all subroutines are included;. *ource is coded for a 4B2/ !C$< ad8ust it to #our needsC *%ows t%e followin screen on a 4B2/ !C$A
---------------------JThis is on line 4 (J JThis is on line 4 2J JThis is on line 4 *J JThis is on line 4 -J ----------------------
35C