Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

LCD interfacing with a PIC - TUTORIAL -

Status
Not open for further replies.

TekUT

Full Member level 6
Joined
Jun 17, 2008
Messages
323
Helped
39
Reputation
78
Reaction score
15
Trophy points
1,298
Location
Italy
Activity points
3,557
pic lcd tutorial

Hi all,
I've see that many people have trouble about LCD interfacing, I've just finish to develop a library to do all the things needed to drive a HD44780 LCD controller based display with a PIC. My application is able to work with 4 bit interface (in order to save 4 pin of the microcontroller) and also isn't restricted to some PIC, just change the pin assignement on the header file and all is done.

This design was originally compiled with Hi-Tech for a PIC16F870 (20 MHz clock) but there is no restriction about what type of PIC you can use, simply change the pin assignement as I'll show later.

There are only three file:

- lcddisp.c (main file - just to show how to use the library)
- lcd-lib.c (the code to drive the LCD)
- lcd-lib.h (pin assignement)

Starting with the main file we've at first the inclusion of the header file regarding the microcontroller pin assignement:

Code:
#include <pic.h>
#include <stdio.h>

#include "lcd-lib.h"		// Pin definition for the LCD

Open the lcd-lib.h file, here below you can find the pin declaration for the Hi-Tech compiler, if you use another type of compiler simply change the pin syntax, just only a things, don't touch the pin name (RS, RW, EN, DB4, DB5, DB6, DB7) because these will be referred from the LCD routine inside the lcd-lib.c file:

Code:
// -------------------------------------------
// LCD type
// -------------------------------------------
#define MAXPOSX	     16
#define MAXPOSY	      2

// -------------------------------------------
// Definition of the LCD uP pin (Hi-Tech compiler)
// -------------------------------------------
static volatile bit RS @  (unsigned)&PORTA*8+0;
static volatile bit RW @  (unsigned)&PORTA*8+1;
static volatile bit EN @  (unsigned)&PORTA*8+2;    
static volatile bit DB4 @ (unsigned)&PORTB*8+1;
static volatile bit DB5 @ (unsigned)&PORTB*8+2;
static volatile bit DB6 @ (unsigned)&PORTB*8+3;
static volatile bit DB7 @ (unsigned)&PORTB*8+4;

Now you've available these functions:

Code:
void GenDelay(int);// Generic delay 
void LongDelay(long);	// Long generic delay
void LCDInit(void); // LCD init routine
void ClearDisplay(void);// Clear the LCD display
void CursorAtHome(void);// Set cursor to home position
void Printxy(unsigned char, unsigned char, unsigned char); // Print a char

If you are using a different compiler or other frequency clock simply change the delay routine to meet your need, just take care about the timing that I've written as remark into the source code.

About the display there is no restriction, the only things is about the controller it must be a HD44780 or compatible.
I've also attached a pic of the connection (the 2kOhm trimmer on the right of the connector is used to set the LCD contrast), anyway here the display connector signal name:

Pin 1: Vss (0 V)
Pin 2: Vcc (+5V)
Pin 3: Vee (contrast, just use a simple 2kOhm trimmer from Vcc to Vss, cursor to Vee)
Pin 4: RS
Pin 5: R/W
Pin 6: E
Pin 7: DB0 (not used for 4-bit interface)
Pin 8: DB1 (not used for 4-bit interface)
Pin 9: DB2 (not used for 4-bit interface)
Pin 10: DB3 (not used for 4-bit interface)
Pin 11: DB4 (used for 4-bit interface)
Pin 12: DB5 (used for 4-bit interface)
Pin 13: DB6 (used for 4-bit interface)
Pin 14: DB7 (used for 4-bit interface)
Pin 15: Led anode (+)
Pin 16: Led katode (-)

I've not used the led for back illumination, if you like to use it connect the Pin 15 trough a 680Ohm resistor to the +5V and the Pin 16 to the 0V.
Hope this can help a bit.

Bye
Pow
 

temp lcd tutorial

Could I have the assmebly source code for this????

Best regards
 
I've coded it in C but I think is very very easy translate the routine inside the lcd-lib.c file in assembly. Let me know if you need help, at now I've no more time but into the next days I can try to make the translate to asm.
To help you in a fast way I've attached the asm listing, this is the compilation result then you can make the change in easy way.

Code:
---  C:\Temp\PIC_LCD\lcd-lib.c  ------------------------------------------------------------------
1:                 void GenDelay(int);														// Funzione per ritrado generico (< 1 secondo)
2:                 void LongDelay(long);													// Funzione per ritrado generico (> 1 secondo)
3:                 void LCDInit(void);
4:                 void ClearDisplay(void);												// Cancella il contenuto dedl display
5:                 void CursorAtHome(void);												// Posiziona il cursore nella posizione di Home
6:                 void Printxy(unsigned char, unsigned char, unsigned char);				// Visualizza un carattere sul display
7:                 
8:                 // -----------------------------------------------------------------------
9:                 // Purpose          : Generic delay (us range)
10:                // Author           : Powermos
11:                // Date creazione   : 25/09/2008
12:                // -----------------------------------------------------------------------
13:                
14:                void GenDelay(int DelayPar)
15:                {
16:                 Loop1:
17:                 asm("clrwdt");
   4D4    0064     CLRWDT
18:                 if (DelayPar >= 0)
   4D5    1283     BCF 0x3, 0x5
   4D6    1303     BCF 0x3, 0x6
   4D7    1BA9     BTFSC 0x29, 0x7
19:                   {
20:                    DelayPar--;
   4D9    08A8     MOVF 0x28, F
   4DA    1903     BTFSC 0x3, 0x2
   4DB    03A9     DECF 0x29, F
   4DC    03A8     DECF 0x28, F
21:                    goto Loop1;
   4DD    2CD4     GOTO 0x4d4
22:                   }
23:                 return;
24:                }
   4D8    0008     RETURN
25:                
26:                // -----------------------------------------------------------------------
27:                // Purpose          : Generic delay (ms range)
28:                // Author           : Powermos
29:                // Date creazione   : 25/09/2008
30:                // -----------------------------------------------------------------------
31:                
32:                void LongDelay(long DelayExt)
33:                {
   50F    3020     MOVLW 0x20
34:                 long DelayInt = 800;
   510    0183     CLRF 0x3
   511    00A7     MOVWF 0x27
   512    3003     MOVLW 0x3
   513    00A8     MOVWF 0x28
   514    3000     MOVLW 0
   515    01A9     CLRF 0x29
   516    01AA     CLRF 0x2a
35:                
36:                 LoopExt:
37:                 if (DelayExt >=0)
   517    2D45     GOTO 0x545
   545    1BA6     BTFSC 0x26, 0x7
   547    2D2A     GOTO 0x52a
38:                   {
39:                    LoopInt:
40:                    asm("clrwdt");
   52A    0064     CLRWDT
41:                    if (DelayInt >= 0)
   52B    1FAA     BTFSS 0x2a, 0x7
   52C    2D18     GOTO 0x518
42:                     {
43:                      DelayInt--;
   518    3001     MOVLW 0x1
   519    00F0     MOVWF 0x70
   51A    01F1     CLRF 0x71
   51B    01F2     CLRF 0x72
   51C    01F3     CLRF 0x73
   51D    02A7     SUBWF 0x27, F
   51E    0871     MOVF 0x71, W
   51F    1C03     BTFSS 0x3, 0
   520    0F71     INCFSZ 0x71, W
   521    02A8     SUBWF 0x28, F
   522    0872     MOVF 0x72, W
   523    1C03     BTFSS 0x3, 0
   524    0F72     INCFSZ 0x72, W
   525    02A9     SUBWF 0x29, F
   526    0873     MOVF 0x73, W
   527    1C03     BTFSS 0x3, 0
   528    0A73     INCF 0x73, W
   529    02AA     SUBWF 0x2a, F
44:                      goto LoopInt;
45:                     }
46:                    DelayInt = 800;
   52D    3020     MOVLW 0x20
   52E    00A7     MOVWF 0x27
   52F    3003     MOVLW 0x3
   530    00A8     MOVWF 0x28
   531    01A9     CLRF 0x29
   532    01AA     CLRF 0x2a
47:                    DelayExt--;
   533    3001     MOVLW 0x1
   534    00F0     MOVWF 0x70
   535    01F1     CLRF 0x71
   536    01F2     CLRF 0x72
   537    01F3     CLRF 0x73
   538    02A3     SUBWF 0x23, F
   539    0871     MOVF 0x71, W
   53A    1C03     BTFSS 0x3, 0
   53B    0F71     INCFSZ 0x71, W
   53C    02A4     SUBWF 0x24, F
   53D    0872     MOVF 0x72, W
   53E    1C03     BTFSS 0x3, 0
   53F    0F72     INCFSZ 0x72, W
   540    02A5     SUBWF 0x25, F
   541    0873     MOVF 0x73, W
   542    1C03     BTFSS 0x3, 0
   543    0A73     INCF 0x73, W
   544    02A6     SUBWF 0x26, F
48:                    goto LoopExt;
49:                   }
50:                 return;
51:                }
   546    0008     RETURN
