~rmyeid/+junk/manual

« back to all changes in this revision

Viewing changes to cocktail/LCD_pic16f877/project.asm

  • Committer: rami
  • Date: 2009-09-19 15:02:55 UTC
  • Revision ID: rami@rami-desktop-20090919150255-2gzw3a8iw1ldjzik
first after splitting latex

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "P16F877A.inc"
2
 
 
3
 
;pins of port E
4
 
RS      EQU     0
5
 
RW      EQU     1
6
 
E       EQU     2
7
 
temp    EQU     0x20    ;temp variable
8
 
 
9
 
 
10
 
org 0
11
 
goto main
12
 
 
13
 
org 04
14
 
goto interrupt
15
 
 
16
 
main
17
 
        CLRWDT          ;clear the watch dog timer
18
 
                                ;watch dog timer restart the program if it overflowed
19
 
        call init_port_d_output
20
 
        banksel PORTD
21
 
        movlw   0x78
22
 
        movwf   PORTD
23
 
        ;call longdelay
24
 
        ;call init_port_e
25
 
        ;call init_LCD
26
 
        ;call clear_LCD
27
 
        ;call home_LCD
28
 
        ;call write_string0
29
 
submain
30
 
        CLRWDT
31
 
        goto submain
32
 
 
33
 
 
34
 
init_port_e
35
 
;The first three pins as output
36
 
;RE0 ---> RS
37
 
;RE1 ---> RW
38
 
;RE2 ---> E
39
 
        banksel ADCON1
40
 
 
41
 
        movlw   b'00001111'     ;Digital mode for port E
42
 
        movwf   ADCON1          ;read page 114 of the datasheet
43
 
 
44
 
        bcf TRISE,RS            ;initialize pin0 to output
45
 
        bcf     TRISE,RW                ;initialize pin1 to output
46
 
        bcf TRISE,E             ;initialize pin2 to output
47
 
        return 
48
 
init_port_d_output
49
 
;PORTD will be used as an input to the LCD data bus
50
 
;RD0-7 ---> D0-7
51
 
        bsf STATUS,5    ;choose bank 01
52
 
        bcf STATUS,6    ;RP0,RP1 from status =01m
53
 
 
54
 
        movlw 0x00
55
 
        movwf TRISD
56
 
        return
57
 
 
58
 
init_port_d_input
59
 
;PORTD will be used as an input to read the LCD status
60
 
;RD0-7 ---> D0-7
61
 
        banksel TRISD
62
 
        movlw 0xFF              ;make PORTD as input
63
 
        movwf TRISD
64
 
        return
65
 
 
66
 
clear_LCD
67
 
        call init_port_d_output
68
 
        call busy_LCD   ;check if the LCD busy
69
 
                                        ; BLOCKing Call 
70
 
        banksel PORTE
71
 
        
72
 
        bcf PORTE,RS            ;RS-->0
73
 
        bcf PORTE,RW            ;R/W -->0
74
 
 
75
 
        banksel PORTD
76
 
        movlw   0x01
77
 
        movwf   PORTD
78
 
        call    pulse_E
79
 
        return
80
 
 
81
 
busy_LCD
82
 
;check if the LCD is busy
83
 
        call init_port_d_input  ; to read the LCD status
84
 
                                                        ; PORTD ---> Input
85
 
        banksel PORTE
86
 
        bcf     PORTE,RS
87
 
        bsf     PORTE,RW
88
 
        
89
 
        banksel PORTD
90
 
busy
91
 
        movf    PORTD,W                 ;flag busy ?
92
 
        call pulse_E
93
 
        btfss   W,7
94
 
        return
95
 
        goto busy
96
 
        return
97
 
 
98
 
putchar_LCD
99
 
;send a char to the LCD
100
 
;the char must be stored in working register
101
 
        bcf             STATUS,5        ;bank 0
102
 
        bcf             STATUS,6
103
 
        movwf   temp    ;moving the WREG contents to a temp variable
104
 
                                        ;WREG will be overwritten
105
 
        call busy_LCD   ;check if the LCD busy
106
 
                                        ; BLOCKing Call
107
 
        call init_port_d_output
108
 
        
109
 
        bsf             PORTE,RS        ;control signals
110
 
        bcf             PORTE,RW
111
 
 
112
 
        banksel PORTD
113
 
 
114
 
        movf    temp,W  ;sending the stored character to PORTD
115
 
        movwf   PORTD
116
 
        call    pulse_E
117
 
        return 
118
 
 
119
 
write_string0
120
 
 
121
 
        movlw   'h'
122
 
        call putchar_LCD
123
 
        movlw   'e'
124
 
        call putchar_LCD
125
 
        movlw   'l'
126
 
        call putchar_LCD
127
 
        movlw   'l'
128
 
        call putchar_LCD
129
 
        movlw   'o'
130
 
        call putchar_LCD
131
 
        movlw   'W'
132
 
        call putchar_LCD
133
 
        movlw   'o'
134
 
        call putchar_LCD
135
 
        movlw   'r'
136
 
        call putchar_LCD
137
 
        movlw   'l'
138
 
        call putchar_LCD
139
 
        movlw   'd'
140
 
        call putchar_LCD
141
 
 
142
 
        return
143
 
 
144
 
home_LCD
145
 
        call    init_port_d_output
146
 
        
147
 
        banksel PORTE
148
 
        bcf     PORTE,RS
149
 
        bcf             PORTE,RW
150
 
        
151
 
        movlw   0x02
152
 
        movwf   PORTD
153
 
        return
154
 
 
155
 
init_LCD
156
 
        call init_port_d_output
157
 
 
158
 
        banksel PORTE
159
 
        bcf     PORTE,RS
160
 
        bcf     PORTE,RW
161
 
        ;Function Set
162
 
        banksel PORTD
163
 
        movlw   b'00111100' ;b3=1-> 2-line mode
164
 
                                                ;b2=1-> Display on
165
 
        movwf   PORTD 
166
 
        call    pulse_E
167
 
        
168
 
        
169
 
        ;Display features
170
 
        banksel PORTD
171
 
        movlw   b'00001111' ;b2=1-> Display on
172
 
                                                ;b1=1-> cursor on
173
 
                                                ;b0=1-> blink on
174
 
        movwf   PORTD
175
 
        call pulse_E
176
 
 
177
 
        call clear_LCD
178
 
        
179
 
        ;Entry mode set
180
 
        banksel PORTD
181
 
        movlw   b'00000111' ;b1=1-> increment on
182
 
                                                ;b0=1-> shift on
183
 
        movwf   PORTD
184
 
        call pulse_E
185
 
        return
186
 
 
187
 
pulse_E
188
 
                banksel PORTE
189
 
                bsf   PORTE,E
190
 
        nop
191
 
        bcf   PORTE,E
192
 
        return
193
 
 
194
 
longdelay
195
 
        call   shortdelay
196
 
        decfsz 0F,f
197
 
        goto   longdelay
198
 
        return
199
 
                
200
 
shortdelay
201
 
        decfsz 0E,f
202
 
        goto   shortdelay
203
 
        return
204
 
 
205
 
interrupt
206
 
 
207
 
 
208
 
END
 
 
b'\\ No newline at end of file'