1 | $regfile = "m32def.dat"
|
2 | $crystal = 16000000
|
3 | $baud = 38400
|
4 |
|
5 | $hwstack = 200
|
6 | $swstack = 200
|
7 | $framesize = 200
|
8 |
|
9 | Config Adc = Single , Prescaler = Auto , Reference = Aref 'Für Spannungsmessung
|
10 | Start Adc
|
11 |
|
12 | Config Porta.2 = Output 'LED amarelo '
|
13 | Config Porta.3 = Output 'LED vermelho
|
14 |
|
15 | Config Portd.3 = Input 'Botao Salvar
|
16 |
|
17 |
|
18 | Config Portb.2 = Input
|
19 | Config Portd.2 = Input
|
20 |
|
21 |
|
22 | Portc.2 = 0
|
23 |
|
24 |
|
25 |
|
26 | Ledamarelo Alias Porta.2
|
27 | Ledvermelho Alias Porta.3
|
28 | Botaosalvar Alias Portd.3
|
29 |
|
30 |
|
31 | Portd.3 = 1
|
32 |
|
33 |
|
34 | Dim Dummi As Integer
|
35 |
|
36 | Dim Rpm1 As Integer
|
37 | Dim Rpm2 As Integer
|
38 |
|
39 | Dim Drehzahl1 As Integer
|
40 | Dim Drehzahl2 As Integer
|
41 |
|
42 | Dim Saveflag As Boolean
|
43 |
|
44 | Saveflag = 0
|
45 |
|
46 | Config Debounce = 30
|
47 |
|
48 | '#################################################################################################################################
|
49 | '#
|
50 | '# LCD
|
51 | '#
|
52 | '#################################################################################################################################
|
53 |
|
54 | ' Einstellen des LCD Display's von myAVR in BASCOM
|
55 | 'Config Lcdpin = Pin , Db4 = Portc.7 , Db5 = Portc.6 , Db6 = Portc.5 , Db7 = Portc.4 , E = Portc.3 , Rs = Portd.7
|
56 | 'Config Lcd = 16 * 2
|
57 |
|
58 |
|
59 | '#################################################################################################################################
|
60 | '#
|
61 | '# Accelerometer
|
62 | '#
|
63 | '#################################################################################################################################
|
64 |
|
65 | 'Acelerometro
|
66 | Config Portc.2 = Output
|
67 | Config Portb.0 = Output
|
68 | Config Portb.1 = Output
|
69 |
|
70 | Portb.0 = 0
|
71 | Portb.1 = 0
|
72 |
|
73 |
|
74 | Config Porta.6 = Input
|
75 | Config Porta.5 = Input
|
76 | Config Porta.4 = Input
|
77 |
|
78 | Dim Xachse As Integer
|
79 | Dim Yachse As Integer
|
80 | Dim Zachse As Integer
|
81 |
|
82 | Dim Ruhelage_x As Integer
|
83 | Dim Ruhelage_y As Integer
|
84 | Dim Ruhelage_z As Integer
|
85 |
|
86 | Const Toleranz_x = 100
|
87 | Const Toleranz_y = 100
|
88 | Const Toleranz_z = 100
|
89 |
|
90 | Waitms 5
|
91 |
|
92 | Ruhelage_x = Getadc(6)
|
93 | Waitms 10
|
94 | Ruhelage_y = Getadc(5)
|
95 | Waitms 10
|
96 | Ruhelage_z = Getadc(4)
|
97 |
|
98 | Waitms 5
|
99 |
|
100 |
|
101 |
|
102 | '#################################################################################################################################
|
103 | '#
|
104 | '# Variabeln für RPM-LEDs
|
105 | '#
|
106 | '#################################################################################################################################
|
107 |
|
108 | ' Porta.0 to SRCLK (Dip pin 11, flat pack pin 14).
|
109 | ' Porta.7 to SER (Dip pin 14, flat pack pin 18).
|
110 | ' Porta.1 to RCLK (Dip pin 12, Flat pack pin 15).
|
111 | '-----------------------------------------------------------------------
|
112 |
|
113 | Config Porta.0 = Output
|
114 | Config Porta.1 = Output
|
115 | Config Porta.7 = Output
|
116 |
|
117 | Dim Rpmwert As Word
|
118 | Dim Low_byte As Byte At Rpmwert Overlay
|
119 | Dim High_byte As Byte At Rpmwert + 1 Overlay
|
120 |
|
121 | Dim I As Integer
|
122 | Dim J As Integer
|
123 |
|
124 | Low_byte = &B10000000
|
125 | High_byte = &B00000000
|
126 |
|
127 | 'Set Ledamarelo
|
128 |
|
129 |
|
130 | For J = 0 To 16
|
131 | ' send byte array to shift regs
|
132 | For I = 0 To 16 'Dein Bit-Zaehler
|
133 |
|
134 | Porta.7 = Rpmwert.6 'Das sind die Datenbits zum reinschieben
|
135 |
|
136 | 'Wenn du also 01101011 im 74595 stehen haben willst,
|
137 | 'dann mußt du das hier in entsprechender Reihenfolge
|
138 | 'so setzten (0 oder 1)
|
139 | '01101011 <- Bits am Ausgang des 74595
|
140 | 'ABCDEFGH <- Ausgang vom 74595
|
141 | '12345678 <- Schleifendurchlauf Nr. x
|
142 |
|
143 | Porta.0 = 1 : Porta.0 = 0 'Damit erzeugst du ne negative Flanke
|
144 |
|
145 | Rotate Rpmwert , Right
|
146 |
|
147 | Next I 'naechstes Bit
|
148 |
|
149 | Porta.1 = 1 : Porta.1 = 0 'Das erzeugt den Impuls zur uebernahme ins Latch
|
150 |
|
151 | 'Reset Ledamarelo
|
152 |
|
153 | Waitms 50
|
154 |
|
155 | Next J
|
156 |
|
157 | Declare Sub Rpm
|
158 |
|
159 |
|
160 |
|
161 | '#################################################################################################################################
|
162 | '#
|
163 | '# Variabeln für die Uhr
|
164 | '#
|
165 | '#################################################################################################################################
|
166 |
|
167 | 'configure the scl and sda pins
|
168 | Config Sda = Portc.1
|
169 | Config Scl = Portc.0
|
170 |
|
171 | 'address of ds1307
|
172 | Const Ds1307w = &HD0 ' Addresses of Ds1307 clock
|
173 | Const Ds1307r = &HD1
|
174 |
|
175 | Config Clock = User ' this will dim the bytes automatic
|
176 | 'dim other needed variables
|
177 | ' Datumsformat deutsch Tag.Monat.Jahr und als Trennzeichen den Punkt
|
178 | Config Date = Dmy , Separator = .
|
179 |
|
180 | Dim Weekday As Byte
|
181 |
|
182 | I2cinit
|
183 |
|
184 | _day = 26
|
185 | _month = 01
|
186 | _year = 12
|
187 | _sec = 59
|
188 | _min = 05
|
189 | _hour = 00
|
190 |
|
191 |
|
192 | Gosub Setdate
|
193 | Gosub Settime
|
194 |
|
195 |
|
196 | '#################################################################################################################################
|
197 | '#
|
198 | '# Variabeln für die SD-Karte
|
199 | '#
|
200 | '#################################################################################################################################
|
201 |
|
202 |
|
203 | ' Variablen festlegen
|
204 | Dim Fsiniterror As Byte ' Fehlercode beim Dateisysteminit
|
205 | Dim Temp As String * 100 ' Zwischenspeicher für Strings
|
206 | Dim Z As Integer ' Zählvariable
|
207 | Const Datei1 = "lesen.txt" ' Datei zum Lesen
|
208 | Const Datei2 = "schreib.txt" ' Datei zum Schreiben
|
209 | ' Achtung:
|
210 | ' Dateinamen müssen im Format 8.3 sein.
|
211 | ' Also Maximal 8 Zeichen vor und 3 nach dem .
|
212 |
|
213 |
|
214 | Const Cmmc_soft = 0
|
215 |
|
216 |
|
217 | #if Cmmc_soft = 0
|
218 |
|
219 | ' --------- Start of Section for HW-SPI ----------------------------------------
|
220 |
|
221 | ' define Chip-Select Pin
|
222 | ' ->
|
223 | ' -> Dieser Pin wird für Chip-Select benutzt.
|
224 | Config Pinb.4 = Output ' define here Pin for CS of MMC/SD Card
|
225 | Mmc_cs Alias Portb.4
|
226 | Set Mmc_cs
|
227 |
|
228 |
|
229 |
|
230 | ' Define here SS Pin of HW-SPI of the CPU (f.e. Pinb.0 on M128)
|
231 | ' If an other Pin than SS is used for MMC_SS, SS must be set to OUTPUT and high for proper work of SPI
|
232 | ' otherwise AVR starts SPI-SLAVE if SS-Pin is INPUT and goes to LOW
|
233 | ' ->
|
234 | ' -> Hier muss der SS-Pin des Hardware-SPI angegeben werden. (Auch wenn ein anderer Pin für Chip-Select benutzt wird.)
|
235 | ' -> Dieser muss als Ausgang konfiguriert sein und auf 1 gehalten werden, da sonst automatisch der SPI-Slave-Modus aktiviert wird.
|
236 | Config Pinb.4 = Output ' define here Pin of SPI SS
|
237 | Spi_ss Alias Portb.4
|
238 | Set Spi_ss ' Set SPI-SS to Output and High por Proper work of
|
239 | ' SPI as Master
|
240 |
|
241 | ' HW-SPI is configured to highest Speed
|
242 |
|
243 | Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 1
|
244 | ' Spsr = 1 ' Double speed on ATMega128
|
245 | Spiinit ' Init SPI
|
246 |
|
247 | ' --------- End of Section for HW-SPI ------------------------------------------
|
248 |
|
249 | #else ' Config here SPI pins, if not using HW SPI
|
250 |
|
251 | ' --------- Start of Section for Soft-SPI --------------------------------------
|
252 |
|
253 | ' Chip Select Pin => Pin 1 of MMC/SD
|
254 | Config Pinb.4 = Output
|
255 | Mmc_cs Alias Portb.4
|
256 | Set Mmc_cs
|
257 |
|
258 | ' MOSI - Pin => Pin 2 of MMC/SD
|
259 | Config Pinb.5 = Output
|
260 | Set Pinb.5
|
261 | Mmc_portmosi Alias Portb
|
262 | Bmmc_mosi Alias 5
|
263 |
|
264 | ' MISO - Pin => Pin 7 of MMC/SD
|
265 | Config Pinb.6 = Input
|
266 | Mmc_portmiso Alias Portb
|
267 | Bmmc_miso Alias 6
|
268 |
|
269 | ' SCK - Pin => Pin 1 of MMC/SD
|
270 | Config Pinb.7 = Output
|
271 | Set Pinb.7
|
272 | Mmc_portsck Alias Portb
|
273 | Bmmc_sck Alias 7
|
274 |
|
275 |
|
276 |
|
277 |
|
278 | ' --------- End of Section for Soft-SPI ----------------------------------------
|
279 |
|
280 | #endif
|
281 |
|
282 | Print "Initialisierung der SD-Card ... " ;
|
283 |
|
284 | Const Cperrdrivereset = 225 ' Error response Byte at Reset command
|
285 | Const Cperrdriveinit = 226 ' Error response Byte at Init Command
|
286 | Const Cperrdrivereadcommand = 227 ' Error response Byte at Read Command
|
287 | Const Cperrdrivewritecommand = 228 ' Error response Byte at Write Command
|
288 | Const Cperrdrivereadresponse = 229 ' No Data response Byte from MMC at Read
|
289 | Const Cperrdrivewriteresponse = 230 ' No Data response Byte from MMC at Write
|
290 | Const Cperrdrive = 231
|
291 | Const Cperrdrivenotsupported = 232 ' return code for DriveGetIdentity, not supported yet
|
292 |
|
293 | Waitms 1 ' Wait some time before initialising MMC/SD
|
294 | Dim Gbdriveerror As Byte ' General Driver Error register
|
295 | Dim Gbdriveerrorreg As Byte ' Driver load Error-Register of HD in case of error
|
296 | Dim Gbdrivestatusreg As Byte ' Driver load Status-Register of HD on case of error
|
297 | Dim Gbdrivedebug As Byte
|
298 | $lib "MMC.LIB" ' link driver library
|
299 | $external _mmc
|
300 | Gbdriveerror = Driveinit() ' Init MMC/SD Card
|
301 |
|
302 | ' 'Fehler beim init?
|
303 | If Gbdriveerror = 0 Then
|
304 | Print "ok"
|
305 |
|
306 | ' 'Config_AVR-DOS einbinden
|
307 | ' 'Puffergrößen, Anzahl von Datei-Handles usw. müssen in dieser Datei angepasst werden!
|
308 | Print "Initialisierung des Dateisystems ..." ;
|
309 | $include "config_avr-dos.bas"
|
310 |
|
311 | 'Dateisystem starten
|
312 | Fsiniterror = Initfilesystem(1)
|
313 | If Fsiniterror = 0 Then
|
314 | Print "ok"
|
315 |
|
316 | Else
|
317 | Print "Fehler bei der Initialisierung des Dateisystems! Fehlercode: " ; Fsiniterror
|
318 |
|
319 | End If
|
320 |
|
321 | ' 'SD-Card erfolgreich gestartet
|
322 | Print "SD-Card wurde erfolgreich gestartet!"
|
323 | Print
|
324 |
|
325 | Else
|
326 |
|
327 | Print "Fehler bei der Initialisierung der SD-Card! Fehlercode: " ; Gbdriveerror
|
328 |
|
329 | End If
|
330 |
|
331 |
|
332 | '#################################################################################################################################
|
333 | '#
|
334 | '# Interrupt für RPM
|
335 | '#
|
336 | '#################################################################################################################################
|
337 |
|
338 | 'Rpm2
|
339 | Dim Icount As Long
|
340 | Dim Wcountlo As Word At Icount Overlay
|
341 | Dim Wcounthi As Word At Icount + 2 Overlay
|
342 | Dim Zahl1 As Long
|
343 | Dim Zahl2 As Long
|
344 | Dim Zahl As Long
|
345 | Dim Frequenz As Long
|
346 |
|
347 | Config Timer1 = Timer , Prescale = 1 , Capture Edge = Rising
|
348 |
|
349 | Config Int2 = Falling
|
350 |
|
351 | On Int2 Oncapture
|
352 | Enable Int2
|
353 |
|
354 | On Ovf1 Onoverflow1
|
355 |
|
356 | Enable Ovf1
|
357 |
|
358 |
|
359 | 'Rpm1
|
360 | Dim Icount2 As Long
|
361 | Dim Wcount2_high As Word At Icount2 Overlay
|
362 | Dim Wcount2_low As Word At Icount2 + 2 Overlay
|
363 | Dim Conta1 As Long
|
364 | Dim Conta2 As Long
|
365 | Dim Conta As Long
|
366 | Dim Frequenz2 As Long
|
367 | Const Interval = 156
|
368 |
|
369 | Config Timer0 = Timer , Prescale = 1
|
370 |
|
371 | Config Int0 = Falling
|
372 |
|
373 | On Int0 Oncapture2
|
374 | Enable Int0
|
375 |
|
376 | On Ovf0 Onoverflow0
|
377 |
|
378 | Enable Ovf0
|
379 |
|
380 |
|
381 |
|
382 | 'Speichern
|
383 | Dim Overflowcount As Long
|
384 | Config Timer2 = Timer , Prescale = 1024
|
385 |
|
386 | On Ovf2 Onoverflow2
|
387 |
|
388 | Config Int1 = Falling
|
389 | On Int1 Save
|
390 | Enable Int1
|
391 |
|
392 | Enable Timer2
|
393 |
|
394 | Enable Interrupts
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 | '#################################################################################################################################
|
401 | '#
|
402 | '# Hauptprogramm
|
403 | '#
|
404 | '#################################################################################################################################
|
405 |
|
406 |
|
407 | Do
|
408 |
|
409 | Waitms 250
|
410 |
|
411 | Disable Interrupts
|
412 |
|
413 | Waitms 5
|
414 |
|
415 | 'Xachse = Getadc(6)
|
416 |
|
417 | Waitms 1
|
418 |
|
419 | 'Yachse = Getadc(5)
|
420 |
|
421 | Waitms 1
|
422 |
|
423 | 'Zachse = Getadc(4)
|
424 |
|
425 | Waitms 3
|
426 |
|
427 | Xachse = Xachse - Ruhelage_x
|
428 | Yachse = Yachse - Ruhelage_y
|
429 | Zachse = Zachse - Ruhelage_z
|
430 |
|
431 | Gosub Getdatetime
|
432 |
|
433 |
|
434 | '~~~ In eine Datei schreiben ~~~
|
435 |
|
436 | 'Datei zum Schreiben öffnen
|
437 | 'Open Datei2 For Output As #10
|
438 | ' 'Altervative:
|
439 | Open Datei2 For Append As #10
|
440 | 'Output 'schreibt die Datei neu (vorhandene Daten werden gelöscht!)
|
441 | 'append 'fügt Daten an die Datei an (vorhandene Daten bleiben erhalten und werden ergänzt)
|
442 |
|
443 | 'Fehler beim Öffnen der Datei?
|
444 | If Gbdoserror <> 0 Then
|
445 | ' Fehler beim Öffnen der Datei
|
446 | Print "Die Datei " ; Datei2 ; " konnte nicht zum Schreiben geöffnet werden! Fehlercode: " ; Gbdoserror
|
447 |
|
448 | Goto Sd_init
|
449 | Else
|
450 | ' Datei erfolgreich geöffnet, ein paar Daten schreiben
|
451 | Print "Schreibe in Datei " ; Datei2 ; " ..."
|
452 |
|
453 | ' Daten schrieben
|
454 | Print #10 , _day ; "." ; _month ; "." ; _year ; ";" ; _hour ; ":" ; _min ; ":" ; _sec ; ";" ; Frequenz ; ";" ; Frequenz2 ; ";" ; Xachse ; ";" ; Yachse ; ";" ; Zachse
|
455 |
|
456 | If Gbdoserror <> 0 Then Print "Fehler beim Schreiben in Datei " ; Datei2 ; "! Fehlercode: " ; Gbdoserror
|
457 |
|
458 | ' Datei wieder schließen
|
459 | Close #10
|
460 |
|
461 |
|
462 | End If
|
463 |
|
464 | 'Reset Ledvermelho
|
465 |
|
466 |
|
467 | 'Reset alle variabeln
|
468 |
|
469 | Xachse = 0
|
470 | Yachse = 0
|
471 | Zachse = 0
|
472 |
|
473 | Print "Gespeichert!"
|
474 |
|
475 |
|
476 | Enable Interrupts
|
477 |
|
478 | Waitms 250
|
479 |
|
480 |
|
481 |
|
482 | Loop
|
483 |
|
484 | End
|
485 |
|
486 | '#################################################################################################################################
|
487 | '#
|
488 | '# Subprogramme für Interrupt
|
489 | '#
|
490 | '#################################################################################################################################
|
491 |
|
492 |
|
493 | Save:
|
494 |
|
495 | Gosub Sd_init
|
496 |
|
497 | Print "Saved"
|
498 |
|
499 | Return
|
500 |
|
501 |
|
502 | Oncapture:
|
503 |
|
504 | Disable Interrupts
|
505 |
|
506 | Wcountlo = Timer1
|
507 | Timer1 = 0
|
508 | Zahl1 = Wcounthi
|
509 | Zahl2 = Wcountlo
|
510 | Wcounthi = 0
|
511 | Zahl = Zahl1 * 65536
|
512 | Zahl = Zahl + Zahl2
|
513 | Frequenz = 480000000 / Zahl
|
514 |
|
515 | Enable Interrupts
|
516 |
|
517 | Return
|
518 |
|
519 |
|
520 |
|
521 |
|
522 | Oncapture2:
|
523 |
|
524 | Disable Interrupts
|
525 | Wcount2_low = Timer0
|
526 | Timer0 = 0
|
527 | Conta1 = Wcount2_high
|
528 | Conta2 = Wcount2_low
|
529 | Wcount2_high = 0
|
530 | Conta = Conta1 * 255
|
531 | Conta = Conta + Conta2
|
532 | Frequenz2 = 480000000 / Conta
|
533 |
|
534 | Print "Rpm1:" ; Frequenz2
|
535 |
|
536 | Enable Interrupts
|
537 |
|
538 | Return
|
539 |
|
540 |
|
541 | Onoverflow1:
|
542 |
|
543 | Incr Wcounthi
|
544 |
|
545 | Return
|
546 |
|
547 |
|
548 | Onoverflow0:
|
549 |
|
550 | Incr Wcount2_high
|
551 |
|
552 | Return
|
553 |
|
554 |
|
555 | Onoverflow2:
|
556 |
|
557 | Disable Interrupts
|
558 |
|
559 | Rpmwert = Frequenz
|
560 |
|
561 | Print Rpmwert
|
562 |
|
563 | Select Case Rpmwert
|
564 |
|
565 | Case 0:
|
566 |
|
567 | Rpmwert = &B0000000000000000
|
568 |
|
569 | Case 1 To 120:
|
570 |
|
571 | Rpmwert = &B0000000000000001
|
572 |
|
573 | Case 121 To 240:
|
574 |
|
575 | Rpmwert = &B0000000000000011
|
576 |
|
577 | Case 241 To 360:
|
578 |
|
579 | Rpmwert = &B0000000000000111
|
580 |
|
581 | Case 361 To 480:
|
582 |
|
583 | Rpmwert = &B0000000000001111
|
584 |
|
585 | Case 481 To 620:
|
586 |
|
587 | Rpmwert = &B0000000000011111
|
588 |
|
589 | Case 621 To 840:
|
590 |
|
591 | Rpmwert = &B0000000000111111
|
592 |
|
593 | Case 841 To 960:
|
594 |
|
595 | Rpmwert = &B0000000001111111
|
596 |
|
597 | Case 961 To 1080:
|
598 |
|
599 | Rpmwert = &B0000000011111111
|
600 |
|
601 | Case 1081 To 1200:
|
602 |
|
603 | Rpmwert = &B0000000111111111
|
604 |
|
605 | Case 1201 To 1320:
|
606 |
|
607 | Rpmwert = &B0000001111111111
|
608 |
|
609 | Case 1321 To 1440:
|
610 |
|
611 | Rpmwert = &B0000011111111111
|
612 |
|
613 | Case 1441 To 1560:
|
614 |
|
615 | Rpmwert = &B0000111111111111
|
616 |
|
617 | Case 1561 To 1680:
|
618 |
|
619 | Rpmwert = &B0001111111111111
|
620 |
|
621 | Case 1681 To 1800:
|
622 |
|
623 | Rpmwert = &B0011111111111111
|
624 |
|
625 | Case 1801 To 1920:
|
626 |
|
627 | Rpmwert = &B0111111111111111
|
628 |
|
629 | End Select
|
630 |
|
631 |
|
632 | Gosub Rpm
|
633 | '
|
634 | Return
|
635 |
|
636 |
|
637 | '#################################################################################################################################
|
638 | '#
|
639 | '# Subprogramme RS-232 Kummunikation
|
640 | '#
|
641 | '#################################################################################################################################
|
642 |
|
643 |
|
644 | ''''''''''''''';called from ds1307clock.lib
|
645 | Getdatetime:
|
646 | I2cstart '''''''''''''''; Generate start code
|
647 | I2cwbyte Ds1307w '''''''''''''''; send address
|
648 | I2cwbyte 0 '''''''''''''''; start address in 1307
|
649 |
|
650 | I2cstart '''''''''''''''; Generate start code
|
651 | I2cwbyte Ds1307r '''''''''''''''; send address
|
652 | I2crbyte _sec , Ack
|
653 | I2crbyte _min , Ack '''''''''''''''; MINUTES
|
654 | I2crbyte _hour , Ack '''''''''''''''; Hours
|
655 | I2crbyte Weekday , Ack '''''''''''''''; Day of Week
|
656 | I2crbyte _day , Ack '''''''''''''''; Day of Month
|
657 | I2crbyte _month , Ack '''''''''''''''; Month of Year
|
658 | I2crbyte _year , Nack '''''''''''''''; Year
|
659 | I2cstop
|
660 | _sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
|
661 | _day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
|
662 | Return
|
663 |
|
664 | Setdate:
|
665 | _day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)
|
666 | I2cstart '''''''''''''''; Generate start code
|
667 | I2cwbyte Ds1307w '''''''''''''''; send address
|
668 | I2cwbyte 4 '''''''''''''''; starting address in 1307
|
669 | I2cwbyte _day '''''''''''''''; Send Data to SECONDS
|
670 | I2cwbyte _month '''''''''''''''; MINUTES
|
671 | I2cwbyte _year '''''''''''''''; Hours
|
672 | I2cstop
|
673 | Return
|
674 |
|
675 | Settime:
|
676 | _sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
|
677 | I2cstart '''''''''''''''; Generate start code
|
678 | I2cwbyte Ds1307w '''''''''''''''; send address
|
679 | I2cwbyte 0 '''''''''''''''; starting address in 1307
|
680 | I2cwbyte _sec '''''''''''''''; Send Data to SECONDS
|
681 | I2cwbyte _min '''''''''''''''; MINUTES
|
682 | I2cwbyte _hour '''''''''''''''; Hours
|
683 | I2cstop
|
684 | Return
|
685 |
|
686 |
|
687 | '#################################################################################################################################
|
688 | '#
|
689 | '# Subprogramme für die SD-Karte
|
690 | '#
|
691 | '#################################################################################################################################
|
692 |
|
693 | Sd_init:
|
694 |
|
695 |
|
696 | Print "Initialisierung der SD-Card ... " ;
|
697 |
|
698 | $external _mmc
|
699 | Gbdriveerror = Driveinit() ' Init MMC/SD Card
|
700 |
|
701 | ' 'Fehler beim init?
|
702 | If Gbdriveerror = 0 Then
|
703 | Print "ok"
|
704 |
|
705 | ' 'Config_AVR-DOS einbinden
|
706 | ' 'Puffergrößen, Anzahl von Datei-Handles usw. müssen in dieser Datei angepasst werden!
|
707 | Print "Initialisierung des Dateisystems ..." ;
|
708 | $include "config_avr-dos.bas"
|
709 |
|
710 | 'Dateisystem starten
|
711 | Fsiniterror = Initfilesystem(1)
|
712 | If Fsiniterror = 0 Then
|
713 | Print "ok"
|
714 |
|
715 | Else
|
716 | Print "Fehler bei der Initialisierung des Dateisystems! Fehlercode: " ; Fsiniterror
|
717 | Do
|
718 | Waitms 500
|
719 | Saveflag = 0
|
720 | Goto Sd_init
|
721 | Loop
|
722 | End If
|
723 |
|
724 | ' 'SD-Card erfolgreich gestartet
|
725 | Print "SD-Card wurde erfolgreich gestartet!"
|
726 | Print
|
727 | Saveflag = 1
|
728 | Print "saveflag aktiviert"
|
729 | Else
|
730 |
|
731 | Print "Fehler bei der Initialisierung der SD-Card! Fehlercode: " ; Gbdriveerror
|
732 | Do
|
733 | Waitms 500
|
734 | Saveflag = 0
|
735 | Goto Sd_init
|
736 | Loop
|
737 | End If
|
738 |
|
739 |
|
740 | Return
|
741 |
|
742 |
|
743 | '#################################################################################################################################
|
744 | '#
|
745 | '# Subprogramme für RPM und RPM-LEDs
|
746 | '#
|
747 | '#################################################################################################################################
|
748 |
|
749 | Rpm: ' *** set initial conditions for I/O ***
|
750 |
|
751 |
|
752 | ' Porta.0 to SCK (Dip pin 11, flat pack pin 14).
|
753 | ' Porta.7 to SER (Dip pin 14, flat pack pin 18).
|
754 | ' Porta.1 to RCK (Dip pin 12, Flat pack pin 15).
|
755 | '-----------------------------------------------------------------------
|
756 |
|
757 | 'Set Ledamarelo
|
758 |
|
759 |
|
760 |
|
761 | ' send byte array to shift regs
|
762 | For I = 0 To 16 'Dein Bit-Zaehler
|
763 |
|
764 | Porta.7 = Rpmwert.15 'Das sind die Datenbits zum reinschieben
|
765 |
|
766 | 'Wenn du also 01101011 im 74595 stehen haben willst,
|
767 | 'dann mußt du das hier in entsprechender Reihenfolge
|
768 | 'so setzten (0 oder 1)
|
769 | '01101011 <- Bits am Ausgang des 74595
|
770 | 'ABCDEFGH <- Ausgang vom 74595
|
771 | '12345678 <- Schleifendurchlauf Nr. x
|
772 |
|
773 | Porta.0 = 1 : Porta.0 = 0 'Damit erzeugst du ne negative Flanke
|
774 |
|
775 | Rotate Rpmwert , Right
|
776 |
|
777 | Next I 'naechstes Bit
|
778 |
|
779 | Porta.1 = 1 : Porta.1 = 0 'Das erzeugt den Impuls zur uebernahme ins Latch
|
780 |
|
781 |
|
782 | 'Reset Ledamarelo
|
783 | Enable Interrupts
|
784 |
|
785 | Return
|