52:                
53:                // -----------------------------------------------------------------------
54:                // Purpose              : LCD initialization with 4 bit interface
55:                // Author               : Powermos
56:                // Date creazione       : 25/09/2008
57:                // -----------------------------------------------------------------------
58:                void LCDInit(void)
59:                {
   639    0183     CLRF 0x3
60:                  char i;
61:                
62:                  // Code 0x03
63:                  RS    = 0;
   63A    1005     BCF 0x5, 0
64:                  RW    = 0;
   63B    1085     BCF 0x5, 0x1
65:                  DB4   = 1;
   63C    1486     BSF 0x6, 0x1
66:                  DB5   = 1;
   63D    1506     BSF 0x6, 0x2
67:                  DB6	= 0;
   63E    1186     BCF 0x6, 0x3
68:                  DB7   = 0;
   63F    1206     BCF 0x6, 0x4
69:                  EN    = 1;
   640    1505     BSF 0x5, 0x2
70:                  asm("nop");
   641    0000     NOP
71:                  asm("nop");
   642    0000     NOP
72:                  asm("nop");
   643    0000     NOP
73:                  asm("nop");
   644    0000     NOP
74:                  asm("nop");
   645    0000     NOP
75:                  EN    = 0;
   646    1105     BCF 0x5, 0x2
76:                  for (i=0; i<8; i++)
   647    01A3     CLRF 0x23
   64C    0AA3     INCF 0x23, F
   64D    3008     MOVLW 0x8
   64E    0223     SUBWF 0x23, W
   64F    1C03     BTFSS 0x3, 0
   650    2E48     GOTO 0x648
77:                	{
78:                		GenDelay(255);	// Time delay 5 ms minimum
   648    30FF     MOVLW 0xff
   649    00A8     MOVWF 0x28
   64A    01A9     CLRF 0x29
   64B    24D4     CALL 0x4d4
79:                	}
80:                  
81:                  // Code 0x03
82:                  RS    = 0;
   651    1005     BCF 0x5, 0
83:                  RW    = 0;
   652    1085     BCF 0x5, 0x1
84:                  DB4   = 1;
   653    1486     BSF 0x6, 0x1
85:                  DB5   = 1;
   654    1506     BSF 0x6, 0x2
86:                  DB6	= 0;
   655    1186     BCF 0x6, 0x3
87:                  DB7   = 0;
   656    1206     BCF 0x6, 0x4
88:                  EN    = 1;
   657    1505     BSF 0x5, 0x2
89:                  asm("nop");
   658    0000     NOP
90:                  asm("nop");
   659    0000     NOP
91:                  asm("nop");
   65A    0000     NOP
92:                  asm("nop");
   65B    0000     NOP
93:                  asm("nop");
   65C    0000     NOP
94:                  EN    = 0;
   65D    1105     BCF 0x5, 0x2
95:                  GenDelay(60); // Time dalay 160 us minimum
   65E    303C     MOVLW 0x3c
   65F    00A8     MOVWF 0x28
   660    01A9     CLRF 0x29
   661    24D4     CALL 0x4d4
96:                
97:                  // Code 0x03
98:                  RS    = 0;
   662    1005     BCF 0x5, 0
99:                  RW    = 0;
   663    1085     BCF 0x5, 0x1
100:                 DB4   = 1;
   664    1486     BSF 0x6, 0x1
101:                 DB5   = 1;
   665    1506     BSF 0x6, 0x2
102:                 DB6	= 0;
   666    1186     BCF 0x6, 0x3
103:                 DB7   = 0;
   667    1206     BCF 0x6, 0x4
104:                 EN    = 1;
   668    1505     BSF 0x5, 0x2
105:                 asm("nop");
   669    0000     NOP
106:                 asm("nop");
   66A    0000     NOP
107:                 asm("nop");
   66B    0000     NOP
108:                 asm("nop");
   66C    0000     NOP
109:                 asm("nop");
   66D    0000     NOP
110:                 EN    = 0;
   66E    1105     BCF 0x5, 0x2
111:                 GenDelay(60); // Time dalay 160 us minimum
   66F    303C     MOVLW 0x3c
   670    00A8     MOVWF 0x28
   671    01A9     CLRF 0x29
   672    24D4     CALL 0x4d4
112:               
113:                 // Function Set (Code 0x02)
114:                 RS    = 0;
   673    1005     BCF 0x5, 0
115:                 RW    = 0;
   674    1085     BCF 0x5, 0x1
116:                 DB4   = 0;
   675    1086     BCF 0x6, 0x1
117:                 DB5   = 1;
   676    1506     BSF 0x6, 0x2
118:                 DB6	= 0;
   677    1186     BCF 0x6, 0x3
119:                 DB7   = 0;
   678    1206     BCF 0x6, 0x4
120:                 EN    = 1;
   679    1505     BSF 0x5, 0x2
121:                 asm("nop");
   67A    0000     NOP
122:                 asm("nop");
   67B    0000     NOP
123:                 asm("nop");
   67C    0000     NOP
124:                 asm("nop");
   67D    0000     NOP
125:                 asm("nop");
   67E    0000     NOP
126:                 EN    = 0;
   67F    1105     BCF 0x5, 0x2
127:                 GenDelay(20); // Wait for 59 us (minimum requested of 37 us)
   680    3014     MOVLW 0x14
   681    00A8     MOVWF 0x28
   682    01A9     CLRF 0x29
   683    24D4     CALL 0x4d4
128:               
129:                 // Function Set (D,N,F)
130:                 RS    = 0;
   684    1005     BCF 0x5, 0
131:                 RW    = 0;
   685    1085     BCF 0x5, 0x1
132:                 DB4   = 0; // D=0 set the 4-bit interface
   686    1086     BCF 0x6, 0x1
133:                 DB5   = 1;
   687    1506     BSF 0x6, 0x2
134:                 DB6	= 0;
   688    1186     BCF 0x6, 0x3
135:                 DB7   = 0;
   689    1206     BCF 0x6, 0x4
136:                 EN    = 1;
   68A    1505     BSF 0x5, 0x2
137:                 asm("nop");
   68B    0000     NOP
138:                 asm("nop");
   68C    0000     NOP
139:                 asm("nop");
   68D    0000     NOP
140:                 asm("nop");
   68E    0000     NOP
141:                 asm("nop");
   68F    0000     NOP
142:                 EN    = 0;
   690    1105     BCF 0x5, 0x2
143:                 DB4   = 0;
   691    1086     BCF 0x6, 0x1
144:                 DB5   = 0;
   692    1106     BCF 0x6, 0x2
145:                 DB6	= 0; // F=0 font
   693    1186     BCF 0x6, 0x3
146:                 DB7   = 1; // N=1 display 2 linee
   694    1606     BSF 0x6, 0x4
147:                 EN    = 1;
   695    1505     BSF 0x5, 0x2
148:                 asm("nop");
   696    0000     NOP
149:                 asm("nop");
   697    0000     NOP
150:                 asm("nop");
   698    0000     NOP
151:                 asm("nop");
   699    0000     NOP
152:                 asm("nop");
   69A    0000     NOP
153:                 EN    = 0;
   69B    1105     BCF 0x5, 0x2
154:                 GenDelay(20); // Wait for 59 us (minimum requested of 37 us)
   69C    3014     MOVLW 0x14
   69D    00A8     MOVWF 0x28
   69E    01A9     CLRF 0x29
   69F    24D4     CALL 0x4d4
155:               
156:                 // Display OFF
157:                 RS    = 0;
   6A0    1005     BCF 0x5, 0
158:                 RW    = 0;
   6A1    1085     BCF 0x5, 0x1
159:                 DB4   = 0; 
   6A2    1086     BCF 0x6, 0x1
160:                 DB5   = 0;
   6A3    1106     BCF 0x6, 0x2
161:                 DB6	= 0;
   6A4    1186     BCF 0x6, 0x3
162:                 DB7   = 0;
   6A5    1206     BCF 0x6, 0x4
163:                 EN    = 1;
   6A6    1505     BSF 0x5, 0x2
164:                 asm("nop");
   6A7    0000     NOP
165:                 asm("nop");
   6A8    0000     NOP
166:                 asm("nop");
   6A9    0000     NOP
167:                 asm("nop");
   6AA    0000     NOP
168:                 asm("nop");
   6AB    0000     NOP
169:                 EN    = 0;
   6AC    1105     BCF 0x5, 0x2
170:                 DB4   = 0;
   6AD    1086     BCF 0x6, 0x1
171:                 DB5   = 0;
   6AE    1106     BCF 0x6, 0x2
172:                 DB6	= 0; 
   6AF    1186     BCF 0x6, 0x3
173:                 DB7   = 1; 
   6B0    1606     BSF 0x6, 0x4
174:                 EN    = 1;
   6B1    1505     BSF 0x5, 0x2
175:                 asm("nop");
   6B2    0000     NOP
176:                 asm("nop");
   6B3    0000     NOP
177:                 asm("nop");
   6B4    0000     NOP
178:                 asm("nop");
   6B5    0000     NOP
179:                 asm("nop");
   6B6    0000     NOP
180:                 EN    = 0;
   6B7    1105     BCF 0x5, 0x2
181:                 GenDelay(20); // Wait for 59 us (minimum requested of 37 us)
   6B8    3014     MOVLW 0x14
   6B9    00A8     MOVWF 0x28
   6BA    01A9     CLRF 0x29
   6BB    24D4     CALL 0x4d4
182:               
183:                 // Display ON
184:                 RS    = 0;
   6BC    1005     BCF 0x5, 0
185:                 RW    = 0;
   6BD    1085     BCF 0x5, 0x1
186:                 DB4   = 0; 
   6BE    1086     BCF 0x6, 0x1
187:                 DB5   = 0;
   6BF    1106     BCF 0x6, 0x2
188:                 DB6	= 0;
   6C0    1186     BCF 0x6, 0x3
189:                 DB7   = 0;
   6C1    1206     BCF 0x6, 0x4
190:                 EN    = 1;
   6C2    1505     BSF 0x5, 0x2
191:                 asm("nop");
   6C3    0000     NOP
192:                 asm("nop");
   6C4    0000     NOP
193:                 asm("nop");
   6C5    0000     NOP
194:                 asm("nop");
   6C6    0000     NOP
195:                 asm("nop");
   6C7    0000     NOP
196:                 EN    = 0;
   6C8    1105     BCF 0x5, 0x2
197:                 DB4   = 0; // B (Cursor blinking ON= 1, OFF=0)
   6C9    1086     BCF 0x6, 0x1
198:                 DB5   = 0; // C (Cursor ON=1, OFF=0)
   6CA    1106     BCF 0x6, 0x2
199:                 DB6	= 1; // D (Display ON=1, OFF=0)
   6CB    1586     BSF 0x6, 0x3
200:                 DB7   = 1; 
   6CC    1606     BSF 0x6, 0x4
201:                 EN    = 1;
   6CD    1505     BSF 0x5, 0x2
202:                 asm("nop");
   6CE    0000     NOP
203:                 asm("nop");
   6CF    0000     NOP
204:                 asm("nop");
   6D0    0000     NOP
205:                 asm("nop");
   6D1    0000     NOP
206:                 asm("nop");
   6D2    0000     NOP
207:                 EN    = 0;
   6D3    1105     BCF 0x5, 0x2
208:                 GenDelay(20); // Wait for 59 us (minimum requested of 37 us)
   6D4    3014     MOVLW 0x14
   6D5    00A8     MOVWF 0x28
   6D6    01A9     CLRF 0x29
   6D7    24D4     CALL 0x4d4
209:               
210:                 // Entry mode set
211:                 RS    = 0;
   6D8    1005     BCF 0x5, 0
212:                 RW    = 0;
   6D9    1085     BCF 0x5, 0x1
213:                 DB4   = 0; 
   6DA    1086     BCF 0x6, 0x1
214:                 DB5   = 0;
   6DB    1106     BCF 0x6, 0x2
215:                 DB6	= 0;
   6DC    1186     BCF 0x6, 0x3
216:                 DB7   = 0;
   6DD    1206     BCF 0x6, 0x4
217:                 EN    = 1;
   6DE    1505     BSF 0x5, 0x2
218:                 asm("nop");
   6DF    0000     NOP
219:                 asm("nop");
   6E0    0000     NOP
220:                 asm("nop");
   6E1    0000     NOP
221:                 asm("nop");
   6E2    0000     NOP
222:                 asm("nop");
   6E3    0000     NOP
223:                 EN    = 0;
   6E4    1105     BCF 0x5, 0x2
224:                 DB4   = 0; // S=0
   6E5    1086     BCF 0x6, 0x1
225:                 DB5   = 1; // ID=1
   6E6    1506     BSF 0x6, 0x2
226:                 DB6	= 1; 
   6E7    1586     BSF 0x6, 0x3
227:                 DB7   = 0; 
   6E8    1206     BCF 0x6, 0x4
228:                 EN    = 1;
   6E9    1505     BSF 0x5, 0x2
229:                 asm("nop");
   6EA    0000     NOP
230:                 asm("nop");
   6EB    0000     NOP
231:                 asm("nop");
   6EC    0000     NOP
232:                 asm("nop");
   6ED    0000     NOP
233:                 asm("nop");
   6EE    0000     NOP
234:                 EN    = 0;
   6EF    1105     BCF 0x5, 0x2
235:                 GenDelay(20); // Wait for 59 us (minimum requested of 37 us)
   6F0    3014     MOVLW 0x14
   6F1    00A8     MOVWF 0x28
   6F2    01A9     CLRF 0x29
   6F3    24D4     CALL 0x4d4
236:               
237:                 ClearDisplay();
   6F4    2CEB     GOTO 0x4eb
238:                 
239:                 return;
240:               }
241:               
242:               // -----------------------------------------------------------------------
243:               // Purpose              : Cancella il contenuto dedl display
244:               // Author               : Powermos
245:               // Date creazione       : 25/09/2008
246:               // -----------------------------------------------------------------------
247:               void ClearDisplay(void)
248:               {
   4EB    0183     CLRF 0x3
249:                 char i;
250:               
251:                 // Clear Display
252:                 RS    = 0;
   4EC    1005     BCF 0x5, 0
253:                 RW    = 0;
   4ED    1085     BCF 0x5, 0x1
254:                 DB4   = 0; 
   4EE    1086     BCF 0x6, 0x1
255:                 DB5   = 0;
   4EF    1106     BCF 0x6, 0x2
256:                 DB6	= 0;
   4F0    1186     BCF 0x6, 0x3
257:                 DB7   = 0;
   4F1    1206     BCF 0x6, 0x4
258:                 EN    = 1;
   4F2    1505     BSF 0x5, 0x2
259:                 asm("nop");
   4F3    0000     NOP
260:                 asm("nop");
   4F4    0000     NOP
261:                 asm("nop");
   4F5    0000     NOP
262:                 asm("nop");
   4F6    0000     NOP
263:                 asm("nop");
   4F7    0000     NOP
264:                 EN    = 0;
   4F8    1105     BCF 0x5, 0x2
265:                 DB4   = 1;
   4F9    1486     BSF 0x6, 0x1
266:                 DB5   = 0;
   4FA    1106     BCF 0x6, 0x2
267:                 DB6	= 0; 
   4FB    1186     BCF 0x6, 0x3
268:                 DB7   = 0; 
   4FC    1206     BCF 0x6, 0x4
269:                 EN    = 1;
   4FD    1505     BSF 0x5, 0x2
270:                 asm("nop");
   4FE    0000     NOP
271:                 asm("nop");
   4FF    0000     NOP
272:                 asm("nop");
   500    0000     NOP
273:                 asm("nop");
   501    0000     NOP
274:                 asm("nop");
   502    0000     NOP
275:                 EN    = 0;
   503    1105     BCF 0x5, 0x2
276:                 for (i=0; i<8; i++)
   504    01A4     CLRF 0x24
   509    0AA4     INCF 0x24, F
   50A    3008     MOVLW 0x8
   50B    0224     SUBWF 0x24, W
   50C    1803     BTFSC 0x3, 0
   50D    0008     RETURN
   50E    2D05     GOTO 0x505
277:               	{
278:               		GenDelay(255);	// Wait for 5 ms min
   505    30FF     MOVLW 0xff
279:               	}
280:               
281:                return;
282:               }
283:               
284:               // -----------------------------------------------------------------------
285:               // Purpose              : set the cursor position to home
286:               // Author               : Powermos
287:               // Date creazione       : 25/09/2008
288:               // -----------------------------------------------------------------------
289:               void CursorAtHome(void)
290:               {
   548    0183     CLRF 0x3
291:                unsigned char Position = 0;
   549    01A3     CLRF 0x23
292:               
293:                Position = Position | 0b10000000;	// Set DB7 to 1
   54A    17A3     BSF 0x23, 0x7
294:                RS    = 0;
   54B    1005     BCF 0x5, 0
295:                RW    = 0;
   54C    1085     BCF 0x5, 0x1
296:                DB4   = ((Position & 0b00010000) == 16) ? 1 : 0;
   54D    1E23     BTFSS 0x23, 0x4
   54E    2D51     GOTO 0x551
   54F    1486     BSF 0x6, 0x1
   550    2D52     GOTO 0x552
   551    1086     BCF 0x6, 0x1
297:                DB5   = ((Position & 0b00100000) == 32) ? 1 : 0; 
   552    1283     BCF 0x3, 0x5
   553    1303     BCF 0x3, 0x6
   554    1EA3     BTFSS 0x23, 0x5
   555    2D58     GOTO 0x558
   556    1506     BSF 0x6, 0x2
   557    2D59     GOTO 0x559
   558    1106     BCF 0x6, 0x2
298:                DB6   = ((Position & 0b01000000) == 64) ? 1 : 0; 
   559    1F23     BTFSS 0x23, 0x6
   55A    2D5D     GOTO 0x55d
   55B    1586     BSF 0x6, 0x3
   55C    2D5E     GOTO 0x55e
   55D    1186     BCF 0x6, 0x3
299:                DB7   = ((Position & 0b10000000) == 128) ? 1 : 0; 
   55E    1FA3     BTFSS 0x23, 0x7
   55F    2D62     GOTO 0x562
   560    1606     BSF 0x6, 0x4
   561    2D63     GOTO 0x563
   562    1206     BCF 0x6, 0x4
300:                EN    = 1;
   563    1505     BSF 0x5, 0x2
301:                asm("nop");
   564    0000     NOP
302:                asm("nop");
   565    0000     NOP
303:                asm("nop");
   566    0000     NOP
304:                asm("nop");
   567    0000     NOP
305:                asm("nop");
   568    0000     NOP
306:                EN    = 0;
   569    1105     BCF 0x5, 0x2
307:                DB4   = ((Position & 0b00000001) == 1) ? 1 : 0;
   56A    1C23     BTFSS 0x23, 0
   56B    2D6E     GOTO 0x56e
   56C    1486     BSF 0x6, 0x1
   56D    2D6F     GOTO 0x56f
   56E    1086     BCF 0x6, 0x1
308:                DB5   = ((Position & 0b00000010) == 2) ? 1 : 0; 
   56F    1CA3     BTFSS 0x23, 0x1
   570    2D73     GOTO 0x573
   571    1506     BSF 0x6, 0x2
   572    2D74     GOTO 0x574
   573    1106     BCF 0x6, 0x2
309:                DB6   = ((Position & 0b00000100) == 4) ? 1 : 0; 
   574    1D23     BTFSS 0x23, 0x2
   575    2D78     GOTO 0x578
   576    1586     BSF 0x6, 0x3
   577    2D79     GOTO 0x579
   578    1186     BCF 0x6, 0x3
310:                DB7   = ((Position & 0b00001000) == 8) ? 1 : 0; 
   579    1DA3     BTFSS 0x23, 0x3
   57A    2D7D     GOTO 0x57d
   57B    1606     BSF 0x6, 0x4
   57C    2D7E     GOTO 0x57e
   57D    1206     BCF 0x6, 0x4
311:                EN    = 1;
   57E    1505     BSF 0x5, 0x2
312:                asm("nop");
   57F    0000     NOP
313:                asm("nop");
   580    0000     NOP
314:                asm("nop");
   581    0000     NOP
315:                asm("nop");
   582    0000     NOP
316:                asm("nop");
   583    0000     NOP
317:                EN    = 0;
   584    1105     BCF 0x5, 0x2
318:                GenDelay(20); // Wait approx 59 us (minimum requested is 37 us)
   585    3014     MOVLW 0x14
319:               
320:                return;
321:               }
322:               
323:               // -----------------------------------------------------------------------
324:               // Purpose              : show a char on the LCD
325:               // Input				:  X position, Y position, char code to show
326:               // Output				: -
327:               // Author               : Powermos
328:               // Date creazione       : 25/09/2008
329:               // -----------------------------------------------------------------------
330:               
331:               void Printxy(unsigned char Xpos, unsigned char Ypos, unsigned char CharToDisp)
332:               {
   589    0183     CLRF 0x3
   58A    00A5     MOVWF 0x25
333:                int Position = 0;
   58B    01A6     CLRF 0x26
   58C    01A7     CLRF 0x27
334:               unsigned char CharLo;
335:               unsigned char CharHi;
336:               
337:                // Check if X and Y are valid for the current display
338:                if (Xpos > MAXPOSX)
   58D    3011     MOVLW 0x11
   58E    0225     SUBWF 0x25, W
   58F    1C03     BTFSS 0x3, 0
   590    2D93     GOTO 0x593
339:               	Xpos = MAXPOSX;
   591    3010     MOVLW 0x10
   592    00A5     MOVWF 0x25
340:                if (Ypos > MAXPOSY)
   593    3003     MOVLW 0x3
   594    0223     SUBWF 0x23, W
   595    1C03     BTFSS 0x3, 0
   596    2DA9     GOTO 0x5a9
341:               	Ypos = MAXPOSY;
   597    3002     MOVLW 0x2
   598    00A3     MOVWF 0x23
342:               
343:                // Calculate the DDRAM address
344:                switch (Ypos)
   599    2DA9     GOTO 0x5a9
   5A9    0823     MOVF 0x23, W
   5AA    3A01     XORLW 0x1
   5AB    1903     BTFSC 0x3, 0x2
   5AC    2DB6     GOTO 0x5b6
   5AD    3A03     XORLW 0x3
   5AE    1903     BTFSC 0x3, 0x2
   5AF    2D9A     GOTO 0x59a
   5B0    3A01     XORLW 0x1
   5B1    1903     BTFSC 0x3, 0x2
   5B2    2D9C     GOTO 0x59c
   5B3    3A07     XORLW 0x7
   5B4    1903     BTFSC 0x3, 0x2
   5B5    2D9E     GOTO 0x59e
345:                 {
346:                   case 1 : Position =  0 + Xpos;
347:               	     break;
348:                   case 2 : Position = 64 + Xpos;
   59A    3040     MOVLW 0x40
   59B    2D9F     GOTO 0x59f
349:               	     break;
350:                   case 3 : Position = 20 + Xpos;
   59C    3014     MOVLW 0x14
   59D    2D9F     GOTO 0x59f
351:               	     break;
352:                   case 4 : Position = 84 + Xpos;
   59E    3054     MOVLW 0x54
   59F    00F0     MOVWF 0x70
   5A0    01F1     CLRF 0x71
   5A1    0825     MOVF 0x25, W
   5A2    0770     ADDWF 0x70, W
   5A3    00A6     MOVWF 0x26
   5A4    0871     MOVF 0x71, W
   5A5    1803     BTFSC 0x3, 0
   5A6    0A71     INCF 0x71, W
   5A7    00A7     MOVWF 0x27
353:               	     break;
   5A8    2DB9     GOTO 0x5b9
354:                   default: Position =  0 + Xpos;
   5B6    0825     MOVF 0x25, W
   5B7    00A6     MOVWF 0x26
   5B8    01A7     CLRF 0x27
355:               	     break;
356:                 }
357:               
358:                // Set the cursor position (DDRAM address)
359:                Position = Position | 0b10000000;	// Set DB7 to 1
   5B9    17A6     BSF 0x26, 0x7
360:                RS    = 0;
   5BA    1005     BCF 0x5, 0
361:                RW    = 0;
   5BB    1085     BCF 0x5, 0x1
362:                DB4   = ((Position & 0b00010000) == 16) ? 1 : 0;
   5BC    1E26     BTFSS 0x26, 0x4
   5BD    2DC0     GOTO 0x5c0
   5BE    1486     BSF 0x6, 0x1
   5BF    2DC1     GOTO 0x5c1
   5C0    1086     BCF 0x6, 0x1
363:                DB5   = ((Position & 0b00100000) == 32) ? 1 : 0; 
   5C1    1283     BCF 0x3, 0x5
   5C2    1303     BCF 0x3, 0x6
   5C3    1EA6     BTFSS 0x26, 0x5
   5C4    2DC7     GOTO 0x5c7
   5C5    1506     BSF 0x6, 0x2
   5C6    2DC8     GOTO 0x5c8
   5C7    1106     BCF 0x6, 0x2
364:                DB6   = ((Position & 0b01000000) == 64) ? 1 : 0; 
   5C8    1F26     BTFSS 0x26, 0x6
   5C9    2DCC     GOTO 0x5cc
   5CA    1586     BSF 0x6, 0x3
   5CB    2DCD     GOTO 0x5cd
   5CC    1186     BCF 0x6, 0x3
365:                DB7   = ((Position & 0b10000000) == 128) ? 1 : 0; 
   5CD    1FA6     BTFSS 0x26, 0x7
   5CE    2DD1     GOTO 0x5d1
   5CF    1606     BSF 0x6, 0x4
   5D0    2DD2     GOTO 0x5d2
   5D1    1206     BCF 0x6, 0x4
366:                EN    = 1;
   5D2    1505     BSF 0x5, 0x2
367:                asm("nop");
   5D3    0000     NOP
368:                asm("nop");
   5D4    0000     NOP
369:                asm("nop");
   5D5    0000     NOP
370:                asm("nop");
   5D6    0000     NOP
371:                asm("nop");
   5D7    0000     NOP
372:                EN    = 0;
   5D8    1105     BCF 0x5, 0x2
373:                DB4   = ((Position & 0b00000001) == 1) ? 1 : 0;
   5D9    1C26     BTFSS 0x26, 0
   5DA    2DDD     GOTO 0x5dd
   5DB    1486     BSF 0x6, 0x1
   5DC    2DDE     GOTO 0x5de
   5DD    1086     BCF 0x6, 0x1
374:                DB5   = ((Position & 0b00000010) == 2) ? 1 : 0; 
   5DE    1CA6     BTFSS 0x26, 0x1
   5DF    2DE2     GOTO 0x5e2
   5E0    1506     BSF 0x6, 0x2
   5E1    2DE3     GOTO 0x5e3
   5E2    1106     BCF 0x6, 0x2
375:                DB6   = ((Position & 0b00000100) == 4) ? 1 : 0; 
   5E3    1D26     BTFSS 0x26, 0x2
   5E4    2DE7     GOTO 0x5e7
   5E5    1586     BSF 0x6, 0x3
   5E6    2DE8     GOTO 0x5e8
   5E7    1186     BCF 0x6, 0x3
376:                DB7   = ((Position & 0b00001000) == 8) ? 1 : 0; 
   5E8    1DA6     BTFSS 0x26, 0x3
   5E9    2DEC     GOTO 0x5ec
   5EA    1606     BSF 0x6, 0x4
   5EB    2DED     GOTO 0x5ed
   5EC    1206     BCF 0x6, 0x4
377:                EN    = 1;
   5ED    1505     BSF 0x5, 0x2
378:                asm("nop");
   5EE    0000     NOP
379:                asm("nop");
   5EF    0000     NOP
380:                asm("nop");
   5F0    0000     NOP
381:                asm("nop");
   5F1    0000     NOP
382:                asm("nop");
   5F2    0000     NOP
383:                EN    = 0;
   5F3    1105     BCF 0x5, 0x2
384:                GenDelay(20); // Wait approx 59 us (minimum requested is 37 us)
   5F4    3014     MOVLW 0x14
   5F5    00A8     MOVWF 0x28
   5F6    01A9     CLRF 0x29
   5F7    24D4     CALL 0x4d4
385:               
386:                // Show the char on the LCD
387:                RS    = 1;
   5F8    1405     BSF 0x5, 0
388:                RW    = 0;
   5F9    1085     BCF 0x5, 0x1
389:                DB4   = ((CharToDisp & 0b00010000) == 16) ? 1 : 0;
   5FA    1E24     BTFSS 0x24, 0x4
   5FB    2DFE     GOTO 0x5fe
   5FC    1486     BSF 0x6, 0x1
   5FD    2DFF     GOTO 0x5ff
   5FE    1086     BCF 0x6, 0x1
390:                DB5   = ((CharToDisp & 0b00100000) == 32) ? 1 : 0; 
   5FF    1283     BCF 0x3, 0x5
   600    1303     BCF 0x3, 0x6
   601    1EA4     BTFSS 0x24, 0x5
   602    2E05     GOTO 0x605
   603    1506     BSF 0x6, 0x2
   604    2E06     GOTO 0x606
   605    1106     BCF 0x6, 0x2
391:                DB6   = ((CharToDisp & 0b01000000) == 64) ? 1 : 0; 
   606    1F24     BTFSS 0x24, 0x6
   607    2E0A     GOTO 0x60a
   608    1586     BSF 0x6, 0x3
   609    2E0B     GOTO 0x60b
   60A    1186     BCF 0x6, 0x3
392:                DB7   = ((CharToDisp & 0b10000000) == 128) ? 1 : 0; 
   60B    1FA4     BTFSS 0x24, 0x7
   60C    2E0F     GOTO 0x60f
   60D    1606     BSF 0x6, 0x4
   60E    2E10     GOTO 0x610
   60F    1206     BCF 0x6, 0x4
393:                EN    = 1;
   610    1505     BSF 0x5, 0x2
394:                asm("nop");
   611    0000     NOP
395:                asm("nop");
   612    0000     NOP
396:                asm("nop");
   613    0000     NOP
397:                asm("nop");
   614    0000     NOP
398:                asm("nop");
   615    0000     NOP
399:                EN    = 0;
   616    1105     BCF 0x5, 0x2
400:                DB4   = ((CharToDisp & 0b00000001) == 1) ? 1 : 0;
   617    1C24     BTFSS 0x24, 0
   618    2E1B     GOTO 0x61b
   619    1486     BSF 0x6, 0x1
   61A    2E1C     GOTO 0x61c
   61B    1086     BCF 0x6, 0x1
401:                DB5   = ((CharToDisp & 0b00000010) == 2) ? 1 : 0; 
   61C    1CA4     BTFSS 0x24, 0x1
   61D    2E20     GOTO 0x620
   61E    1506     BSF 0x6, 0x2
   61F    2E21     GOTO 0x621
   620    1106     BCF 0x6, 0x2
402:                DB6   = ((CharToDisp & 0b00000100) == 4) ? 1 : 0; 
   621    1D24     BTFSS 0x24, 0x2
   622    2E25     GOTO 0x625
   623    1586     BSF 0x6, 0x3
   624    2E26     GOTO 0x626
   625    1186     BCF 0x6, 0x3
403:                DB7   = ((CharToDisp & 0b00001000) == 8) ? 1 : 0; 
   626    1DA4     BTFSS 0x24, 0x3
   627    2E2A     GOTO 0x62a
   628    1606     BSF 0x6, 0x4
   629    2E2B     GOTO 0x62b
   62A    1206     BCF 0x6, 0x4
404:                EN    = 1;
   62B    1505     BSF 0x5, 0x2
405:                asm("nop");
   62C    0000     NOP
406:                asm("nop");
   62D    0000     NOP
407:                asm("nop");
   62E    0000     NOP
408:                asm("nop");
   62F    0000     NOP
409:                asm("nop");
   630    0000     NOP
410:                EN    = 0;
   631    1105     BCF 0x5, 0x2
411:                GenDelay(20); // Wait approx 59 us (minimum requested is 37 us)
   632    3014     MOVLW 0x14
   633    00A8     MOVWF 0x28
   634    01A9     CLRF 0x29
   635    24D4     CALL 0x4d4
412:                RS    = 0;
   636    1005     BCF 0x5, 0
413:                RW    = 0;
   637    1085     BCF 0x5, 0x1
414:               
415:                return;
416:               }
   638    0008     RETURN
