OpenCores
URL https://opencores.org/ocsvn/mcip_open/mcip_open/trunk

Subversion Repositories mcip_open

[/] [mcip_open/] [trunk/] [Hi_MCIPopen.ASM] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mezzah
;******************************************************************************
2
;                                                                             *
3
;    Filename:       Hi_MCIPopen.asm                                          *
4
;    Description:    ASM program for MCIPopen implementation example          *
5
;    Date:           07/25/2015                                               *
6
;    File Version:   1                                                        *
7
;    Tool:           MPLAB IDE v8.83                                          *
8
;                                                                             *
9
;    Author:         Ibrahim MEZZAH                                           *
10
;    Company:        Ferhat Abbas University - Algeria                        *
11
;                                                                             *
12
;******************************************************************************
13
;                                                                             *
14
;    Files Required: P18F4410.INC                                             *
15
;                                                                             *
16
;******************************************************************************
17
 
18
        LIST P=18F4410  ;directive to define processor
19
        #include        ;processor specific variable definitions
20
 
21
 
22
 
23
;   Oscillator Selection:
24
    CONFIG      OSC = LP             ;LP
25
 
26
 
27
 
28
; LCD defines /////////////////////////////////////////
29
#define LCD_DATA_PRT       0xF8B ;/*PRTC*/
30
#define LCD_DATA_PORT      0x8B
31
#define LCD_TRIS_DATA_PORT 0x94
32
#define LCD_INST_PORT      0x8C ;/*PRTD*/
33
#define LCD_TRIS_INST_PORT 0x95
34
 
35
#define RW_PIN   5   ;/* PORT for RW */
36
#define RS_PIN   6   ;/* PORT for RS */
37
#define E_PIN    7   ;/* PORT for E  */
38
 
39
#define FOUR_BIT                        0x28    ;0b00101000
40
#define CLEAR                           0x01    ;0b00000001
41
#define CURSOR_HOME                     0x02    ;0b00000010
42
#define MODE_SET                        0x06    ;0b00000110
43
#define DISPLAY_ON_C            0x0e    ;0b00001110
44
#define DISPLAY_ON_B            0x0f    ;0b00001111
45
#define DISPLAY_ON                      0x0c    ;0b00001100
46
#define DISPLAY_OFF                     0x08    ;0b00001000
47
#define SHIFT_D_R                       0x1c    ;0b00011100
48
#define SHIFT_D_L                       0x18    ;0b00011000
49
#define SHIFT_C_R                       0x14    ;0b00010100
50
#define SHIFT_C_L                       0x10    ;0b00010000
51
 
52
#define access    0
53
 
54
                CBLOCK  0x080
55
                WREG_TEMP1      ;variable used for context saving
56
                STATUS_TEMP1 ;variable used for context saving
57
                BSR_TEMP1       ;variable used for context saving
58
 
59
                WREG_TEMP2      ;variable used for context saving
60
                STATUS_TEMP2 ;variable used for context saving
61
                BSR_TEMP2       ;variable used for context saving
62
 
63
                WREG_TEMP3      ;variable used for context saving
64
                STATUS_TEMP3 ;variable used for context saving
65
                BSR_TEMP3       ;variable used for context saving
66
 
67
                WREG_TEMP4      ;variable used for context saving
68
                STATUS_TEMP4 ;variable used for context saving
69
                BSR_TEMP4       ;variable used for context saving
70
                ENDC
71
 
72
                CBLOCK  0x009 ;variables in access RAM
73
                e1
74
                e2
75
                e3
76
                e4
77
                LCD_command
78
                LCD_data
79
                ENDC
80
 
81
 
82
;******************************************************************************
83
;Reset vector
84
; This code will start executing when a reset occurs.
85
 
86
                ORG     0x0000
87
 
88
                goto    Main            ;go to start of main code
89
 
90
 
91
 
92
Main:
93
 
94
    ;------------------------------------------------------------------------------
95
    ;  I/O ports configuration
96
    ;------------------------------------------------------------------------------
97
 
98
        MOVLW 0x0f
99
        MOVWF LCD_TRIS_DATA_PORT,0
100
        CLRF LCD_INST_PORT,0
101
        MOVLW 0x1f
