1 | ' Digitalanzeige mit
|
2 | ' 7-Segmentanzeigen
|
3 | ' In: Drehimpulsgeber an d.2 und d.3
|
4 | ' Out: 7-Segmentanzeige
|
5 |
|
6 | $regfile = "M8def.dat"
|
7 | $crystal = 8000000
|
8 |
|
9 |
|
10 | '--------------Declarationen für Drehimpulsgeber
|
11 | Config Int0 = Falling 'Change
|
12 | On Int0 Drehencoder
|
13 | Enable Int0
|
14 | Enable Interrupts
|
15 | '--------------Config Eingänge Drehgeber
|
16 | Config Pind.2 = Input
|
17 | Config Pind.3 = Input
|
18 | Portd.2 = 1
|
19 | Encoder_a Alias Pind.2
|
20 | Portd.3 = 1
|
21 | Encoder_b Alias Pind.3
|
22 | '-------------Config Ausgänge Siebensegment
|
23 | Config Portb = &B11111111
|
24 | Config Portc = &B00111100
|
25 | '-------------Pullup Taster0 Taster_Auf Taster_Ab
|
26 | Config Pind.0 = Input
|
27 | Portc.0 = 1
|
28 | Taster0 Alias Pinc.0
|
29 | Portc.1 = 1
|
30 | Taster_ab Alias Pinc.1
|
31 | Portd.0 = 1
|
32 | Taster_auf Alias Pind.0
|
33 | '-------------Deklaration Variable
|
34 | Dim Wert As Word
|
35 | Dim Grad As String * 4
|
36 | Dim Grad1 As String * 1
|
37 | Dim Teiler As Byte
|
38 | Dim Ee_teiler As Eram Byte
|
39 | Dim Hilfswert As Byte
|
40 | Dim Rueck As Byte
|
41 | Teiler = Ee_teiler
|
42 | '-------------Test Siebensegmentanzeige
|
43 | Portb = &B00000000
|
44 | Portc = &B00000010
|
45 | Waitms 2000
|
46 | Portc = &B11011111
|
47 | Waitms 2000
|
48 | Portc = &B11101111
|
49 | Waitms 2000
|
50 | Portc = &B11110111
|
51 | Waitms 2000
|
52 | Portc = &B11111011
|
53 | Waitms 2000
|
54 | Portb = &B00000000
|
55 | Portc = &B00000010
|
56 | Waitms 2000
|
57 | '-------------Hauptprogramm---------------
|
58 |
|
59 | Do
|
60 |
|
61 | If Taster0 = 0 Then 'Anzeige nullen
|
62 | Wert = 0
|
63 | End If
|
64 | While Taster0 = 0 'Einstellung Teiler
|
65 | Hilfswert = Hilfswert + 1
|
66 | Waitms 500
|
67 | If Hilfswert > 10 Then
|
68 | Gosub Einstellung
|
69 | End If
|
70 | Wend
|
71 | Hilfswert = 0
|
72 | Wert = Wert / Teiler
|
73 | Grad = Str(wert) 'Wandlung zu String
|
74 | Grad = Format(grad , "0000") 'Formatieren immer 4 Stellen
|
75 | 'Ansteuerung 1. Segment
|
76 | Grad1 = Mid(grad , 1 , 1)
|
77 | Portb.2 = 1
|
78 | Gosub Auswahl
|
79 | Portc = &B11011111
|
80 | Waitms 2
|
81 | 'Ansteuerung 2. Segment
|
82 | Grad1 = Mid(grad , 2 , 1)
|
83 | Portb.2 = 1
|
84 | Gosub Auswahl
|
85 | Portc = &B11101111
|
86 | Waitms 2
|
87 | 'Ansteuerung 3. Segment
|
88 | Grad1 = Mid(grad , 3 , 1)
|
89 | Gosub Auswahl
|
90 | Portc = &B11110111
|
91 | Portb.2 = 0 'Dezimalpunkt setzen
|
92 | Waitms 2
|
93 | 'Ansteuerung 4. Segment
|
94 | Grad1 = Mid(grad , 4 , 1)
|
95 | Portb.2 = 1
|
96 | Gosub Auswahl
|
97 | Portc = &B11111011
|
98 | Waitms 2
|
99 | Loop
|
100 | End
|
101 |
|
102 | Drehencoder:
|
103 | If Encoder_b = 0 Then Decr Wert Else Incr Wert
|
104 | Return
|
105 |
|
106 | Auswahl:
|
107 | Select Case Grad1
|
108 | Case "0" : Portb = &B00000110
|
109 | Case "1" : Portb = &B11100111
|
110 | Case "2" : Portb = &B00001101
|
111 | Case "3" : Portb = &B01000101
|
112 | Case "4" : Portb = &B11100100
|
113 | Case "5" : Portb = &B01010100
|
114 | Case "6" : Portb = &B00010100
|
115 | Case "7" : Portb = &B11000111
|
116 | Case "8" : Portb = &B00000100
|
117 | Case "9" : Portb = &B01000100
|
118 | End Select
|
119 | Return
|
120 |
|
121 | Einstellung:
|
122 | Do
|
123 | Rueck = Rueck + 1
|
124 | If Taster_auf = 0 Then
|
125 | Waitms 100
|
126 | Rueck = 0
|
127 | Teiler = Teiler + 1
|
128 | End If
|
129 | If Taster_ab = 0 Then
|
130 | Waitms 100
|
131 | Rueck = 0
|
132 | Teiler = Teiler - 1
|
133 | End If
|
134 | Waitms 50
|
135 | Select Case Teiler
|
136 | Case 0 : Portb = &B00000110
|
137 | Case 1 : Portb = &B11100111
|
138 | Case 2 : Portb = &B00001101
|
139 | Case 3 : Portb = &B01000101
|
140 | Case 4 : Portb = &B11100100
|
141 | Case 5 : Portb = &B01010100
|
142 | Case 6 : Portb = &B00010100
|
143 | Case 7 : Portb = &B11000111
|
144 | Case 8 : Portb = &B00000100
|
145 | Case 9 : Portb = &B01000100
|
146 | End Select
|
147 | Portc = &B11111011
|
148 | Waitms 2
|
149 | Loop Until Rueck = 100
|
150 | Ee_teiler = Teiler
|
151 | Return
|