---  C:\Temp\PIC_LCD\lcddisp.c  ------------------------------------------------------------------
1:                 #include <pic.h>
2:                 #include <stdio.h>
3:                 
4:                 #include "lcd-lib.h"		// Pin definition file for the LCD
5:                 
6:                 // ---------------------------------------------------------------------------
7:                 // Design  : LCDDISP.PJT
8:                 // Purpose : LCD display with PIC16F870 (LCD 2x16) 4 bit interface
9:                 // Author  : Powermos
10:                // Date    : 25/09/2008
11:                // Rev     : 0
12:                // General : Fosc = 20.000 MHz, C1=C2=33 pF, Rosc2 = 10 Ohm, Hi-Tech compiler
13:                // ---------------------------------------------------------------------------
14:                //
15:                //	PORTA	
16:                //		0 = RS (Data / Instruction register select)
17:                //		1 = RW (Read / Write )
18:                //		2 = EN (Enable signal, start data read / write)
19:                //		3 = NOT USED (Input)
20:                //		4 = NOT USED (Input)
21:                //		5 = NOT USED (Input)
22:                //
23:                //	PORTB (4 bit data bus display LCD)
24:                //		0 = NOT USED (Input)
25:                //		1 = NOT USED (Input)
26:                //		2 = NOT USED (Input)
27:                //		3 = NOT USED (Input)
28:                //		4 = DB4
29:                //		5 = DB5
30:                //		6 = DB6
31:                //		7 = DB7
32:                //
33:                //	PORTC
34:                //		0 = NOT USED (Input)
35:                //		1 = NOT USED (Input)
36:                //		2 = NOT USED (Input)
37:                //		3 = NOT USED (Input)
38:                //		4 = NOT USED (Input)
39:                //		5 = NOT USED (Input)
40:                //		6 = NOT USED (Input)
41:                //		7 = NOT USED (Input)
42:                //
43:                // ---------------------------------------------------------------------------
44:                
45:                 __CONFIG(0x3F72);
46:                 __IDLOC(FFFF); // ID0 = 0F, ID1 = 0F, ID2 = 0F, ID3 = 0F
47:                
48:                // ===========================================================================
49:                // GLOBAL VARIABLE DEFINITION
50:                // ===========================================================================
51:                unsigned char SWVersion[] = "Ver. 1.0";
52:                unsigned char SWDate[]    = "25/09/2008";
53:                
54:                // ===========================================================================
55:                // FUNCTIONS DECLARATION
56:                // ===========================================================================
57:                void HardwareInit(void);              									// Inizializzazione periferiche hardware
58:                void interrupt InterruptServiceRoutine(void);   						// Funzione per gestione interrupt
59:                
60:                // ===========================================================================
61:                // FUNCTIONS DEFINITION
62:                // ===========================================================================
63:                
64:                void  HardwareInit(void)
65:                { 
66:                 // -----------------------------------------------------------------------
67:                 // uP hardware initialization
68:                 // -----------------------------------------------------------------------
69:                 
70:                 // ADC off, all digital I/O
71:                 ADON = 0;
   4DE    0183     CLRF 0x3
   4DF    101F     BCF 0x1f, 0
72:                 ADCON1 = 0b00000110;
   4E0    3006     MOVLW 0x6
   4E1    1683     BSF 0x3, 0x5
   4E2    009F     MOVWF 0x1f
73:                
74:                 // PORT direction register
75:                 TRISA = 0b11111000;
   4E3    30F8     MOVLW 0xf8
   4E4    0085     MOVWF 0x5
76:                 TRISB = 0b11100001;
   4E5    30E1     MOVLW 0xe1
   4E6    0086     MOVWF 0x6
77:                 TRISC = 0b11111111;
   4E7    30FF     MOVLW 0xff
   4E8    0087     MOVWF 0x7
78:                
79:                 return;
80:                }                                                                                                       
   4E9    1283     BCF 0x3, 0x5
