Pic32 monophone Soundausgabe
- Kondesator nur für PWM nötig, kann also weggelassen werden.
<highlightSyntax language="c">
- include <p32xxxx.h>
- include <plib.h>
void delay_7us (void)
{
#define DELAYU 1 T1CON = 0x8030; PR1 = 0xffff; TMR1 = 0; while (TMR1 < DELAYU);
return;
}
int main(void) { int c,d,e;
int hoehe=7; int a[37]={1092,
1031, 973, 918, 867, 818, 772, 729, 688, 649, 613, 579, 546, 515, 486, 459, 433, 409, 386, 364, 344, 325, 306, 289, 273, 258, 243, 230, 217, 205, 193, 182, 172, 162, 153, 145, 137};
int b[37]={16,
17,
18,
19,
21,
22,
23,
24,
26,
28,
29,
31,
33,
35,
37,
39,
41,
44,
46,
49,
52,
55,
58,
62,
65,
69,
73,
78,
82,
87,
92,
98,
104,
110,
117,
123,
131
};
int lied[][2]={
{7, 4}, {7, 4}, {7, 4}, {3, 3}, {10, 1}, {7, 4}, {3, 3}, {10, 1}, {7, 8}, {14, 4}, {14, 4}, {14, 4}, {15, 3}, {10, 1}, {6, 4}, {3, 3}, {10, 1}, {7, 8}, {19, 4}, {7, 3}, {7, 1}, {19, 4}, {18, 3}, {17, 1}, {16, 1}, {15, 1}, {16, 4}, {8, 2}, {13, 4}, {12, 3}, {11, 1}, {10, 1}, {9, 1}, {10, 4}, {3, 2}, {6, 4}, {3, 3}, {6, 1}, {10, 4}, {7, 3}, {10, 1}, {14, 8}, {19, 4}, {7, 3}, {7, 1}, {19, 4}, {18, 3}, {17, 1}, {16, 1}, {15, 1}, {16, 4}, {8, 2}, {13, 4}, {12, 3}, {11, 1}, {10, 1}, {9, 1}, {10, 4}, {3, 2}, {6, 4}, {3, 3}, {10, 1}, {7, 4}, {3, 3}, {10, 1}, {7, 8}
};
/* Configure PB frequency and wait states */ SYSTEMConfigPerformance(40000000L);
/* output via port C2 (entspricht digital con4 D2 auf dem pb */
mPORTCSetPinsDigitalOut(BIT_2);
while(1) {
for(c=0; c<66; c++){ //schleife ueber alle toene for(d=0; d<b[ lied[c][0] + hoehe ] * lied[c][1] ; d++){ //laenge des tons mPORTCToggleBits(BIT_2); for(e=0; e<a[lied[c][0] + hoehe ]; e++) //freqenz delay_7us(); } for(e=0; e<100; e++){ delay_7us(); } } for(e=0; e<100000; e++){ delay_7us(); } }
return 0; }
</highlightSyntax>