final_countdown.asm


1
.include "8535def.inc"
2
3
4
RJMP reset
5
RETI
6
RETI
7
RETI
8
RETI
9
RETI
10
RETI
11
RETI
12
RETI
13
RJMP start
14
RETI
15
RETI
16
RETI
17
RETI
18
RETI
19
RETI
20
RETI
21
22
23
24
.def temp1  =  r16
25
.def temp2  =  r17
26
.def temp3  =  r18
27
.def loop1  =  r19
28
.def loop2  =  r20
29
.def ztau   =   r1  
30
.def taus   =   r2
31
.def hund   =   r3
32
.def zehn   =  r4
33
.def ein   =   r5      
34
.def konst  =   r21
35
36
37
.equ temp_lsb   =  0x060
38
.equ temp_msb  =  0x061  
39
.equ th_reg    =   0x062
40
.equ tl_reg    =  0x063
41
.equ res1    =  0x064  
42
.equ res2    =  0x065    
43
.equ count_re  =  0x066
44
.equ count_pc  =  0x067
45
.equ crc    =  0x068
46
47
48
reset:  
49
    clr temp1
50
    clr temp2
51
    clr temp3
52
    clr loop1
53
    clr loop2
54
55
    sts temp_lsb, temp1
56
    sts temp_msb, temp1
57
    sts th_reg  , temp1
58
    sts tl_reg  , temp1
59
    sts res1  , temp1
60
    sts res2  , temp1
61
    sts count_re, temp1
62
    sts count_pc, temp1
63
    sts crc   , temp1
64
65
    ldi temp1, low(ramend)
66
    out spl, temp1
67
    ldi temp1, high(ramend)
68
    out sph, temp1
69
70
  
71
    ldi temp1, 0xFF
72
    out ddrc, temp1
73
74
    rcall lcd_init
75
    rcall lcd_clear
76
77
    rcall timerinit
78
    sei
79
;------------------------------------------------------------------------------
80
warten: rjmp warten
81
82
ausgabe:                ; alle sekunden
83
    inc r23
84
    cpi r23,4            ; alle 4 sekunden abfragen
85
    breq main
86
    ret
87
88
main:   rcall init    
89
    rcall skip_rom
90
    rcall convert_t
91
    rcall init
92
    rcall skip_rom
93
    rcall read_scratchpad
94
    rcall init
95
  
96
    
97
weiter:                  ; schauen ob plus oder minus
98
    lds temp3, temp_msb
99
    sbrs temp3, 0
100
    rjmp plus
101
102
    ldi temp1, 0b10000001      ; minus
103
    rcall lcd_command_1
104
    ldi temp1, 45
105
    rcall lcd_data_1
106
    rjmp weiter1
107
108
plus:  ldi temp1, 0b10000001      ;plus
109
    rcall lcd_command_1
110
    ldi temp1, 43
111
    rcall lcd_data_1
112
    rjmp weiter1
113
114
weiter1:
115
    lds temp3, temp_lsb        ; ,5 ja nein
116
    sbrs temp3,0
117
    rjmp nein
118
    
119
    ldi temp1, 0b10000101
120
    rcall lcd_command_1
121
    ldi temp1, 44
122
    rcall lcd_data_1
123
    ldi temp1, 53
124
    rcall lcd_data_1
125
    rjmp weiter2
126
127
nein:   ldi temp1, 0b10000101      ; ,0
128
    rcall lcd_command_1
129
    ldi temp1, 44
130
    rcall lcd_data_1
131
    ldi temp1, 48
132
    rcall lcd_data_1
133
    rjmp weiter2
134
135
weiter2: 
136
    ror temp3            ; rechtsrollen
137
    mov xl, temp3
138
    ldi xh, 0x00
139
140
    rcall bin2ascii
141
142
    ldi temp1, 0b10000011
143
    rcall lcd_command_1
144
145
    mov temp1,r4
146
    rcall lcd_data_1
147
    mov temp1,r5
148
    rcall lcd_data_1
149
150
    ldi temp1, 0b10001000
151
    rcall lcd_command_1
152
      
153
    ldi temp1, 223          ; °
154
    rcall lcd_data_1
155
156
    ldi temp1, 'C'          ; C
157
    rcall lcd_data_1
158
159
    ret
160
161
;------------------------------------------------------------------------------
162
163
init:  sbi ddrb, 0            ;pb0 ausgang
164
    cbi portb, 0          ;signal auf low ziehen    
165
    rcall wait500us          ;und 500us halten
166
    
167
    cbi ddrb,0
168
    rcall wait70us          ;wartet dazu 70us
169
  
170
    wait_presence_pulse:
171
    sbic pinb,0
172
    rjmp wait_presence_pulse
173
174
    rcall wait410us          ;410us warten
175
        
176
  
177
178
    ret
179
180
;------------------------------------------------------------------------------
181
182
write_1:
183
    sbi ddrb, 0            ;pb0 ausgang
184
    cbi portb, 0          ;signal auf low ziehen        
185
      
186
    rcall wait6us          ;und 6us halten
187
      
188
    cbi ddrb, 0            ;lässt bus los
189
    rcall wait65us          ;wartet dazu 65us
190
191
    ret
192
193
194
;-----------------------------------------------------------------------------
195
196
197
write_0:sbi ddrb, 0            ;pb0 ausgang            
198
    cbi portb, 0          ;signal auf low ziehen
199
  
200
    rcall wait60us          ;und 60us halten
201
202
    cbi ddrb, 0            ;lässt bus los
203
    rcall wait10us          ;wartet dazu 10us
204
        
205
    ret
206
207
208
;-----------------------------------------------------------------------------
209
210
211
read_bit:
212
    clr temp3            ;löschen
