PREAMP_PWM.c


1
#include  <avr/io.h>
2
#include     <stdint.h>
3
4
//////////////////////////////
5
#define   Takt 8000000ul
6
//////////////////////////////
7
volatile   uint16_t i;
8
volatile   uint16_t GainA;
9
volatile   uint16_t GainB;
10
volatile   uint16_t TrebleA;
11
volatile   uint16_t TrebleB;
12
volatile   uint16_t MidsA;
13
volatile   uint16_t MidsB;
14
volatile   uint16_t BassA;
15
volatile   uint16_t BassB;
16
volatile   uint16_t PresenceA;
17
volatile   uint16_t PresenceB;
18
volatile   uint16_t LevelA;
19
volatile   uint16_t LevelB;
20
//////////////////////////////
21
#define    PORTA1     PORTB
22
#define    PORTA2     PORTC  
23
#define    Gain1      PB0
24
#define    Gain2      PB1
25
#define    Treble1    PB2
26
#define    Treble2     PB3
27
#define    Mids1     PB4
28
#define    Mids2     PB5
29
#define    Bass1     PB6
30
#define    Bass2     PB7
31
#define    Presence1  PC0
32
#define    Presence2  PC1
33
#define   Level1     PC2
34
#define    Level2     PC3
35
36
37
38
void main (void)
39
{  
40
  GainA=32768; //Spannung=2,5V  entspricht 2^16/2
41
  DDRB=0xFF;
42
  DDRC=0xFF;
43
  PORTA1=0x00;
44
  PORTA2=0x00;
45
46
  
47
  
48
  while(1)
49
  {  
50
  
51
52
    
53
  if(GainA>=i)        //Abgleich mit des Zähler i mit den globalen Variablen
54
     {
55
         PORTA1|=(1<<Gain1);
56
     }
57
  else
58
     {
59
         PORTA1&=~(1<<Gain1);
60
     }  
61
  
62
  if(GainB>=i)
63
     {
64
         PORTA1|=(1<<Gain2);
65
     }
66
  else
67
     {
68
         PORTA1&=~(1<<Gain2);
69
     }  
70
  
71
  if(TrebleA>=i)
72
     {
73
         PORTA1|=(1<<Treble1);
74
     }
75
  else
76
     {
77
         PORTA1&=~(1<<Treble1);
78
     }  
79
80
  if(TrebleB>=i)
81
     {
82
         PORTA1|=(1<<Treble2);
83
     }
84
  else
85
     {
86
         PORTA1&=~(1<<Treble2);
87
     }
88
89
  if(MidsA>=i)
90
     {
91
         PORTA1|=(1<<Mids1);
92
     }
93
  else
94
     {
95
         PORTA1&=~(1<<Mids1);
96
     }
97
       
98
  if(MidsB>=i)
99
     {
100
         PORTA1|=(1<<Mids2);
101
     }
102
  else
103
     {
104
         PORTA1&=~(1<<Mids2);
105
     }
106
107
  if(BassA>=i)
108
     {
109
         PORTA1|=(1<<Bass1);
110
     }
111
  else
112
     {
113
         PORTA1&=~(1<<Bass1);
114
     }
115
116
  if(BassB>=i)
117
     {
118
         PORTA1|=(1<<Bass2);
119
     }
120
  else
121
     {
122
         PORTA1&=~(1<<Bass2);
123
     }
124
125
  if(PresenceA>=i)
126
     {
127
         PORTA2|=(1<<Presence1);
128
     }
129
  else
130
     {
131
         PORTA2&=~(1<<Presence1);
132
     }
133
134
  if(PresenceB>=i)
135
     {
136
         PORTA2|=(1<<Presence2);
137
     }
138
  else
139
     {
140
         PORTA2&=~(1<<Presence2);
141
     }
142
143
  if(LevelA>=i)
144
     {
145
         PORTA2|=(1<<Level1);
146
     }
147
  else
148
     {
149
         PORTA2&=~(1<<Level1);
150
     }
151
152
  if(LevelB>=i)
153
     {
154
         PORTA2|=(Level2<<1);
155
     }
156
  else
157
     {
158
         PORTA2&=~(Level2<<1);
159
     }
160
161
  i++;  //erhöhen des Zählers
162
163
  }
164
165
}