servo.c


1
/*********************************************
2
This program was produced by the
3
CodeWizardAVR V1.23.7a Professional
4
Automatic Program Generator
5
© Copyright 1998-2002 HP InfoTech s.r.l.
6
http://www.hpinfotech.ro
7
e-mail:office@hpinfotech.ro
8
9
Project : 
10
Version : 
11
Date    : 07.06.2004
12
Author  : Species                         
13
Company :                                 
14
Comments: 
15
16
17
Chip type           : AT90S2313
18
Clock frequency     : 16,000000 MHz
19
Memory model        : Tiny
20
Internal SRAM size  : 128
21
External SRAM size  : 0
22
Data Stack size     : 32
23
*********************************************/
24
25
#include <90s2313.h>
26
#include <delay.h>
27
28
// Declare your global variables here
29
int Durchlaufzaehler = 0; 
30
31
32
33
#pragma savereg-
34
35
36
// Timer 1 overflow interrupt service routine
37
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
38
{
39
#asm
40
push r30
41
in   r30,SREG
42
push r30
43
#endasm
44
45
46
Durchlaufzaehler++;
47
TCNT0=0xE0;
48
49
#asm
50
    pop r30
51
    out SREG,r30
52
    pop r30
53
#endasm
54
}
55
56
57
58
59
60
61
void main(void)
62
{
63
// Declare your local variables here
64
char Position[8]={0,0,128,255,255,255,0,0};
65
int Durchlaufzaehler1 = 0;
66
67
// Input/Output Ports initialization
68
// Port B initialization
69
PORTB=0x0F;
70
DDRB=0xFF;
71
72
// Port D initialization
73
PORTD=0xFF;
74
DDRD=0x00;
75
76
// Timer/Counter 0 initialization
77
// Clock source: System Clock
78
// Clock value: 12000,000 kHz
79
TCCR0=0x01;
80
TCNT0=0xB0;
81
82
// Timer(s)/Counter(s) Interrupt(s) initialization
83
TIMSK=0x02;
84
85
// Global enable interrupts
86
#asm("sei")
87
88
89
90
91
while (1)
92
      {
93
      
94
      for(Durchlaufzaehler = 0; Durchlaufzaehler < 220;) PORTB=0xFF;
95
      
96
      
97
      for(Durchlaufzaehler = 0; Durchlaufzaehler < 255;)
98
        {
99
        if (Durchlaufzaehler<Position[0]) PORTB.0 = 1;
100
        else PORTB.0 = 0;
101
        
102
        if (Durchlaufzaehler<Position[1]) PORTB.1 = 1;
103
        else PORTB.1 = 0;
104
        
105
        if (Durchlaufzaehler<Position[2]) PORTB.2 = 1;
106
        else PORTB.2 = 0;
107
        
108
        if (Durchlaufzaehler<Position[3]) PORTB.3 = 1;
109
        else PORTB.3 = 0;
110
        
111
        if (Durchlaufzaehler<Position[4]) PORTB.4 = 1;
112
        else PORTB.4 = 0;
113
        
114
        if (Durchlaufzaehler<Position[5]) PORTB.5 = 1;
115
        else PORTB.5 = 0;
116
        
117
        if (Durchlaufzaehler<Position[6]) PORTB.6 = 1;
118
        else PORTB.6 = 0; 
119
        
120
        if (Durchlaufzaehler<Position[7]) PORTB.7 = 1;
121
        else PORTB.7 = 0;
122
        
123
        }
124
        
125
      for(Durchlaufzaehler1 = 0; Durchlaufzaehler1 <= 10; Durchlaufzaehler1++)
126
        {
127
        for(Durchlaufzaehler = 0;Durchlaufzaehler <= 128;)
128
          {
129
                PORTB=0x00;
130
                }       
131
        }
132
   
133
 if (PIND.4 == 0 ) Position[0]+= 1;
134
 if (PIND.6 == 0 ) Position[0]-= 1;  
135
136
      };
137
}