SERVO2.ASM


1
.include "m8def.inc"            ; Definitionen für Atmel ATmega8
2
3
.def pos1 = r16
4
.def pos2 = r17
5
.def cnt1 = r18
6
.def cnt2 = r20
7
.def temp = r21
8
.def tmp2 = r22
9
10
;#############################################################################;
11
12
.org 0x000
13
   rjmp INIT                  ; Reset Handler
14
15
.org OVF0addr
16
   rjmp Timer0                  ; Timer0 Overflow Handler
17
18
;#############################################################################;
19
20
.equ MinValue  = 49             ; Der Minimalwert für die linke Position
21
                                ; Der Wert hängt vom verwendeten Servo ab!
22
.equ PosServo1 = 1              ; Position von Servo1; 1 <= n <= 100
23
.equ PosServo2 = 100            ; Position von Servo2; 1 <= n <= 100
24
.equ frequenz  = 4000000  ; Frequenz in Hz
25
;.equ start = 256-(12.5*frequenz/1000000)
26
.equ start= 206                          
27
28
;#############################################################################;
29
30
INIT:
31
32
   ldi temp, LOW(RAMEND)
33
   out SPL, temp
34
   ldi temp, HIGH(RAMEND)
35
   out SPH, temp
36
37
   ldi temp, 0xFF
38
   out DDRB, temp               ; Port B -> Ausgang
39
   ldi temp, 0x00
40
   out PORTB, temp
41
   
42
   ldi pos1, PosServo1          ; Servo1 positionieren
43
   ldi pos2, PosServo2          ; Servo2 positionieren
44
45
   ldi temp, 0b00000010         ; Timer0 Interrupt aktivieren
46
   out TIMSK, temp
47
48
   ldi temp, start              ; Startwert des Timers
49
   out TCNT0, temp
50
51
   ldi temp, 0b00000010         ; Prescaler auf 8
52
   out TCCR1B, temp
53
54
   sei                          ; Interrupts aktivieren
55
56
   ldi cnt1, 0
57
   rjmp MAIN
58
59
;#############################################################################;
60
61
MAIN:
62
63
   rjmp MAIN                  
64
65
;#############################################################################;
66
   
67
Timer0:                      
68
   
69
comp1:  ldi temp,10
70
  cpse cnt1,temp   
71
     rjmp comp2
72
     sbi portb,0
73
74
comp2:  ldi temp,20
75
  cpse cnt1,temp  
76
     rjmp comp3
77
     cbi portb,0
78
79
comp3:  ldi temp,200
80
  cpse cnt1,temp   
81
     rjmp restart
82
     ldi cnt1,0
83
84
restart:
85
   ldi temp, start 
86
   out TCNT0, temp   
87
   inc cnt1
88
   reti