102
        MOVWF LCD_TRIS_INST_PORT,0
103
 
104
        MOVLW 0x0f
105
        CLRF LATA
106
        MOVWF TRISA
107
        CLRF TRISB
108
    ;------------------------------------------------------------------------------
109
    ;  LCD Initialisation
110
    ;------------------------------------------------------------------------------
111
 
112
 
113
        MOVLW 0x30
114
        MOVWF LCD_DATA_PORT,0
115
        BSF LCD_INST_PORT,E_PIN,0
116
        NOP
117
        NOP
118
        BCF LCD_INST_PORT,E_PIN,0
119
 
120
        CALL    Delay1_6ms
121
        CALL    Delay1_6ms
122
 
123
        BSF LCD_INST_PORT,E_PIN,0
124
        NOP
125
        NOP
126
        BCF LCD_INST_PORT,E_PIN,0
127
 
128
        CALL    Delay42us
129
        CALL    Delay42us
130
 
131
        BSF LCD_INST_PORT,E_PIN,0
132
        NOP
133
        NOP
134
        BCF LCD_INST_PORT,E_PIN,0
135
 
136
        CALL    Delay42us
137
        CALL    Delay42us
138
 
139
        MOVLW 0x20
140
        MOVWF LCD_DATA_PORT,0
141
        BSF LCD_INST_PORT,E_PIN,0
142
        NOP
143
        NOP
144
        BCF LCD_INST_PORT,E_PIN,0
145
 
146
        CALL    Delay42us
147
        CALL    Delay42us
148
 
149
        MOVLW   FOUR_BIT
150
        MOVWF   LCD_command,access
151
        CALL    Command
152
 
153
        CALL    Delay42us
154
        CALL    Delay42us
155
 
156
        MOVLW   DISPLAY_OFF
157
        MOVWF   LCD_command,access
158
        CALL    Command
159
 
160
        CALL    Delay42us
161
        CALL    Delay42us
162
 
163
        MOVLW   DISPLAY_ON
164
        MOVWF   LCD_command,access
165
        CALL    Command
166
 
167
        CALL    Delay42us
168
        CALL    Delay42us
169
 
170
        MOVLW   MODE_SET
171
        MOVWF   LCD_command,access
172
        CALL    Command
173
 
174
        CALL    Delay42us
175
        CALL    Delay42us
176
 
177
        MOVLW   CLEAR
178
        MOVWF   LCD_command,access
179
        CALL    Command
180
 
181
        CALL    Delay1_6ms
182
        CALL    Delay1_6ms
183
 
184
    ;------------------------------------------------------------------------------
185
    ;  END LCD Initialisation
186
    ;------------------------------------------------------------------------------
187
 
188
        ; Displaying "Hello MCIP!"
189
        MOVLW   0x03
190
        MOVWF   LCD_data,access
191
        CALL    Set_address
192
        CALL    Delay42us
193
 
194
        MOVLW   'H'
195
        MOVWF   LCD_data,access
196
        CALL    Display
197
        CALL    Delay42us
198
 
199
        MOVLW   'e'
200
        MOVWF   LCD_data,access
201
        CALL    Display
202
        CALL    Delay42us
203
 
204
        MOVLW   'l'
205
        MOVWF   LCD_data,access
206
        CALL    Display
207
        CALL    Delay42us
208
 
209
        MOVLW   'l'
210
        MOVWF   LCD_data,access
211
        CALL    Display
212
        CALL    Delay42us
213
 
214
        MOVLW   'o'
215
        MOVWF   LCD_data,access
216
        CALL    Display
217
        CALL    Delay42us
218
 
219
        MOVLW   ' '
220
        MOVWF   LCD_data,access
221
        CALL    Display
222
        CALL    Delay42us
223
 
224
        MOVLW   'M'
225
        MOVWF   LCD_data,access
226
        CALL    Display
227
        CALL    Delay42us
228
 
229
        MOVLW   'C'
230
        MOVWF   LCD_data,access
231
        CALL    Display
232
        CALL    Delay42us
233
 
234
        MOVLW   'I'
235
        MOVWF   LCD_data,access
236
        CALL    Display
237
        CALL    Delay42us
238
 
239
        MOVLW   'P'
