Forum: Mikrocontroller und Digitale Elektronik PIC 16F628 LCD-Display


von Michael K. (Firma: Otto-Hahn-Gymnasium) (micha2420)


Lesenswert?

Hallo,

ich habe das SPRUT-Programm LCD-Display verwendet, geht super. Ich 
benötige aber den PIN PORTB.0 für ext. Interrupt (Zähler).
Nun wollte ich den frei machen und Enable des Displays einfach auf 
PORTB.1 ändern. Das Programm geht dann aber nicht mehr. Das Display wird 
nicht einmal mehr initialisiert.
Kann mir jemand helfen und mal drüber schauen?
1
  list p=16f628
2
;**************************************************************
3
;*    Pinbelegung
4
;*  ----------------------------------  
5
;*  PORTA:   0 - 
6
;*    1 -
7
;*    2 -  
8
;*    3 -
9
;*    4 -
10
;*  PORTB:  0 
11
;*    1 LCD Display E neu sonst auf 0    
12
;*    2 LCD Display RS
13
;*    3 LCD Display R/W  
14
;*    4-7 LCD Display D4 .. D7 
15
;*  
16
;**************************************************************
17
;
18
;sprut (zero) Bredendiek 05/2000 (mod. 15.01.2002)
19
;
20
; LCD-Display mit Matrixtastatur
21
;
22
; Taktquelle: 4 MHz
23
;
24
;**************************************************************
25
26
27
  #include <P16f628.INC>
28
29
; Configuration festlegen
30
; bis 4 MHz: Power on Timer, kein Watchdog, XT-Oscillator
31
32
  __CONFIG  _PWRTE_ON & _WDT_OFF & _XT_OSC
33
34
;**************************************************************
35
; Variablen festlegen
36
37
w_copy  Equ  0x20
38
s_copy  Equ  0x21
39
LcdDaten  Equ  0x22
40
LcdStatus Equ  0x23
41
loops  EQU  0x24
42
loops2  EQU  0x25
43
44
; Constanten festlegen
45
46
PORTC  equ  PORTB    ; LCD-Control-Port
47
PORTD  equ  PORTB    ; LCD-Daten-Port
48
LcdE  equ  1    ; enable Lcd
49
LcdRw  equ  3    ; read Lcd
50
LcdRs  equ  2    ; Daten Lcd (nicht control)  
51
Ini_con Equ  B'00000000'  ; TMR0 -> Intetupt disable
52
Ini_opt  Equ  B'00000010'  ; pull-up
53
54
;********************************************************
55
; Das Programm beginnt mit der Initialisierung
56
57
Init  bsf     STATUS, RP0  ; Bank 1
58
  movlw   Ini_opt       ; pull-up on
59
  movwf   OPTION_REG 
60
  movlw  B'11111000'  ; RA0 .. RA2 outputs, RA3, RA4 input 
61
  movwf  TRISA    ; 
62
  movlw  B'00000000'  ; PortB alle outputs 
63
  movwf  TRISB
64
  bcf     STATUS, RP0  ; Bank 0
65
  clrf  PORTA    
66
  clrf  PORTB    
67
        
68
  movlw   Ini_con       ; Interupt disable
69
  movwf   INTCON   
70
71
  call  InitLCD    ; Display initialisieren
72
73
; am LCD "Hallo" ausgeben
74
  
75
  movlw  'H'
76
  movwf  LcdDaten
77
  call  OutLcdDaten
78
  movlw  'a'
79
  movwf  LcdDaten
80
  call  OutLcdDaten
81
  movlw  'l'
82
  movwf  LcdDaten
83
  call  OutLcdDaten
84
  movlw  'l'
85
  movwf  LcdDaten
86
  call  OutLcdDaten
87
  movlw  'o'
88
  movwf  LcdDaten
89
  call  OutLcdDaten
90
91
  sleep
92
Main        
93
  goto   Main  
94
95
;*****************************************************************  
96
;Zeitverzögerung um loops * 1 ms
97
; 4MHz externer Takt bedeutet 1MHz interner Takt
98
; also dauert 1 ms genau 1000 Befehle
99
; 110 Schleifen a 9 Befehle sind 990 Befehle = 0.99 ms
100
; die restlichen 10 Befehle für Einsprung und Rücksprung
101
102
WAIT
103
top      movlw   .110           ; timing adjustment variable (1ms)
104
         movwf   loops2
105
top2     nop                    ; sit and wait
106
         nop
107
         nop
108
         nop
109
         nop
110
         nop
111
         decfsz  loops2, F      ; inner loops complete?
112
         goto    top2           ; no, go again
113
                                ;
114
         decfsz  loops, F       ; outer loops complete?
115
         goto    top            ; no, go again
116
         retlw   0              ; yes, return from subWAIT
