1 | /*****************************************************
|
2 | This program was produced by the
|
3 | CodeWizardAVR V1.24.8 Standard
|
4 | Automatic Program Generator
|
5 | © Copyright 1998-2006 Pavel Haiduc, HP InfoTech s.r.l.
|
6 | http://www.hpinfotech.com
|
7 |
|
8 | Project : Türklingel
|
9 | Version :
|
10 | Date : 25.07.2011
|
11 | Author : Winfried Jaeckel
|
12 | Company : Deviltronic
|
13 | Comments:
|
14 |
|
15 |
|
16 | Chip type : ATtiny2313
|
17 | Clock frequency : 4,096000 MHz
|
18 | Memory model : Tiny
|
19 | External SRAM size : 0
|
20 | Data Stack size : 32
|
21 | *****************************************************/
|
22 |
|
23 | #include <tiny2313.h>
|
24 |
|
25 |
|
26 | #define g0 0x28d0 //196Hz
|
27 | #define a0 0x245c //220Hz
|
28 | #define h0 0x2062 //247Hz
|
29 | #define c 0x1e88 //262Hz
|
30 | #define d 0x1b35 //294Hz
|
31 | #define e 0x183d //330Hz
|
32 | #define f 0x16eb //349Hz
|
33 | #define g 0x1468 //392Hz
|
34 | #define a 0x122e //440Hz
|
35 | #define h 0x1031 //494Hz
|
36 | #define c1 0x0f4b //523Hz
|
37 | #define d1 0x0da0 //587Hz
|
38 | #define e1 0x0c23 //659Hz
|
39 | #define f1 0x0b75 //698Hz
|
40 | #define g1 0x0a34 //784Hz
|
41 |
|
42 | //Damit auch längere Pausen eingebunden werden können, wird der Wert 1 als Pause interpretiert:
|
43 | #define p 1 //Pause
|
44 |
|
45 |
|
46 | // Declare your global variables here
|
47 |
|
48 | flash unsigned int m1[]=
|
49 | {
|
50 | c,30, //Ton C0 (tiefes C), 300ms (30 x 10ms) (horch)
|
51 | d,30, //was
|
52 | e,30, //kommt
|
53 | f,30, //von
|
54 | g,30, //drau-
|
55 | a,30, //;ßen
|
56 | g,60, //rein
|
57 |
|
58 | f,30,d,30,h,60, //hollahi
|
59 | g,30,e,30,c1,60, //hollaho
|
60 | c,30,d,30,e,30,f,30,g,30,a,30,g,60, //hoch was kommt von draußen rein
|
61 | f,30,d,30,h,30,d1,30,c1,120, //hollahiaho...
|
62 | a,60,a,60,c1,60,h,30,a,30,g,60,e,60,g,120,
|
63 | f,60,d,60,h,120,g,60,e,60,c1,120, //hollahi hollaho
|
64 | a,60,a,60,c1,60,h,30,a,30,g,60,e,60,g,120,
|
65 | f,60,d,60,h,60,d1,60,c1,120, //hollahiaho...
|
66 | 0,0 //Ende-Kennung "0"
|
67 |
|
68 | }; //melodie
|
69 |
|
70 | bit start, stop,run,tr;//tr ton_run
|
71 | // Timer 0 overflow interrupt service routine
|
72 | interrupt [TIM0_OVF] void timer0_ovf_isr(void)
|
73 | {
|
74 | static int tonnr,tonh; //Tonnummer,Tonhöhe
|
75 | static unsigned char dauer;
|
76 | // Reinitialize Timer 0 value
|
77 | TCNT0=0xd8; //in 10ms sehen wir uns wieder
|
78 |
|
79 | // Place your code here
|
80 | if (start==1){tonnr=0;start=0;stop=0;run=1;};
|
81 | if ((run ==1)&(tr==0)) // falls die melodie läuft und der vorherige ton fertig ist
|
82 | {
|
83 | tonh=m1[tonnr]; // Ton holen
|
84 | dauer=m1[tonnr+1]; // und dessen Dauer
|
85 | tr=1; // Ton starten
|
86 | };
|
87 | if (tonh==0)stop=1; // wenn der ton==0 dann ist die melodie aus
|
88 | if (stop==1){tonnr=0;start=0;stop=0;run=0;tr=0;}; // hier wird alles ausgeschaltet
|
89 |
|
90 | if (run==1) //So lange die Musik spielt ist Run==1
|
91 | {
|
92 | if (tonh==1) tonh=0; // wenn hier eine eins ist wird der tongenerator für eine Notedauer ausgeschaltetet
|
93 |
|
94 | if (dauer >1) // wenn keine Notenpause dann
|
95 | {
|
96 | OCR1AH=(tonh&0xff00)/256; // higbyte // tongenrator mit ton versorgen
|
97 | OCR1AL=tonh&0x00ff; // lowbyte
|
98 | }
|
99 | else
|
100 | {
|
101 | OCR1AH=0; // die letzen 10ms jeder Note ist Ruhe.
|
102 | OCR1AL=0;
|
103 | };
|
104 | if (dauer>0) // Falss der ton noch nicht zu ende ist
|
105 | {
|
106 |
|
107 | dauer--; // wird hier die Tondauer dekrementiert
|
108 | }
|
109 | else {tr=0;tonnr=tonnr+2;}; // ansonsten wird das der Tonzäler erhöht und tr==0 zeigt an das der nächste ton zu holen ist
|
110 |
|
111 | };
|
112 |
|
113 |
|
114 | }
|
115 |
|
116 |
|
117 | void main(void) Hier wird nur initialisiert
|
118 | {
|
119 | // Declare your local variables here
|
120 |
|
121 | // Crystal Oscillator division factor: 1
|
122 | #pragma optsize-
|
123 | CLKPR=0x80;
|
124 | CLKPR=0x00;
|
125 | #ifdef _OPTIMIZE_SIZE_
|
126 | #pragma optsize+
|
127 | #endif
|
128 |
|
129 | // Input/Output Ports initialization
|
130 | // Port A initialization
|
131 | // Func2=In Func1=In Func0=In
|
132 | // State2=T State1=T State0=T
|
133 | PORTA=0x00;
|
134 | DDRA=0x00;
|
135 |
|
136 | // Port B initialization
|
137 | // Func7=In Func6=In Func5=In Func4=In Func3=Out Func2=In Func1=In Func0=In
|
138 | // State7=T State6=T State5=T State4=T State3=0 State2=T State1=T State0=T
|
139 | PORTB=0x00;
|
140 | DDRB=0x08;
|
141 |
|
142 | // Port D initialization
|
143 | // Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
|
144 | // State6=T State5=T State4=T State3=T State2=T State1=T State0=T
|
145 | PORTD=0x00;
|
146 | DDRD=0x40;
|
147 |
|
148 | // Timer/Counter 0 initialization
|
149 | // Clock source: System Clock
|
150 | // Clock value: 4,000 kHz
|
151 | // Mode: Normal top=FFh
|
152 | // OC0A output: Disconnected
|
153 | // OC0B output: Disconnected
|
154 | TCCR0A=0x00;
|
155 | TCCR0B=0x05;
|
156 | TCNT0=0xd8; //d8;
|
157 | OCR0A=0x00;
|
158 | OCR0B=0x00;
|
159 |
|
160 | // Timer/Counter 1 initialization
|
161 | // Clock source: System Clock
|
162 | // Clock value: 4096,000 kHz
|
163 | // Mode: CTC top=OCR1A
|
164 | // OC1A output: Toggle
|
165 | // OC1B output: Discon.
|
166 | // Noise Canceler: Off
|
167 | // Input Capture on Falling Edge
|
168 | // Timer 1 Overflow Interrupt: Off
|
169 | // Input Capture Interrupt: Off
|
170 | // Compare A Match Interrupt: Off
|
171 | // Compare B Match Interrupt: Off
|
172 | TCCR1A=0x40;
|
173 | TCCR1B=0x09;
|
174 | TCNT1H=0x00;
|
175 | TCNT1L=0x00;
|
176 | ICR1H=0x00;
|
177 | ICR1L=0x00;
|
178 | OCR1AH=0x03;
|
179 | OCR1AL=0xff;
|
180 | OCR1BH=0x00;
|
181 | OCR1BL=0x00;
|
182 |
|
183 | // External Interrupt(s) initialization
|
184 | // INT0: Off
|
185 | // INT1: Off
|
186 | // Interrupt on any change on pins PCINT0-7: Off
|
187 | GIMSK=0x00;
|
188 | MCUCR=0x00;
|
189 |
|
190 | // Timer(s)/Counter(s) Interrupt(s) initialization
|
191 | TIMSK=0x02;
|
192 |
|
193 | // Universal Serial Interface initialization
|
194 | // Mode: Disabled
|
195 | // Clock source: Register & Counter=no clk.
|
196 | // USI Counter Overflow Interrupt: Off
|
197 | USICR=0x00;
|
198 |
|
199 | // Analog Comparator initialization
|
200 | // Analog Comparator: Off
|
201 | // Analog Comparator Input Capture by Timer/Counter 1: Off
|
202 | ACSR=0x80;
|
203 |
|
204 | // Global enable interrupts
|
205 | #asm("sei")
|
206 | start=1;
|
207 | while (1)
|
208 | {
|
209 | // Place your code here
|
210 |
|
211 | };
|
212 | }
|