Hallo ;) fang grad an mich mit dem Xmega128A1 zu beschäftigen, schon lang nix mehr in C gemacht das sollte doch so funktionieren oder? : Danke schonmal!
1 | int set_clock(clock) { |
2 | |
3 | if (clock = 0) { |
4 | OSC.CTRL = OSC_RC2MEN_bm; // Internal 2 MHz |
5 | /* if Oscillator is stable, RC2MRDY is set */
|
6 | while(!(OSC.STATUS & OSC_RC2MRDY_bm)); |
7 | /*I/O Protection*/
|
8 | CCP = 0xD8; |
9 | /*2 MHz Internal RC Oscillator*/
|
10 | CLK.CTRL = 0x00; |
11 | return 0; |
12 | }
|
13 | |
14 | if (clock = 1) { |
15 | OSC.CTRL = OSC_RC32MEN_bm; // Internal 32 MHz |
16 | /* if Oscillator is stable, RC32MRDY is set */
|
17 | while(!(OSC.STATUS & OSC_RC32MRDY_bm)); |
18 | /*I/O Protection*/
|
19 | CCP = 0xD8; |
20 | /*32 MHz Internal RC Oscillator*/
|
21 | CLK.CTRL = 0x01; |
22 | return 0; |
23 | }
|
24 | |
25 | if (clock = 2) { |
26 | OSC.CTRL = OSC_RC32KEN_bm; // Internal 32kHz |
27 | /* if Oscillator is stable, RC32MRDY is set */
|
28 | while(!(OSC.STATUS & OSC_RC32KEN_bm)); |
29 | /*I/O Protection*/
|
30 | CCP = 0xD8; |
31 | /*32 kHz Internal RC Oscillator*/
|
32 | CLK.CTRL = 0x10; |
33 | return 0; |
34 | }
|
35 | |
36 | if (clock = 3) { |
37 | OSC.CTRL = OSC_XOSCEN_bm; // External |
38 | /* if Oscillator is stable, XOSCEN is set */
|
39 | while(!(OSC.STATUS & OSC_XOSCEN_bm)); |
40 | /*I/O Protection*/
|
41 | CCP = 0xD8; |
42 | /*External Oscillator or Clock*/
|
43 | CLK.CTRL = 0x11; |
44 | return 0; |
45 | }
|
46 | |
47 | return 0; |
48 | }
|