1 | ; PortA free
|
2 | ;
|
3 | ;R/S = register select line
|
4 | ;R/S = 0 ensures that the data to the display will change the registers
|
5 | ;R/S = 1 writes the charakters to the display ;
|
6 | ; PortE Bit0: RS
|
7 | ; Bit1: RW ;
|
8 | ; Bit2: E ;
|
9 | ; PORTB Bit0-3: 4Bit datenleitungen ; ;
|
10 | ; Bit6: incircuit programming ;
|
11 | ; Bit7: incircuit programming ;
|
12 | ; ;
|
13 | ; PortC Bit 0-7: Keypad ;
|
14 | ; ;
|
15 | ; PortD Bit 0-7: LED ;
|
16 | ;
|
17 |
|
18 | #include <p16F887.inc>
|
19 | __CONFIG _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
|
20 | __CONFIG _CONFIG2, _WRT_OFF & _BOR21V
|
21 |
|
22 |
|
23 |
|
24 | ; Variablen festlegen
|
25 | STATUS Equ 0x03
|
26 | PORTA Equ 0x05
|
27 | PORTB Equ 0x06
|
28 | PORTC Equ 0x07
|
29 | PORTD Equ 0x08
|
30 | PORTE Equ 0x09
|
31 | INTCON Equ 0x0B
|
32 | OPTION_REG EQU 0x81
|
33 | TRISA Equ 0x85
|
34 | TRISB Equ 0x86
|
35 | TRISC Equ 0x87
|
36 | TRISD Equ 0x88
|
37 | TRISE EQU 0x89
|
38 | ANSEL Equ 0x188
|
39 | ANSELH Equ 0x189
|
40 | w_copy Equ 0x20
|
41 | s_copy Equ 0x21
|
42 | LcdDaten Equ 0x22
|
43 | LcdStatus Equ 0x23
|
44 | loops EQU 0x24
|
45 | loops2 EQU 0x25
|
46 |
|
47 | ; Constanten festlegen
|
48 | RP0 equ 5
|
49 | RP1 equ 6
|
50 | LcdE equ 2 ; enable Lcd
|
51 | LcdRw equ 1 ; read Lcd
|
52 | LcdRs equ 0 ; Daten Lcd (nicht control)
|
53 | Ini_con Equ B'00000000' ; TMR0 -> Intetupt disable
|
54 | Ini_opt Equ B'00000010' ; pull-up
|
55 |
|
56 | ;********************************************************
|
57 | ; Das Programm beginnt mit der Initialisierung
|
58 |
|
59 | Init bsf STATUS, RP0 ; Bank 1
|
60 | movlw Ini_opt ; pull-up on
|
61 | movwf OPTION_REG
|
62 | movlw B'11111000' ; RA0 .. RA2 outputs, RA3, RA4 input
|
63 | movwf TRISA ;
|
64 | movlw B'00000000' ; PortB alle outputs
|
65 | movwf TRISB
|
66 | movwf TRISC
|
67 | movwf TRISD
|
68 | movwf TRISE
|
69 | BSF STATUS, RP1 ; Bank 4
|
70 | movlw B'00000000' ; all PORTS are digital
|
71 | movwf ANSEL
|
72 | movwf ANSELH
|
73 | bcf STATUS, RP1
|
74 | bcf STATUS, RP0 ; Bank 0
|
75 | clrf PORTE
|
76 | clrf PORTB
|
77 | clrf PORTD
|
78 | CLRF PORTC
|
79 |
|
80 | movlw Ini_con ; Interupt disable
|
81 | movwf INTCON
|
82 |
|
83 | call InitLCD ; Display initialisieren
|
84 |
|
85 | ; am LCD "Hallo" ausgeben
|
86 |
|
87 | movlw 'H'
|
88 | movwf LcdDaten
|
89 | call OutLcdDaten
|
90 | movlw 'a'
|
91 | movwf LcdDaten
|
92 | call OutLcdDaten
|
93 | movlw 'l'
|
94 | movwf LcdDaten
|
95 | call OutLcdDaten
|
96 | movlw 'l'
|
97 | movwf LcdDaten
|
98 | call OutLcdDaten
|
99 | movlw 'o'
|
100 | movwf LcdDaten
|
101 | call OutLcdDaten
|
102 |
|
103 | sleep
|
104 |
|
105 |
|
106 | ;*****************************************************************
|
107 | ;Zeitverzögerung um loops *
|
108 | WAIT
|
109 | top movlw .250 ; timing adjustment variable (1ms)
|
110 | movwf loops2
|
111 | top2 nop ; sit and wait
|
112 | nop
|
113 | nop
|
114 | nop
|
115 | nop
|
116 | nop
|
117 | decfsz loops2, F ; inner loops complete?
|
118 | goto top2 ; no, go again
|
119 | ;
|
120 | decfsz loops, F ; outer loops complete?
|
121 | goto top ; no, go again
|
122 | retlw 0 ; yes, return from subWAIT
|
123 |
|
124 | ;**********************************************************
|
125 | ; Initialisierung des LCD-Displays
|
126 |
|
127 | InitLCD
|
128 | movlw D'255' ; Pause nach dem Einschalten
|
129 | movwf loops
|
130 | call WAIT
|
131 |
|
132 | movlw B'00000010' ; 1
|
133 | movwf PORTB
|
134 | bsf PORTE, LcdE
|
135 | nop
|
136 | bcf PORTE, LcdE
|
137 |
|
138 | movlw D'120' ;
|
139 | movwf loops
|
140 | call WAIT
|
141 |
|
142 | movlw B'00000010' ; 2
|
143 | call Control8Bit
|
144 |
|
145 |
|
146 | movlw B'00001111' ; 3 display on, cursor on, cursor flash
|
147 | call OutLcdControl
|
148 | movlw B'00000001' ; 4 delate display, cursor on pos 1
|
149 | call OutLcdControl
|
150 | movlw B'00000110' ; 5 Cursor Auto increment
|
151 | call OutLcdControl
|
152 |
|
153 |
|
154 | ; ein Steuerbyte 8-bittig übertragen
|
155 | Control8Bit
|
156 | movwf PORTB
|
157 | bsf PORTE, LcdE
|
158 | nop
|
159 | bcf PORTE, LcdE
|
160 | movlw D'100'
|
161 | movwf loops
|
162 | call WAIT
|
163 | return
|
164 |
|
165 |
|
166 | ; ein Byte mit Steuerdaten von LcdDaten zum Display übertragen
|
167 | OutLcdControl
|
168 | movwf LcdDaten
|
169 | movlw D'100' ;sicherstellen das LCD fertig
|
170 | movwf loops
|
171 | call WAIT
|
172 | swapf LcdDaten, w
|
173 | andlw H'0F'
|
174 | movwf PORTB ; Hi-teil Daten schreiben
|
175 | bsf PORTE, LcdE
|
176 | nop
|
177 | bcf PORTE, LcdE ; Disable LcdBus
|
178 | movf LcdDaten, w
|
179 | andlw H'0F'
|
180 | movwf PORTB ; Lo-teil Daten schreiben
|
181 | bsf PORTE, LcdE
|
182 | nop
|
183 | bcf PORTE, LcdE ; Disable LcdBus
|
184 | return
|
185 |
|
186 | ; ein Datenbyte von LCDDaten zum Display übertragen
|
187 | OutLcdDaten
|
188 | bsf PORTD, 2 ; Test LED 2 on
|
189 | movwf LcdDaten
|
190 | movlw D'120'
|
191 | movwf loops
|
192 | call WAIT
|
193 | swapf LcdDaten, w
|
194 | andlw H'0F'
|
195 | movwf PORTB ; Hi-teil Daten schreiben
|
196 | bsf PORTE, LcdRs ; Daten
|
197 | bsf PORTE, LcdE ; Enable LcdBus
|
198 | nop
|
199 | bcf PORTE, LcdE ; Disable LcdBus
|
200 | swapf LcdDaten, w
|
201 | andlw H'0F'
|
202 | movwf PORTB ; Lo-teil Daten schreiben
|
203 | bsf PORTE, LcdRs ; Daten
|
204 | bsf PORTE, LcdE
|
205 | nop
|
206 | bcf PORTE, LcdE ; Disable LcdBus
|
207 | bcf PORTE, LcdRs ;
|
208 | bcf PORTD, 2 ; Test LED 2 on
|
209 | return
|
210 |
|
211 | end
|