213
    ldi temp1, 8          ;für 8mal durchführen (8bit)
214
215
  read_bit1:
216
      
217
    ror temp3            ;rechts rollen
218
    cbi portb, 0          ;signal auf low ziehen
219
    sbi ddrb,0            ;pb0 ausgang
220
    rcall wait6us          ;und 6us halten
221
222
    cbi ddrb, 0            ;lässt bus los  
223
    rcall wait9us          ;wartet dazu 9us
224
225
    sbis pinb,0            ;prüfen ob null anliegt
226
    rjmp read_bit2          ;wenn 0 dann springen
227
      
228
    ldi temp2, 128          ;10000000 laden
229
    add temp3, temp2        ;und zu temp3 addieren
230
    
231
  read_bit2:  
232
      
233
    rcall wait55us          ;wartet 55us
234
    dec temp1            ;temp1 erniedigen
235
    brne read_bit1          ;von vorne bis temp1=0
236
      
237
    ret
238
239
240
;-----------------------------------------------------------------------------
241
242
243
write_command:
244
        
245
    ldi temp1, 8          ; für 8 mal durchführen (8bit)    
246
  
247
  write_command1:
248
  
249
    sbrs r10, 0            ;prüfen ob 0
250
    rcall write_0          ;wenn ja dann 0 schreiben
251
252
    sbrc r10, 0            ;prüfen ob 1
253
    rcall write_1          ;wenn ja dann 1 schreiben
254
255
    ror r10              ;rollen
256
    dec temp1            ;um eins erniedrigen
257
    brne write_command1        ;von vorne bis temp1=0
258
259
    ret
260
261
;-----------------------------------------------------------------------------
262
263
264
skip_rom:
265
      
266
    ldi temp1, 0xCC          ;befehl für skip rom
267
    mov r10, temp1          
268
    rcall write_command        ;schicken
269
    ret
270
271
;-----------------------------------------------------------------------------
272
273
274
convert_t:
275
      
276
    ldi temp1, 0x44          ;befehl für convert_t
277
    mov r10, temp1
278
    rcall write_command        ;schicken
279
            
280
    
281
    cbi portb,0
282
    sbi ddrd,0
283
    rcall wait6us
284
    cbi portb,0
285
    rcall wait9us
286
  
287
  convert_t1:
288
    sbis pinb,0
289
    rjmp convert_t1
290
    
291
292
    ret
293
294
295
;-----------------------------------------------------------------------------
296
297
298
read_scratchpad:
299
  
300
    ldi temp1, 0xBE          ;befehl für scratchpad  
301
    mov r10, temp1
302
    rcall write_command        ;schicken
303
304
      
305
    rcall read_bit          ;einlesen und speichern
306
    sts temp_lsb, temp3
307
308
    rcall read_bit
309
    sts temp_msb, temp3
310
311
    rcall read_bit 
312
    sts th_reg, temp3
313
314
    rcall read_bit
315
    sts tl_reg, temp3
316
317
    rcall read_bit
318
    sts res1, temp3
319
320
    rcall read_bit
321
    sts res2, temp3
322
      
323
    rcall read_bit
324
    sts count_re, temp3
325
326
    rcall read_bit
327
    sts count_pc, temp3
328
329
    rcall read_bit
330
    sts crc, temp3
331
      
332
    ret
333
334
335
336
;-----------------------------------------------------------------------------
337
338
339
wait500us:
340
      ldi  loop1, 200  
341
    ldi  loop2, 6
342
  wait500us1:  
343
      
344
    inc loop1
345
    brne wait500us1
346
        dec  loop2
347
        brne wait500us1
348
349
    ret  
350
      
351
      
352
;-----------------------------------------------------------------------------
353
354
355
wait410us:
356
      ldi  loop1, 5
357
      ldi  loop2, 185
358
  wait410us2:
359
       inc loop1
360
            brne wait410us2
361
            dec  loop2
362
            brne wait410us2
363
364
      ret
365
      
366
      
367
;-----------------------------------------------------------------------------
368
369
370
wait70us:
371
        ldi  loop1, 185
372
  wait70us1:   
373
      inc  loop1
374
           brne wait70us1
375
          
376
377
      ret
378
379
380
;-----------------------------------------------------------------------------
381
          
382
383
wait65us:   
384
      ldi  loop1, $AD
385
  wait65us1: 
386
       dec  loop1
387
            brne wait65us1
388
      nop
389
      
390
      ret
391
392
393
;-----------------------------------------------------------------------------
394
395
396
wait60us:
397
      ldi  loop1, $A0
398
  wait60us1:   
399
      dec  loop1
400
            brne wait60us1
401
402
      ret
403
404
405
;-----------------------------------------------------------------------------
406
407
408
wait55us:
409
      ldi  loop1, $92
410
  wait55us1:  
411
      dec  loop1
412
            brne wait55us1
413
            nop
414
            nop
415
416
      ret
417
418
419
;-----------------------------------------------------------------------------
420
421
422
wait10us:
423
      ldi  loop1, $1A
424
  wait10us1:    
425
      dec  loop1
426
            brne wait10us1
427
            nop
428
            nop
429
430
      ret
431
432
433
;-----------------------------------------------------------------------------
434
435
436
wait9us:
437
       ldi  loop1, $18
438
  wait9us1:  
439
      dec  loop1
440
            brne wait9us1
441
442
      ret
443
444
445
;-----------------------------------------------------------------------------
446
447
448
wait6us:
449
      ldi  loop1, $10
450
  wait6us1:  
451
      dec  loop1
452
            brne wait6us1
453
454
      ret
455
456
457
458
.include "sekunden-routine.asm"
459
.include "LCD-Routine PortC.asm"
460
.include "BIN2ASCII 16Bit.asm"