240
        MOVWF   LCD_data,access
241
        CALL    Display
242
        CALL    Delay42us
243
 
244
        MOVLW   '!'
245
        MOVWF   LCD_data,access
246
        CALL    Display
247
        CALL    Delay42us
248
 
249
 
250
        ;--------------------
251
        MOVLW   0x53
252
        MOVWF   LCD_data,access
253
        CALL    Set_address
254
        CALL    Delay42us
255
 
256
        MOVLW   '<'
257
        MOVWF   LCD_data,access
258
        CALL    Display
259
        CALL    Delay42us
260
 
261
        MOVLW   '<'
262
        MOVWF   LCD_data,access
263
        CALL    Display
264
        CALL    Delay42us
265
 
266
        MOVLW   0x63
267
        MOVWF   LCD_data,access
268
        CALL    Set_address
269
        CALL    Delay42us
270
 
271
        MOVLW   '<'
272
        MOVWF   LCD_data,access
273
        CALL    Display
274
        CALL    Delay42us
275
 
276
        MOVLW   '<'
277
        MOVWF   LCD_data,access
278
        CALL    Display
279
        CALL    Delay42us
280
 
281
 
282
        ;----------------------
283
        ; ~ 2second delay
284
        MOVLW   0x22
285
        MOVWF   e4,access
286
 
287
loop21:
288
        CALL    Delay58ms
289
        DECFSZ  e4,1,access
290
        BRA loop21
291
 
292
        MOVLW   0x80
293
        MOVWF   LATB
294
 
295
looplooop:
296
        RLNCF   LATB,1,0
297
 
298
        MOVLW   SHIFT_D_L
299
        MOVWF   LCD_command,access
300
        CALL    Command
301
 
302
        MOVLW   0x0f
303
        ANDWF   PORTA,0,0
304
 
305
        MOVWF   e4,0
306
 
307
        INCF    e4,1,0
308
 
309
loop_3x58ms:
310
        CALL    Delay58ms
311
        ;CALL   Delay58ms
312
 
313
        DECF    e4,1,0
314
        TSTFSZ  e4,0
315
        BRA             loop_3x58ms
316
        BRA             looplooop
317
 
318
 
319
; Fuctions:
320
 
321
;---------------------------------
322
; Delay 42us *********************
323
Delay42us:
324
 
325
        ;save working registers
326
        movff   STATUS,STATUS_TEMP1
327
        movff   WREG,WREG_TEMP1
328
        movff   BSR,BSR_TEMP1
329
 
330
        MOVLW   0xAC
331
        MOVWF   e1,access
332
 
333
loop10:
334
        INCFSZ  e1,1,access
335
        BRA loop10
336
 
337
        ;restore working registers
338
        movff   BSR_TEMP1,BSR
339
        movff   WREG_TEMP1,WREG
340
        movff   STATUS_TEMP1,STATUS
341
 
342
        RETURN
343
;******** end Delay 40us **********
344
;----------------------------------
345
 
346
 
347
;---------------------------------
348
; Delay 1.6ms ********************
349
Delay1_6ms:
350
 
351
        ;save working registers
352
        movff   STATUS,STATUS_TEMP2
353
        movff   WREG,WREG_TEMP2
354
        movff   BSR,BSR_TEMP2
355
 
356
        MOVLW   0x25
357
        MOVWF   e2,access
358
 
359
loop3:
360
        CALL    Delay42us
361
        DECFSZ  e2,1,access
362
        BRA loop3
363
 
364
        ;restore working registers
365
        movff   BSR_TEMP2,BSR
366
        movff   WREG_TEMP2,WREG
367
        movff   STATUS_TEMP2,STATUS
368
 
369
        RETURN
370
;******** end Delay1.6ms **********
371
;----------------------------------
372
 
373
 
374
;---------------------------------
375
; Delay 58ms *********************
376
Delay58ms:
377
 
378
        ;save working registers
379
        movff   STATUS,STATUS_TEMP3
380
        movff   WREG,WREG_TEMP3
381
        movff   BSR,BSR_TEMP3
382
 
383
        MOVLW   0x24
384
        MOVWF   e3,access
385
 
386
loop4:
387
        CALL    Delay1_6ms
388
        DECFSZ  e3,1,access
