1 | ; TID 10 Stellen Display Anzeige
|
2 | ; Überarbeitet Version von Marco Reinke (DG1YIQ)
|
3 | ; Features: Festtext
|
4 | ; Anpassung an Atmega 8 von PIC 16F88
|
5 |
|
6 | ; Version v0.2
|
7 |
|
8 | .include "m8def.inc" ;Include Datei Atmega8
|
9 |
|
10 | ;--- Reset und Interruptvectoren; VNr. Bezeichnung
|
11 | begin: rjmp main ; 1 Power ON RESET
|
12 | reti ; 2 Int0- Interrupt
|
13 | reti ; 3 Int1- Interrupt
|
14 | reti ; 4 TC2 Compare Match
|
15 | reti ; 5 TC2 Overflow
|
16 | reti ; 6 TC1 Capture
|
17 | reti ; 7 TC1 Compare Match A
|
18 | reti ; 8 TC1 Compare Match B
|
19 | reti ; 9 TC1 Overflow
|
20 | reti ;10 TC0 Overflow
|
21 | reti ;11 SPI, STC = Serial Transfer Complete
|
22 | reti ;12 UART Rx Complete
|
23 | reti ;13 UART Data Register Empty
|
24 | reti ;14 UART Tx Complete
|
25 | reti ;15 ADC Conversion Complete
|
26 | reti ;16 EEPROM Ready
|
27 | reti ;17 Analog Comparator
|
28 | reti ;18 TWI (I²C) Serial Interface
|
29 | reti ;19 Store Programm Memory Ready
|
30 | main:
|
31 | ; Portzuweisungen
|
32 | ; Port A, keine Zuweisungen
|
33 | ; PORTA,4 INFO! ; TMR0 Zähler Geschwindigkeit/(Drehzahl)
|
34 |
|
35 | ; Port B
|
36 | #define ANZ PortC,0 ; Display/Datum (low = Display an, high = Datum)
|
37 | #define SCL PortB,5 ; SCL TID - Clock zum Display
|
38 | #define SDA PortB,6 ; SDA TID - Daten zum Display
|
39 | #define MRQ PortB,7 ; MRQ TID - Request ?
|
40 |
|
41 | ;Registern Namen geben
|
42 | .def temp1=r16
|
43 | .def temp2=r17
|
44 | .def I2CBYTE=r19
|
45 | .def AREG=r20
|
46 | .def BREG=r21
|
47 | .def CREG=r22
|
48 | .def DREG=r18
|
49 | .def integ100=r23
|
50 | .def integ10=r24
|
51 | .def integ1=r25
|
52 |
|
53 | ; Speicher und Variablen
|
54 | ;.equ buf= 0x60
|
55 | ;.equ count= 0x61
|
56 | .equ CounterA=0x62
|
57 | .equ CounterB=0x63
|
58 | .equ CounterC=0x64
|
59 | ;.equ CounterD=0x65
|
60 | ;.equ W1= 0x66
|
61 | ;.equ W2= 0x67
|
62 | ;.equ W3= 0x68
|
63 | ;.equ I2CBYTE=0x69
|
64 | ; .equ AREG= 0x6A
|
65 | ; .equ BREG= 0x6B
|
66 | ; .equ CREG= 0x6C
|
67 | ; .equ DREG= 0x6D
|
68 | .equ CHAR1= 0x6E
|
69 | .equ CHAR2= 0x6F
|
70 | .equ CHAR3= 0x70
|
71 | .equ CHAR4= 0x71
|
72 | .equ CHAR5= 0x72
|
73 | .equ CHAR6= 0x73
|
74 | .equ CHAR7= 0x74
|
75 | .equ CHAR8= 0x75
|
76 | .equ CHAR9= 0x76
|
77 | .equ CHAR10= 0x77
|
78 | .equ TIDtemp=0x78
|
79 | .equ TIDtextNr=0x79
|
80 | ;.equ integ1= 0x7A
|
81 | ;.equ integ10=0x7B
|
82 | ;.equ integ100=0x7C
|
83 | .equ current=0x7D
|
84 | .equ temp= 0x7E
|
85 | .equ mainTemp=0x7F
|
86 | .equ xw0= 0x80
|
87 | .equ xw1= 0x81
|
88 | .equ f0= 0x82
|
89 | .equ f1= 0x83
|
90 | .equ counter=0x84
|
91 | ;.equ Fehler= 0x85
|
92 | ;.equ STI= 0x86 ;war erst ST
|
93 | ;.equ SZ= 0x87
|
94 | ;.equ SH= 0x88
|
95 | ;.equ SED= 0x89 ;war erst SE
|
96 | ;.equ eebuf=0x8A
|
97 |
|
98 | ; Stackpointer festlegen
|
99 | ldi temp2, low (RAMEND) ;Init Stackpointer Low
|
100 | out SPL, temp2
|
101 | ldi temp2, high(RAMEND) ;Init Stackpointer High
|
102 | out SPH, temp2
|
103 |
|
104 | ; Port A - einstellen der Richtung und Art der Pins
|
105 |
|
106 | ldi temp2,0b11111111;Port A komplett Digital
|
107 | out DDRC,temp2 ;PORTA alles Ausgänge
|
108 |
|
109 | ; Port B - einstellen der Richtung und Art der Pins
|
110 |
|
111 | ldi temp2,0b11111111
|
112 | out DDRB,temp2 ;Port B alles Ausgänge
|
113 |
|
114 | ; Zähler Einstellungen
|
115 |
|
116 | ldi temp2,0x01
|
117 | out TCCR0,temp2 ; Zähler ohne Vorteiler
|
118 |
|
119 | ; 1 Sekunde Pause damit die Hardware sich stabilisieren kann
|
120 |
|
121 | sbi ANZ ; Datum an - Display aus !
|
122 | rcall delay_1_sec ; 1 Sekunde warten
|
123 | ; rcall delay_1_sec ; 1 Sekunde warten
|
124 | cbi ANZ ; Datum aus - Display an !
|
125 |
|
126 | ; TID Text Nr "0"
|
127 | ldi temp2,0x00
|
128 | sts TIDtextNr,temp2 ; Zeichenzähler auf 0
|
129 |
|
130 | ;***********************************************************
|
131 | ;
|
132 | ; --->>> Ab hier geht das Hauptprogramm und Schleifen los...
|
133 | ;
|
134 | ;***********************************************************
|
135 |
|
136 | sendTID:
|
137 | ldi temp2,0xff
|
138 | mov BREG,temp2 ; Send byte (W)
|
139 | mov I2CBYTE,temp2; Send byte (W)
|
140 | clr CREG ; The number of 1
|
141 | ldi temp2,0x07
|
142 | mov AREG,temp2 ; cycle value
|
143 |
|
144 | send0:
|
145 | ldi temp2,0x00 ; temp2 mit 0 Laden damit es dann verglichen werden kann
|
146 | ror BREG ; rotate the byte,
|
147 | brcc jump1 ; Überspringe wenn Carry Flag=0 nächsten Befehl Sprung zu jump
|
148 | inc CREG ; (but only the low 7 bit)
|
149 | jump1:
|
150 | dec AREG ; Subtrahiere 1 von AREG
|
151 | cpse AREG,temp2 ; Überspringe nächsten Befehl von AREG = temp2 (0=0)
|
152 | rcall send0
|
153 |
|
154 | rol I2CBYTE ; Rotate, and behind the parity
|
155 | cbr I2CBYTE,0 ;Bit0 löschen
|
156 | sbrs CREG,0 ; if CREG odd, then clear parity
|
157 | sbr I2CBYTE,0 ;Bit0 setzen
|
158 |
|
159 | ; send byte
|
160 | ldi temp2,0x08 ;
|
161 | mov CREG,temp2 ; Cycle 8x
|
162 |
|
163 | send1:
|
164 | cbi SCL ; Clock=0
|
165 | rcall wait050ms ; UP wait050ms aufrufen
|
166 |
|
167 | sbrc I2CBYTE,7 ; ist Bit7 gesetzt?
|
168 | rjmp send3 ; UP send3 aufrufen
|
169 | cbi SDA ; SDA=0
|
170 | rjmp send4 ; UP send4 aufrufen
|
171 | send3:
|
172 | sbi SDA ; SDA=1
|
173 | send4:
|
174 | rcall wait050ms ; UP wait050ms aufrufen
|
175 | sbi SCL ; SCL=1, ->valid data
|
176 | rcall wait050ms ; UP wait050ms aufrufen
|
177 |
|
178 | rol I2CBYTE ; rotate left trough carry
|
179 |
|
180 | dec CREG ; Cycle
|
181 | cpse CREG,temp2 ; Überspringe nächsten Befehl von CREG = temp2 (0=0)
|
182 | rjmp send1 ; UP send1 aufrufen
|
183 |
|
184 | cbi SCL ; SCL= 0
|
185 | rcall wait050ms ; UP wait050ms aufrufen
|
186 |
|
187 | ; ACK
|
188 | sbi SDA ; Output=1
|
189 | rcall wait050ms ; UP wait050ms aufrufen
|
190 | sbi SCL ; Clock=1=> ACK
|
191 |
|
192 | rcall wait050ms ; ignore ACK
|
193 |
|
194 | cbi SCL ; Clock=0
|
195 | rcall wait050ms ; UP wait050ms aufrufen
|
196 | cbi SDA ; data=0
|
197 | ret
|
198 |
|
199 |
|
200 | ;**********************************
|
201 | ;
|
202 | ; --->>> Ab hier Zeitschleifen ect.
|
203 | ;
|
204 | ;**********************************
|
205 |
|
206 | ; Zeitverzögerung 0.50 mS -> 1/4 Milli Sekunde
|
207 | ; Time Delay = 0.0005s with Osc = 4 MHz
|
208 | wait050ms:
|
209 | ; delaying 19998 cycles: 5ms
|
210 | ldi R20, $21
|
211 | WGLOOP0: ldi R21, $C9
|
212 | WGLOOP1: dec R21
|
213 | brne WGLOOP1
|
214 | dec R20
|
215 | brne WGLOOP0
|
216 | ; -----------------------------
|
217 | ; delaying 2 cycles:
|
218 | nop
|
219 | nop
|
220 | ret
|
221 |
|
222 | ; Zeitverzögerung 2mS -> 2/1000 Sekunde
|
223 | ; Time Delay = 0.002s with Osc = 4 MHz
|
224 | wait2ms:
|
225 | ; delaying 7998 cycles:2ms
|
226 | ldi R20, $1F
|
227 | WGLOOP02: ldi R21, $55
|
228 | WGLOOP12: dec R21
|
229 | brne WGLOOP12
|
230 | dec R20
|
231 | brne WGLOOP02
|
232 | ; -----------------------------
|
233 | ; delaying 2 cycles:
|
234 | nop
|
235 | nop
|
236 | ret
|
237 |
|
238 | ; Zeitverzögerung 10ms -> Zeitverzögerung 1/100 Sekunde
|
239 | ; Time Delay = 0.09999500s with Osc = 4.00000000MHz
|
240 | wait01s:
|
241 | ; delaying 399999 cycles: 1 Hundertstel
|
242 | ldi R20, $97
|
243 | WGLOOP03: ldi R21, $06
|
244 | WGLOOP13: ldi R22, $92
|
245 | WGLOOP23: dec R22
|
246 | brne WGLOOP23
|
247 | dec R21
|
248 | brne WGLOOP13
|
249 | dec R20
|
250 | brne WGLOOP03
|
251 | ; -----------------------------
|
252 | ; delaying 1 cycle:
|
253 | nop
|
254 | ret
|
255 |
|
256 | ; Zeitverzögerung 200ms Sekunden -> 1/5 Sekunde
|
257 | ; Time Delay = 0.19999300s with Osc = 4.00000000MHz
|
258 | delay02sec:
|
259 | ldi temp2,0x02
|
260 | mov CREG,temp2
|
261 | ldi temp2,0x05
|
262 | mov BREG,temp2
|
263 | ldi temp2,0xB7
|
264 | mov AREG,temp2
|
265 |
|
266 | delay_02s_sec_loop:
|
267 | ldi temp2,0x00
|
268 | dec AREG
|
269 | cpse AREG,temp2
|
270 | rjmp delay_02s_sec_loop
|
271 | delay_02s_sec_loopB:
|
272 | dec BREG
|
273 | cpse BREG,temp2
|
274 | rjmp delay_02s_sec_loopB
|
275 | delay_02s_sec_loopC:
|
276 | dec CREG
|
277 | cpse CREG,temp2
|
278 | rcall delay_02s_sec_loopC
|
279 | ret
|
280 |
|
281 | ; Zeitverzögerung 1.0 Sekunden -> 1/1 Sekunde
|
282 | ; Time Delay = 0.99999800s with Osc = 4.00000000MHz
|
283 | delay_1_sec:
|
284 |
|
285 | ; delaying 3999996 cycles ->1s
|
286 | ldi R20, $24
|
287 | WGLOOP01: ldi R21, $BC
|
288 | WGLOOP11: ldi R22, $C4
|
289 | WGLOOP21: dec R22
|
290 | brne WGLOOP21
|
291 | dec R21
|
292 | brne WGLOOP11
|
293 | dec R20
|
294 | brne WGLOOP01
|
295 | ; -----------------------------
|
296 | ; delaying 3 cycles:
|
297 | ldi R20, $01
|
298 | WGLOOP31: dec R20
|
299 | brne WGLOOP31
|
300 | ; -----------------------------
|
301 | ; delaying 1 cycle:
|
302 | nop
|
303 | ; =============================
|
304 |
|
305 | ret
|