81:                
82:                // -----------------------------------------------------------------------
83:                // Interrupt handler
84:                // -----------------------------------------------------------------------
85:                
86:                void interrupt InterruptServiceRoutine(void)
87:                 {
88:                   GIE = 0;		
   008    138B     BCF 0xb, 0x7
89:                
90:                   // ...........   
91:                
92:                   GIE = 1;		
   009    178B     BSF 0xb, 0x7
93:                   return; 
94:                }
   00A    1303     BCF 0x3, 0x6
95:                
96:                // -----------------------------------------------------------------------
97:                // Include the LCD source code
98:                // -----------------------------------------------------------------------
99:                #include "lcd-lib.c"
100:               
101:               // ===========================================================================
102:               // MAIN
103:               // ===========================================================================
104:               void main(void)
105:               {
   6F5    1283     BCF 0x3, 0x5
106:                 unsigned char i = 0;
   6F6    1303     BCF 0x3, 0x6
   6F7    01A2     CLRF 0x22
107:                 unsigned char Xpos = 0;
   6F8    01A0     CLRF 0x20
108:                 unsigned char Ypos = 0;
   6F9    01A1     CLRF 0x21
109:               
110:                 // Init the uP hardware
111:                 HardwareInit();
   6FA    24DE     CALL 0x4de
112:                 
113:                 // Power-up time (almeno 50 ms)
114:                 LongDelay(10);
   6FB    300A     MOVLW 0xa
   6FC    00A3     MOVWF 0x23
   6FD    01A4     CLRF 0x24
   6FE    01A5     CLRF 0x25
   6FF    01A6     CLRF 0x26
   700    250F     CALL 0x50f
115:               
116:                 // Must be the first function called!!!!
117:                 LCDInit();
   701    2639     CALL 0x639
118:               
119:                 // Show the software release version
120:                 Xpos = 4;
   702    3004     MOVLW 0x4
   703    00A0     MOVWF 0x20
121:                 Ypos = 1;	
   704    01A1     CLRF 0x21
   705    0AA1     INCF 0x21, F
122:                 for(i = 0; i <= 7; i++)
   706    01A2     CLRF 0x22
   712    0AA2     INCF 0x22, F
   713    3008     MOVLW 0x8
   714    0222     SUBWF 0x22, W
   715    1C03     BTFSS 0x3, 0
   716    2F07     GOTO 0x707
123:               	 Printxy(Xpos+i, Ypos, *(SWVersion+i));
   707    0821     MOVF 0x21, W
   708    00A3     MOVWF 0x23
   709    0822     MOVF 0x22, W
   70A    3E2B     ADDLW 0x2b
   70B    0084     MOVWF 0x4
   70C    1383     BCF 0x3, 0x7
   70D    0800     MOVF 0, W
   70E    00A4     MOVWF 0x24
   70F    0820     MOVF 0x20, W
   710    0722     ADDWF 0x22, W
   711    2589     CALL 0x589
124:                
125:                 // Show the data release
126:                 Xpos = 3;	
   717    3003     MOVLW 0x3
   718    00A0     MOVWF 0x20
127:                 Ypos = 2;
   719    3002     MOVLW 0x2
   71A    00A1     MOVWF 0x21
128:                 for(i = 0; i <= 9; i++)
   71B    01A2     CLRF 0x22
   727    0AA2     INCF 0x22, F
   728    300A     MOVLW 0xa
   729    0222     SUBWF 0x22, W
   72A    1C03     BTFSS 0x3, 0
   72B    2F1C     GOTO 0x71c
129:                   Printxy(Xpos+i, Ypos, *(SWDate+i));
   71C    0821     MOVF 0x21, W
   71D    00A3     MOVWF 0x23
   71E    0822     MOVF 0x22, W
   71F    3E34     ADDLW 0x34
   720    0084     MOVWF 0x4
   721    1383     BCF 0x3, 0x7
   722    0800     MOVF 0, W
   723    00A4     MOVWF 0x24
   724    0820     MOVF 0x20, W
   725    0722     ADDWF 0x22, W
   726    2589     CALL 0x589
130:               
131:                 // Wait for 2s
132:                 LongDelay(400);
   72C    3090     MOVLW 0x90
   72D    00A3     MOVWF 0x23
   72E    3001     MOVLW 0x1
   72F    00A4     MOVWF 0x24
   730    3000     MOVLW 0
   731    01A5     CLRF 0x25
   732    01A6     CLRF 0x26
   733    250F     CALL 0x50f
133:               
134:                 ClearDisplay();
   734    24EB     CALL 0x4eb
135:               
136:                 // Write char at the specified location
137:                 Printxy(0 , 1, 'H');
   735    01A3     CLRF 0x23
   736    0AA3     INCF 0x23, F
   737    3048     MOVLW 0x48
   738    00A4     MOVWF 0x24
   739    3000     MOVLW 0
   73A    2589     CALL 0x589
138:                 Printxy(1 , 1, 'E');
   73B    01A3     CLRF 0x23
   73C    0AA3     INCF 0x23, F
   73D    3045     MOVLW 0x45
   73E    00A4     MOVWF 0x24
   73F    3001     MOVLW 0x1
   740    2589     CALL 0x589
139:                 Printxy(2 , 1, 'L');
   741    01A3     CLRF 0x23
   742    0AA3     INCF 0x23, F
   743    304C     MOVLW 0x4c
   744    00A4     MOVWF 0x24
   745    3002     MOVLW 0x2
   746    2589     CALL 0x589
140:                 Printxy(3 , 1, 'L');
   747    01A3     CLRF 0x23
   748    0AA3     INCF 0x23, F
   749    304C     MOVLW 0x4c
   74A    00A4     MOVWF 0x24
   74B    3003     MOVLW 0x3
   74C    2589     CALL 0x589
141:                 Printxy(4 , 1, 'O');
   74D    01A3     CLRF 0x23
   74E    0AA3     INCF 0x23, F
   74F    304F     MOVLW 0x4f
   750    00A4     MOVWF 0x24
   751    3004     MOVLW 0x4
   752    2589     CALL 0x589
142:                 Printxy(5 , 1, ' ');
   753    01A3     CLRF 0x23
   754    0AA3     INCF 0x23, F
   755    3020     MOVLW 0x20
   756    00A4     MOVWF 0x24
   757    3005     MOVLW 0x5
   758    2589     CALL 0x589
143:                 Printxy(6 , 1, 'W');
   759    01A3     CLRF 0x23
   75A    0AA3     INCF 0x23, F
   75B    3057     MOVLW 0x57
   75C    00A4     MOVWF 0x24
   75D    3006     MOVLW 0x6
   75E    2589     CALL 0x589
144:                 Printxy(7 , 1, 'O');
   75F    01A3     CLRF 0x23
   760    0AA3     INCF 0x23, F
   761    304F     MOVLW 0x4f
   762    00A4     MOVWF 0x24
   763    3007     MOVLW 0x7
   764    2589     CALL 0x589
145:                 Printxy(8 , 1, 'R');
   765    01A3     CLRF 0x23
   766    0AA3     INCF 0x23, F
   767    3052     MOVLW 0x52
   768    00A4     MOVWF 0x24
   769    3008     MOVLW 0x8
   76A    2589     CALL 0x589
146:                 Printxy(9, 1, 'L');
   76B    01A3     CLRF 0x23
   76C    0AA3     INCF 0x23, F
   76D    304C     MOVLW 0x4c
   76E    00A4     MOVWF 0x24
   76F    3009     MOVLW 0x9
   770    2589     CALL 0x589
147:                 Printxy(10, 1, 'D');
   771    01A3     CLRF 0x23
   772    0AA3     INCF 0x23, F
   773    3044     MOVLW 0x44
   774    00A4     MOVWF 0x24
   775    300A     MOVLW 0xa
   776    2589     CALL 0x589
148:                 Printxy(11, 1, '!');
   777    01A3     CLRF 0x23
   778    0AA3     INCF 0x23, F
   779    3021     MOVLW 0x21
   77A    00A4     MOVWF 0x24
   77B    300B     MOVLW 0xb
   77C    2589     CALL 0x589
149:               
150:                 Printxy(0 , 2, 'L');
   77D    3002     MOVLW 0x2
   77E    00A3     MOVWF 0x23
   77F    304C     MOVLW 0x4c
   780    00A4     MOVWF 0x24
   781    3000     MOVLW 0
   782    2589     CALL 0x589
151:                 Printxy(1 , 2, 'C');
   783    3002     MOVLW 0x2
   784    00A3     MOVWF 0x23
   785    3043     MOVLW 0x43
   786    00A4     MOVWF 0x24
   787    3001     MOVLW 0x1
   788    2589     CALL 0x589
152:                 Printxy(2 , 2, 'D');
   789    3002     MOVLW 0x2
   78A    00A3     MOVWF 0x23
   78B    3044     MOVLW 0x44
   78C    00A4     MOVWF 0x24
   78D    3002     MOVLW 0x2
   78E    2589     CALL 0x589
153:                 Printxy(3 , 2, ' ');
   78F    3002     MOVLW 0x2
   790    00A3     MOVWF 0x23
   791    3020     MOVLW 0x20
   792    00A4     MOVWF 0x24
   793    3003     MOVLW 0x3
   794    2589     CALL 0x589
154:                 Printxy(4 , 2, 'T');
   795    3002     MOVLW 0x2
   796    00A3     MOVWF 0x23
   797    3054     MOVLW 0x54
   798    00A4     MOVWF 0x24
   799    3004     MOVLW 0x4
   79A    2589     CALL 0x589
155:                 Printxy(5 , 2, 'E');
   79B    3002     MOVLW 0x2
   79C    00A3     MOVWF 0x23
   79D    3045     MOVLW 0x45
   79E    00A4     MOVWF 0x24
   79F    3005     MOVLW 0x5
   7A0    2589     CALL 0x589
156:                 Printxy(6 , 2, 'S');
   7A1    3002     MOVLW 0x2
   7A2    00A3     MOVWF 0x23
   7A3    3053     MOVLW 0x53
   7A4    00A4     MOVWF 0x24
   7A5    3006     MOVLW 0x6
   7A6    2589     CALL 0x589
157:                 Printxy(7 , 2, 'T');
   7A7    3002     MOVLW 0x2
   7A8    00A3     MOVWF 0x23
   7A9    3054     MOVLW 0x54
   7AA    00A4     MOVWF 0x24
   7AB    3007     MOVLW 0x7
   7AC    2589     CALL 0x589
158:               
159:                 CursorAtHome();
   7AD    2548     CALL 0x548
160:               
161:                 // Wait for 2s
162:                 LongDelay(400);
   7AE    3090     MOVLW 0x90
   7AF    00A3     MOVWF 0x23
   7B0    3001     MOVLW 0x1
   7B1    00A4     MOVWF 0x24
   7B2    3000     MOVLW 0
   7B3    01A5     CLRF 0x25
   7B4    01A6     CLRF 0x26
   7B5    250F     CALL 0x50f
163:               
164:                 // -----------------------------
165:                 // Main loop
166:                 // -----------------------------
167:                 while (1)
168:               	{
169:               		asm("clrwdt");
   7B6    0064     CLRWDT
170:               
171:               		for (i=0; i<=MAXPOSX; i++)
   7B7    01A2     CLRF 0x22
   7CC    0AA2     INCF 0x22, F
   7CD    3011     MOVLW 0x11
   7CE    0222     SUBWF 0x22, W
   7CF    1C03     BTFSS 0x3, 0
   7D0    2FB8     GOTO 0x7b8
172:               			{
173:               				ClearDisplay();
   7B8    24EB     CALL 0x4eb
174:               				Printxy(i , 1, '*');
   7B9    01A3     CLRF 0x23
   7BA    0AA3     INCF 0x23, F
   7BB    302A     MOVLW 0x2a
   7BC    00A4     MOVWF 0x24
   7BD    0822     MOVF 0x22, W
   7BE    2589     CALL 0x589
175:               				Printxy(MAXPOSX-i, 2, '*');
   7BF    3002     MOVLW 0x2
   7C0    00A3     MOVWF 0x23
   7C1    302A     MOVLW 0x2a
   7C2    00A4     MOVWF 0x24
   7C3    0822     MOVF 0x22, W
   7C4    3C10     SUBLW 0x10
   7C5    2589     CALL 0x589
176:               				LongDelay(10);	
   7C6    300A     MOVLW 0xa
   7C7    00A3     MOVWF 0x23
   7C8    01A4     CLRF 0x24
   7C9    01A5     CLRF 0x25
   7CA    01A6     CLRF 0x26
   7CB    250F     CALL 0x50f
177:               			}
178:               
179:               		for (i=0; i<=MAXPOSX; i++)
   7D1    01A2     CLRF 0x22
   7E6    0AA2     INCF 0x22, F
180:               			{
181:               				ClearDisplay();
   7D2    24EB     CALL 0x4eb
182:               				Printxy(MAXPOSX-i , 1, '*');
   7D3    01A3     CLRF 0x23
   7D4    0AA3     INCF 0x23, F
   7D5    302A     MOVLW 0x2a
   7D6    00A4     MOVWF 0x24
   7D7    0822     MOVF 0x22, W
   7D8    3C10     SUBLW 0x10
   7D9    2589     CALL 0x589
183:                               Printxy(i , 2, '*');
   7DA    3002     MOVLW 0x2
   7DB    00A3     MOVWF 0x23
   7DC    302A     MOVLW 0x2a
   7DD    00A4     MOVWF 0x24
   7DE    0822     MOVF 0x22, W
   7DF    2589     CALL 0x589
184:               				LongDelay(10);	
   7E0    300A     MOVLW 0xa

Bye
Pow
 
  • Like
Reactions: netart

    netart

    Points: 2
    Helpful Answer Positive Rating
Let me know if you need some help.

Bye
Pow
 

hi tekut...

i'm currently doing for the energy meter project...i'm using the pic16f877a...the input for this pic is current, voltage and also phase differnce cct...then the pic have to calculate the kwh and display it on the lcd...can u kindly provide the source code for me...
 

Dear pisces12,
the source code is included into the tutorial and is written in C language for the Hi-Tech compiler.

Regards
 
hi tekut, i need help on keypad interfacing pic. what i have to do is almost like mobile keypad. As you imagine that, when i press the buttom of 2, it would show A, in 2 or 3 seconds, if i press it again, it would show on the lcd, B.. i got a code like this, but i'm not quite sure that it is true. So can you help me on that pls?? İ got 4x4 keypad, and pic 16F877A...

#define DELAY_FOR_NEXT 1000 // Delay before orginal Key is returnd time depends on how foten the "Call_Me_Every_1ms()" rutine is called

// Key_list[number of keys][number of characters/key]
// if you whant to have more characters on some keys then use a null on empty spots like below
//const unsigned char Key_list[9][6]={{'A','B','C','1',!,¤},{'D','E',0,0,'F','2',%,0},{'G','H','I','3','<','>'},{'J','K','L','4',0,0},{'M','N','O','5',0,0},{'P','Q','R','6',0,0},{'S','T','U','7',0,0},{'V','W','X','8',0,0},{'Y','Z','9',' ',0,0}};

const unsigned char Key_list[9][4]={{'A','B','C','1'},{'D','E','F','2'},{'G','H','I','3'},{'J','K','L','4'},{'M','N','O','5'},{'P','Q','R','6'},{'S','T','U','7'},{'V','W','X','8'},{'Y','Z','9',' '}};
unsigned short Delay_Timer= 0; // Timer for delay
unsigned char NewKey= 0; // use this as a way to see if the value is stepped or a new Key were pressed

void Call_Me_Every_1ms(){ // call this rutine at a steddy pase, if not value will step every time the DoKey() rutine is called whit the same value
if( Delay_Timer < 0xffff ) Delay_Timer++;
}

unsigned char DoKey(unsigned char Key) { // call this rutine with the Key pressed "as a character 0-9" and it returnes the value to display if called whit any other it returns null
static unsigned char step, last; // local

if( Key < '0' || Key > '9' ) return 0; // if not a valid value return null
if( Key == last && (Delay_Timer < DELAY_FOR_NEXT) ) { step++; NewKey= 1; } else { NewKey= 0; last= Key; step= 0; Delay_Timer= 0; } // check if same Key and the amount of time is less then time before next Key should be displayd
if( (step >= sizeof(Key_list[0])) || (Key_list[Key-'0'][step] == 0 ) ) step= 0; // if step is bigger than amount of chars in list or if null go to beginning of list

return Key_list[Key-'0'][step]; // return the value for the Key as a character
}

unsigned char tstkey= 0; // only for test of this
unsigned char display_char; // only for test of this

void main( void )
{
do{
display_char= DoKey('1');
if( NewKey ) // this is a check if display should move to new position and desplay character, remove if not needed
display_char;
else
display_char;
Call_Me_Every_1ms(); // update timer
Delay_ms(1);
}while(1);
}
 

Re: LCD interfacing with a PIC16f877a

hii
i m working on a project 'bite force measurement' for that i need to interface graphical lcd with pic16f877A using assembly language plz post me the programm for the same.
 

Re: LCD interfacing with a PIC16f877a

hii
i m working on a project 'bite force measurement' for that i need to interface graphical lcd with pic16f877A using assembly language plz post me the programm for the same.


lcd asm code for pic16f :lcd-display

lcd C code for pic18F : lcd-hello-world

i hope it useful to u
 

Below is some code I am working on, to create a LCD that can be connected to any device using a software serial protocol, if that is of any help. There is some delay routine that may not be used, but I just cut and paste these from other projects and saves reinventing the wheel.


Code:
        list p=16f636
        include "p16f636.inc"
 
 
temp        equ    0x20
Delay        equ    0x21        ;Delay counter
Delay2        equ    0x22        ;Delay counter 2
Delay3        equ     0x23        ;Delay counter 3
count        equ    0x24
 
bit_count     equ    0x25
Rec_byte     equ    0x26
 
 
#define    en    porta,1
#define    rs    porta,2
 
 
    ;Start at the reset vector
    ;code for bootloader
    ORG 0x0000 ;reset vector 
;    clrf 0x3 ;zero status
;    movlw 0x00 ;high byte of long jump <<<these next 2 lines are important
;    movwf 0xA ;zero PCLATH
    goto start
 
 
;********************************************************************************************
;Setup up the delay routines that may be used
;delay of 1ms for 4mHz clock
Delay_1ms
    Movlw    D'166'    
    Movwf    Delay
delay_loop
    Nop
    Nop
    Nop
    Decfsz    Delay,f
    goto     delay_loop
    return
;delay of 10ms for 4mHz clock
Delay_10ms
    movlw    d'10'
    movwf    Delay2
Delay_Loop_10ms    
    Call     Delay_1ms        ; Call 1ms delay    
    Decfsz    Delay2,f
    goto     Delay_Loop_10ms
    return
 
;delay of 100ms for 4mHz clock
Delay_100ms
    movlw    d'100'
Delay_100x
    movwf    Delay2
Delay_Loop_100ms    
    Call     Delay_1ms        ; Call 1ms delay    
    Decfsz    Delay2,f
    goto     Delay_Loop_100ms
    return
 
;delay of 1ms for 4mHz clock
Delay_1s
    movlw    d'10'
    movwf    Delay3
Delay_Loop_1s    
    Call     Delay_100ms        ; Call 100ms delay    
    Decfsz    Delay3,f
    goto     Delay_Loop_1s
    return
 
Delay_52ns
    movlw   0x0C
        movwf   Delay
Delay_52ns_loop 
    nop
        decfsz      Delay , f
        goto        Delay_52ns_loop
    return
 
Delay_104ns
    movlw   0x18
        movwf   Delay
Delay_104ns_loop 
    nop
        decfsz      Delay , f
        goto        Delay_104ns_loop
    return
 
 
 
;********************************************************************************************
;initialize the display
initLCD
    movlw        d'20'
    movwf        delay2            ;set up 20ms delay
    call            delay_loop_10ms
    bcf            rs
    bcf            en
    movlw        0x03
    movwf        portc
    bsf            en
    nop
    bcf            en
    movlw        d'5'
    movwf        delay2            ;set up 5ms delay
    call            delay_loop_10ms
 
    movlw        0x03
    movwf        portc
    bsf            en
    nop
    bcf            en
    movlw        d'34'
    movwf        delay            ;set up 200us delay
    call            delay_loop
 
    movlw        0x03
    movwf        portc
    bsf            en
    nop
    bcf            en
    movlw        d'34'
    movwf        delay            ;set up 200us delay
    call            delay_loop
 
    movlw        0x02
    movwf        portc
    bsf            en
    nop
    bcf            en
    movlw        d'5'
    movwf        delay2            ;set up 5ms delay
    call            delay_loop_10ms
 
    movlw        0x28    
    call            writecmd    
    movlw        0x08    
    call            writecmd
    movlw        0x01    
    call            writecmd
    movlw        0x06    
    call            writecmd
    movlw        0x0C
    call            writecmd
    return
 
;********************************************************************************************
writecmd
    movwf        temp        
    swapf        temp,W   
    movwf        portc       
    bcf            rs
     bsf            en      
    nop    
    bcf            en
    movlw        0x05
    movwf        delay2            
    call            delay_loop_10ms
    movf        temp,W 
    movwf        portc     
    bcf            rs 
    bsf            en        
    nop
    bcf            en
    movlw        0x05
    movwf        delay2            
    call            delay_loop_10ms
    return
;********************************************************************************************
writechar
    movwf        temp        
    swapf        temp,W   
    movwf        portc    
    bsf            rs   
     bsf            en          
    nop    
    bcf            en
    movlw        d'34'
    movwf        delay            ;set up 200us delay
    call            delay_loop
    movf        temp,W 
    movwf        portc   
    bsf            rs   
    bsf            en      
    nop    
    bcf            en
    movlw        d'34'
    movwf        delay            ;set up 200us delay
    call            delay_loop
    return
;********************************************************************************************
;********************************************************************************************
Start
    banksel        porta
    clrf            porta
    clrf            portc
    movlw        0x07
    movwf        cmcon0
 
    banksel        trisa
    clrf            portc    
    movlw        b'100001'
    movwf        porta
 
    movwf        wda
    movwf        wpuda
 
    movlw        b'100000'
    movwf        ioca
    bsf            intcon,RAIE        ;enable interrupt on change
    bcf            intcon,T0IE        ;disable TMR interrupt
    banksel        porta
 
 
    call            initlcd
 
 
 
 
;read our serial port baud 9800 8N1
; wait for the serial port to go high
Wait_for_high
    btfsc        porta,0    
    goto        Wait_for_High
    call            delay_52ns
    btfsc        porta,0
    goto        Wait_for_High
;read the next 8 bits
 
    movlw        0x08
    movwf        bit_count
    clrf            rec_byte
next_bit
    call            delay_104ns
    btfss        porta,0
    bcf            status,c
    btfsc        porta,0
    bsf            status,c
    rrf            rec_byte,1
    decfsz        bit_count,1
    goto        next_bit
    call            delay_104ns
    movfw        rec_byte
 
    sublw        d'31'
    btfss        status,C
    goto        printChar
    movfw        rec_byte
    call            writecmd
    goto        wait_for_high
 
PrintChar
    movfw        rec_byte
    call            writechar
    goto        wait_for_high
 
 
 
 
 
end
 

Attachments

  • serial_lcd.zip
    1.4 KB · Views: 111
Last edited:

JUst learning about PIC16F877A using HI-TECH ANSI C Compiler.....
I just get this display on my LCD....
 

Re: pic lcd tutorial

I am using PIC18F4220 and hi-tech compiler,but whenever i try to compile your source code .Following Errors occurs.

[141] C:\Documents and Settings\Administrator\My Documents\Downloads\lcddisp.c; 1.16 can't open include file "pic.h": No such file or directory

I have also attached the pictures of the error i am facing
Please help me
I will be very thankful to you

Best Regards
 

Attachments

  • Eror.bmp
    2.3 MB · Views: 121
  • ERROR.bmp
    2.3 MB · Views: 109

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top