389
        BRA loop4
390
 
391
        ;restore working registers
392
        movff   BSR_TEMP3,BSR
393
        movff   WREG_TEMP3,WREG
394
        movff   STATUS_TEMP3,STATUS
395
 
396
        RETURN
397
;******** end Delay 58ms **********
398
;----------------------------------
399
 
400
 
401
;----------------------------------
402
; send a command to the LCD *******
403
Command:
404
 
405
        ;save working registers
406
        movff   STATUS,STATUS_TEMP4
407
        movff   WREG,WREG_TEMP4
408
        movff   BSR,BSR_TEMP4
409
 
410
MOVFF LCD_command,LCD_DATA_PRT
411
BSF LCD_INST_PORT,E_PIN,0
412
NOP
413
NOP
414
NOP
415
BCF LCD_INST_PORT,E_PIN,0
416
SWAPF LCD_DATA_PORT,1,0
417
NOP
418
NOP
419
NOP
420
NOP
421
NOP
422
NOP
423
NOP
424
NOP
425
NOP
426
NOP
427
NOP
428
BSF LCD_INST_PORT,E_PIN,0
429
NOP
430
NOP
431
NOP
432
BCF LCD_INST_PORT,E_PIN,0
433
 
434
        ;restore working registers
435
        movff   BSR_TEMP4,BSR
436
        movff   WREG_TEMP4,WREG
437
        movff   STATUS_TEMP4,STATUS
438
 
439
RETURN
440
;****** end send command **********
441
;----------------------------------
442
 
443
 
444
;----------------------------------
445
; send data to the LCD ************
446
Display:
447
 
448
        ;save working registers
449
        movff   STATUS,STATUS_TEMP4
450
        movff   WREG,WREG_TEMP4
451
        movff   BSR,BSR_TEMP4
452
 
453
MOVFF LCD_data,LCD_DATA_PRT
454
BSF LCD_INST_PORT,RS_PIN,0
455
BSF LCD_INST_PORT,E_PIN,0
456
NOP
457
NOP
458
NOP
459
BCF LCD_INST_PORT,E_PIN,0
460
SWAPF LCD_DATA_PORT,1,0
461
NOP
462
NOP
463
NOP
464
NOP
465
NOP
466
NOP
467
NOP
468
NOP
469
NOP
470
NOP
471
NOP
472
BSF LCD_INST_PORT,E_PIN,0
473
NOP
474
NOP
475
NOP
476
BCF LCD_INST_PORT,E_PIN,0
477
BCF LCD_INST_PORT,RS_PIN,0
478
 
479
        ;restore working registers
480
        movff   BSR_TEMP4,BSR
481
        movff   WREG_TEMP4,WREG
482
        movff   STATUS_TEMP4,STATUS
483
 
484
RETURN
485
;******** end send data ***********
486
;----------------------------------
487
 
488
;----------------------------------
489
; Set an address to the LCD *******
490
Set_address:
491
 
492
        ;save working registers
493
        movff   STATUS,STATUS_TEMP4
494
        movff   WREG,WREG_TEMP4
495
        movff   BSR,BSR_TEMP4
496
 
497
MOVLW   0x80
498
IORWF   LCD_data,1,access
499
 
500
MOVFF LCD_data,LCD_DATA_PRT
501
BSF LCD_INST_PORT,E_PIN,0
502
NOP
503
NOP
504
NOP
505
BCF LCD_INST_PORT,E_PIN,0
506
SWAPF LCD_DATA_PORT,1,0
507
NOP
508
NOP
509
NOP
510
NOP
511
NOP
512
NOP
513
NOP
514
NOP
515
NOP
516
NOP
517
NOP
518
BSF LCD_INST_PORT,E_PIN,0
519
NOP
520
NOP
521
NOP
522
BCF LCD_INST_PORT,E_PIN,0
523
 
524
        ;restore working registers
525
        movff   BSR_TEMP4,BSR
526
        movff   WREG_TEMP4,WREG
527
        movff   STATUS_TEMP4,STATUS
528
 
529
RETURN
530
;******** end set address *********
531
;----------------------------------
532
 
533
 
534
;******************************************************************************
535
;End of program
536
 
537
                END

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.