1 | .include "m8def.inc"
|
2 |
|
3 | .def temp1 = r16
|
4 | .def temp2 = r17
|
5 | .def temp3 = r18
|
6 | .def temp4 = r19
|
7 |
|
8 | text:
|
9 | .db "Uss= ",0 ; Stringkonstante, durch eine 0 abgeschlossen
|
10 |
|
11 | text1:
|
12 | .db " ",0 ;soll im erste Zeile mit adresse 0x05
|
13 |
|
14 | text2:
|
15 | .db "Volt ",0 ;soll im erste Zeile mit adresse 0x0D
|
16 |
|
17 | text3: ;soll im erste Zeile mit adresse 0x40
|
18 | .db "P= ",0
|
19 |
|
20 | text4: ;soll im erste Zeile mit adresse 0x45
|
21 | .db " ",0
|
22 | text5: ;soll im erste Zeile mit adresse 0xaF
|
23 | .db "Watt ",0
|
24 |
|
25 |
|
26 | ldi temp1, LOW(RAMEND) ; LOW-Byte der obersten RAM-Adresse
|
27 | out SPL, temp1
|
28 | ldi temp1, HIGH(RAMEND) ; HIGH-Byte der obersten RAM-Adresse
|
29 | out SPH, temp1
|
30 |
|
31 | ldi temp1, 0xFF ;Port D = Ausgang
|
32 | out DDRD, temp1
|
33 |
|
34 | rcall lcd_init ;Display initialisieren
|
35 | rcall lcd_clear ;Display löschen
|
36 |
|
37 | start:
|
38 | ;ldi temp1,0x80 ; Set DDRAM Adress to 0x40
|
39 | ;rcall lcd_command
|
40 |
|
41 | ldi ZL, LOW(text*2) ; Adresse des Strings in den
|
42 | ldi ZH, HIGH(text*2) ; Z-Pointer laden
|
43 | rcall print
|
44 | rcall lcd_data ; Unterfunktion print aufrufen
|
45 |
|
46 | ;ldi R16, 10 ; die Bytes 10 und 13 senden
|
47 | ;rcall lcd_data ; (Zeilenumbruch im Terminal)
|
48 | ;ldi R16, 13
|
49 | ;rcall lcd_data
|
50 |
|
51 | ; das Ganze wiederholen
|
52 |
|
53 |
|
54 | ldi temp1,0x85 ; Set DDRAM Adress to 0x05
|
55 | rcall lcd_command
|
56 | ldi ZL, LOW (text1*2)
|
57 | ldi ZH, HIGH (text1*2)
|
58 | rcall print
|
59 | rcall lcd_data
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | ldi temp1,0x8c ; Set DDRAM Adress to 0x0d
|
65 | rcall lcd_command
|
66 | ldi ZL, LOW (text2*2)
|
67 | ldi ZH, HIGH (text2*2)
|
68 | rcall print
|
69 | rcall lcd_data
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | ldi temp1,0xc0 ; Set DDRAM Adress to 0x05
|
75 | rcall lcd_command
|
76 | ldi ZL, LOW (text3*2)
|
77 | ldi ZH, HIGH (text3*2)
|
78 | rcall print
|
79 | rcall lcd_data
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | ldi temp1,0xc3 ; Set DDRAM Adress to 0x45
|
85 | rcall lcd_command
|
86 | ldi ZL, LOW (text4*2)
|
87 | ldi ZH, HIGH (text4*2)
|
88 | rcall print
|
89 | rcall lcd_data
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | ldi temp1,0xcc ; Set DDRAM Adress to 0x4c
|
95 | rcall lcd_command
|
96 | ldi ZL, LOW (text5*2)
|
97 | ldi ZH, HIGH (text5*2)
|
98 | rcall print
|
99 | rcall lcd_data
|
100 |
|
101 | rjmp start
|
102 | ret
|
103 |
|
104 |
|
105 | ; print: sendet die durch den Z-Pointer adressierte Zeichenkette
|
106 | print:
|
107 | lpm ; Erstes Byte des Strings nach R0 lesen
|
108 | tst R0 ; R0 auf 0 testen
|
109 | breq print_end ; wenn 0, dann zu print_end
|
110 | mov r16, r0 ; Inhalt von R0 nach R16 kopieren
|
111 | rcall lcd_data ; UART-Sendefunktion aufrufen
|
112 | adiw ZL, 1 ; Adresse des Z-Pointers um 1 erhöhen
|
113 | rjmp print ; wieder zum Anfang springen
|
114 | print_end:
|
115 |
|
116 | ldi temp1, 0b00000011
|
117 | out ADMUX, temp1
|
118 | ldi temp1, 0b10001111
|
119 | out ADCSR, temp1
|
120 | sei
|
121 | sbi ADCSR, 6
|
122 |
|
123 | in R30, adcl
|
124 | in R31, adch
|
125 |
|
126 |
|
127 | ldi r22, -1 + '0'
|
128 | _bcd7: inc r22
|
129 | subi r30, low(1000) ;-1000
|
130 | sbci r31, high(1000)
|
131 | brcc _bcd7
|
132 |
|
133 | ldi r21, 10 + '0'
|
134 | _bcd8: dec r21
|
135 | subi r30, low(-100) ;+100
|
136 | sbci r31, high(-100)
|
137 | brcs _bcd8
|
138 |
|
139 | ldi r20, -1 + '0'
|
140 | _bcd9: inc r20
|
141 | subi r30, 10 ;-10
|
142 | brcc _bcd9
|
143 |
|
144 | subi r30, -10 - '0'
|
145 | mov r19, r30
|
146 |
|
147 | ldi temp1,0x85 ; Set DDRAM Adress to 0x05
|
148 | rcall lcd_command
|
149 |
|
150 | mov temp1,R19
|
151 | rcall lcd_data
|
152 |
|
153 | ldi temp1,0x86 ; Set DDRAM Adress to 0x05
|
154 | rcall lcd_command
|
155 |
|
156 | mov temp1,R20
|
157 | rcall lcd_data
|
158 |
|
159 | ldi temp1,0x87 ; Set DDRAM Adress to 0x05
|
160 | rcall lcd_command
|
161 |
|
162 | mov temp1, R21
|
163 | rcall lcd_data
|
164 |
|
165 | ldi temp1,0x88 ; Set DDRAM Adress to 0x05
|
166 | rcall lcd_command
|
167 |
|
168 | mov temp1, R22
|
169 | rcall lcd_data
|
170 |
|
171 | sbi ADCSR, 6
|
172 |
|
173 | ; ret
|
174 |
|
175 | ;ldi temp1,0xc0 ; Set DDRAM Adress to 0x40
|
176 | ;rcall lcd_command
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 | ;fin ici
|
183 |
|
184 | ;loop:
|
185 | ; rjmp loop
|
186 |
|
187 |
|
188 |
|
189 |
|
190 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
191 | ;; LCD-Routinen ;;
|
192 | ;; ============ ;;
|
193 | ;; ;;
|
194 | ;; ;;
|
195 | ;; 4bit-Interface ;;
|
196 | ;; DB4-DB7: PD0-PD3 ;;
|
197 | ;; RS: PD4 ;;
|
198 | ;; E: PD5 ;;
|
199 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
200 |
|
201 | ;.include "lcd-routines.asm" ;LCD-Routinen werden hier eingefügt
|
202 |
|
203 | ;sendet ein Datenbyte an das LCD
|
204 | lcd_data:
|
205 | mov temp2, temp1 ;"Sicherungskopie" für
|
206 | ;die Übertragung des 2.Nibbles
|
207 | swap temp1 ;Vertauschen
|
208 | andi temp1, 0b00001111 ;oberes Nibble auf Null setzen
|
209 | sbr temp1, 1<<4 ;entspricht 0b00010000
|
210 | out PORTD, temp1 ;ausgeben
|
211 | rcall lcd_enable ;Enable-Routine aufrufen
|
212 | ;2. Nibble, kein swap da es schon
|
213 | ;an der richtigen stelle ist
|
214 | andi temp2, 0b00001111 ;obere Hälfte auf Null setzen
|
215 | sbr temp2, 1<<4 ;entspricht 0b00010000
|
216 | out PORTD, temp2 ;ausgeben
|
217 | rcall lcd_enable ;Enable-Routine aufrufen
|
218 | rcall delay50us ;Delay-Routine aufrufen
|
219 | ret ;zurück zum Hauptprogramm
|
220 |
|
221 | ;sendet einen Befehl an das LCD
|
222 | lcd_command: ;wie lcd_data, nur ohne RS zu setzen
|
223 | mov temp2, temp1
|
224 | swap temp1
|
225 | andi temp1, 0b00001111
|
226 | out PORTD, temp1
|
227 | rcall lcd_enable
|
228 | andi temp2, 0b00001111
|
229 | out PORTD, temp2
|
230 | rcall lcd_enable
|
231 | rcall delay50us
|
232 | ret
|
233 |
|
234 | ;erzeugt den Enable-Puls
|
235 | lcd_enable:
|
236 | sbi PORTD, 5 ;Enable high
|
237 | nop ;3 Taktzyklen warten
|
238 | nop
|
239 | nop
|
240 | cbi PORTD, 5 ;Enable wieder low
|
241 | ret ;Und wieder zurück
|
242 |
|
243 | ;Pause nach jeder Übertragung
|
244 | delay50us: ;50us Pause
|
245 | ldi temp1, $42
|
246 | delay50us_:dec temp1
|
247 | brne delay50us_
|
248 | ret ;wieder zurück
|
249 |
|
250 | ;Längere Pause für manche Befehle
|
251 | delay5ms: ;5ms Pause
|
252 | ldi temp1, $21
|
253 | WGLOOP0: ldi temp2, $C9
|
254 | WGLOOP1: dec temp2
|
255 | brne WGLOOP1
|
256 | dec temp1
|
257 | brne WGLOOP0
|
258 | ret ;wieder zurück
|
259 |
|
260 | ;Initialisierung: muss ganz am Anfang des Programms aufgerufen werden
|
261 | lcd_init:
|
262 | ldi temp3,50
|
263 | powerupwait:
|
264 | rcall delay5ms
|
265 | dec temp3
|
266 | brne powerupwait
|
267 | ldi temp1, 0b00000011 ;muss 3mal hintereinander gesendet
|
268 | out PORTD, temp1 ;werden zur Initialisierung
|
269 | rcall lcd_enable ;1
|
270 | rcall delay5ms
|
271 | rcall lcd_enable ;2
|
272 | rcall delay5ms
|
273 | rcall lcd_enable ;und 3!
|
274 | rcall delay5ms
|
275 | ldi temp1, 0b00000010 ;4bit-Modus einstellen
|
276 | out PORTD, temp1
|
277 | rcall lcd_enable
|
278 | rcall delay5ms
|
279 | ldi temp1, 0b00000100
|
280 | rcall lcd_command
|
281 | ldi temp1, 0b00101000 ;noch was einstellen...
|
282 | rcall lcd_command
|
283 | ldi temp1, 0b00001100 ;...nochwas...
|
284 | rcall lcd_command
|
285 | ldi temp1, 0b00000100 ;endlich fertig
|
286 | rcall lcd_command
|
287 | ret
|
288 |
|
289 | ;Sendet den Befehl zur Löschung des Displays
|
290 | lcd_clear:
|
291 | ldi temp1, 0b00000001 ;Display löschen
|
292 | rcall lcd_command
|
293 | rcall delay5ms
|
294 | ret
|