117
118
;**********************************************************  
119
; Initialisierung des LCD-Displays
120
121
InitLCD
122
  movlw  D'255'    ; 250 ms Pause nach dem Einschalten
123
  movwf  loops  
124
  call  WAIT    
125
126
  movlw  B'00110000'  ; 1
127
  movwf  PORTB
128
  bsf  PORTB, LcdE
129
  nop  
130
  bcf  PORTB, LcdE
131
  
132
  movlw  D'50'    ; 50 ms Pause
133
  movwf  loops
134
  call  WAIT
135
  
136
  movlw  B'00110000'  ; 2
137
  call  Control8Bit
138
  movlw  B'00110000'  ; 3
139
  call   Control8Bit
140
  movlw  B'00100000'  ; 4
141
  call   Control8Bit
142
143
  movlw  B'00000001'  ; löschen und cusor home
144
  call  OutLcdControl  
145
  movlw  B'00101000'  ; 5 function set, 4-bit  2-zeilig,  5x7
146
  call  OutLcdControl  
147
  movlw  B'00001000'  ; 6 display off
148
  call  OutLcdControl
149
  movlw  B'00000110'  ; 7 entry mode, increment, disable display-shift
150
  call  OutLcdControl
151
  movlw  B'00000011'  ; 8 cursor home, cursor home
152
  call  OutLcdControl
153
  movlw  B'00001111'  ; 9 display on
154
  call  OutLcdControl
155
  return
156
157
; ein Steuerbyte 8-bittig übertragen
158
Control8Bit
159
  movwf  PORTB
160
  bsf  PORTB, LcdE
161
  nop
162
  bcf  PORTB, LcdE
163
  movlw  D'10'
164
  movwf  loops
165
  call   WAIT
166
  return
167
168
; darauf warten, daß das Display bereit zur Datenannahme ist
169
LcdBusy
170
  bsf  PORTA, 1  ; Test LED 1 on
171
        bsf     STATUS, RP0  ; make Port B4..7 input
172
  movlw  B'11110000'
173
  iorwf   TRISB, f 
174
        bcf     STATUS, RP0
175
BusyLoop    
176
  bcf  PORTC, LcdRs
177
  bsf  PORTC, LcdRw  ; Lesen
178
  bsf  PORTC, LcdE
179
  nop
180
  movf  PORTD, w
181
  movwf  LcdStatus
182
  bcf  PORTC, LcdE
183
  nop
184
  bsf  PORTC, LcdE  ; Enable
185
  nop
186
  bcf  PORTC, LcdE
187
  btfsc  LcdStatus, 7  ; teste bit 7
188
  goto  BusyLoop
189
  bcf  PORTC, LcdRw
190
        bsf     STATUS, RP0  ; make Port B4..7 output
191
  movlw  B'00001111'
192
  andwf   TRISB, f    
193
        bcf     STATUS, RP0
194
  bcf  PORTA, 1  ; Test LED 1 off
195
  return  
196
197
; ein Byte mit Steuerdaten von LcdDaten zum Display übertragen
198
OutLcdControl
199
  movwf  LcdDaten
200
  call  LcdBusy
201
  movf  LcdDaten, w
202
  andlw  H'F0'
203
  movwf  PORTD    ; Hi-teil Daten schreiben
204
  bsf  PORTC, LcdE
205
  nop
206
  bcf  PORTC, LcdE  ; Disable LcdBus
207
  swapf  LcdDaten, w
208
  andlw  H'F0'
209
  movwf  PORTD    ; Lo-teil Daten schreiben
210
  bsf  PORTC, LcdE
211
  nop
212
  bcf  PORTC, LcdE  ; Disable LcdBus
213
  return
214
215
; ein Datenbyte von LCDDaten zum Display übertragen
216
OutLcdDaten
217
  bsf  PORTA, 2  ; Test LED 2 on
218
  movwf  LcdDaten
219
  call  LcdBusy
220
  movf  LcdDaten, w
221
  andlw  H'F0'
222
  movwf  PORTD    ; Hi-teil Daten schreiben
223
  bsf  PORTC, LcdRs  ; Daten
224
  bsf  PORTC, LcdE  ; Enable LcdBus
225
  nop
226
  bcf  PORTC, LcdE  ; Disable LcdBus  
227
  swapf  LcdDaten, w
228
  andlw  H'F0'
229
  movwf  PORTD    ; Lo-teil Daten schreiben
230
  bsf  PORTC, LcdRs  ; Daten
231
  bsf  PORTC, LcdE
232
  nop
233
  bcf  PORTC, LcdE  ; Disable LcdBus  
234
  bcf  PORTC, LcdRs  ;
235
  bcf  PORTA, 2  ; Test LED 2 on
236
  return
237
238
  end

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.