War nicht so schlimm.
Das Problem sind 2 Punkte
* Zum einen die ISR Syntax
* Der Interrupt Vektor heißt ein wenig anders. Lässt sich allerdings
mit 'vergleichender Verhaltensforschung' leicht rauskriegen, wie das
beim WinAVR heißen muss.
* Zum anderen, dass der ICC Code in mcu.h alles mitbekommt, was beim
WinAVR durch die Wahl des Prozessors und
#include <avr/io.h>
geregelt wird.
In der mcu.h wird so gut wie alles auskommentiert, bzw mit einem
1 | #ifdef _ICC_
|
2 | ...
|
3 | #endif
|
ausgeblockt
Ein
kommt unten noch ins File mit hinein, da es diese Konstanet beim WinAvr
nicht gibt, sondern dort PLOCK heißt. Und damit ist dann schon fast
alles andere auch geregelt
main.c sieht dann so aus.
1 | //! @file psc_drv.c,v
|
2 | //!
|
3 | //! Copyright (c) 2004 Atmel.
|
4 | //!
|
5 | //! Please read file license.txt for copyright notice.
|
6 | //!
|
7 | //! @brief This file contains simple example for the PSC1
|
8 | //!
|
9 |
|
10 |
|
11 | #include <avr/io.h>
|
12 | #include <avr/interrupt.h>
|
13 |
|
14 | #include "lib_mcu\compiler.h"
|
15 | #include "lib_mcu\mcu.h"
|
16 | #include "lib_mcu\psc\psc_drv.h"
|
17 |
|
18 |
|
19 | ISR( PSC1_EC_vect )
|
20 | {
|
21 |
|
22 | PIND|=0x80; // just to see that interrupt is alive !
|
23 |
|
24 | }
|
25 |
|
26 |
|
27 |
|
28 | int main()
|
29 |
|
30 | {
|
31 | DDRD |= 0xFF;
|
32 | PORTD |= 0xFF;
|
33 |
|
34 | // PSC is on 12 BIT from 0X0000 To 0x0FFF*
|
35 |
|
36 | OCR1SAH = 0x00; OCR1SAL = 0X00;
|
37 | OCR1RAH = 0X05; OCR1RAL = 0X00;
|
38 | OCR1SBH = 0X03; OCR1SBL = 0X80;
|
39 | OCR1RBH = 0X0F; OCR1RBL = 0Xff;
|
40 |
|
41 |
|
42 | Psc1_use_64_mega_pll_clock(); // Use PLL as clock at 64MHz
|
43 |
|
44 | Enable_both_psc1_outputs(); // Enable PSC1 output
|
45 | Psc1_outputs_active_high(); // PSC1 output active is High level
|
46 | Psc1_in_1_ramp_mode(); // PSC1 in one Ramp mode
|
47 |
|
48 |
|
49 |
|
50 | PIM1=0x01; // enable IT end of cycle PSC1
|
51 | SREG=0x80; // enable interrupt
|
52 |
|
53 | Start_psc1(); // let's go
|
54 |
|
55 | while(1);
|
56 | }
|
Dann bleibt nur noch ein Problem, weil sich Atmel entschieden hat
'Funktionen' als Makros zu definieren. Zumindest mein WinAvr ist mit
Psc1_use_64_mega_pll_clock
nicht glücklich.
Ein Umarbeiten des Makros in psc_drv.h auf eine inline Funktion behebt
das Problem allerdings ganz schnell
1 | ...
|
2 |
|
3 | #define Psc1_use_io_clock() (PCNF1 &= ~(1<<PCLKSEL0) )
|
4 | //! Start the PLL at 64MHz and connect it to PSC1
|
5 |
|
6 |
|
7 | inline void Psc1_use_64_mega_pll_clock()
|
8 | {
|
9 | Start_pll_64_mega();
|
10 | Wait_pll_ready();
|
11 | Psc1_use_pll_clock();
|
12 | }
|
13 |
|
14 |
|
15 | //! Start the PLL at 32MHz and connect it to PSC1
|
16 | #define Psc1_use_32_mega_pll_clock() \
|
17 | (Start_pll_32_mega(), \
|
18 |
|
19 | ...
|
Damit compiliert und linkt das Projekt schon mal. Obs auch funktioniert,
kann ich hier nicht testen.
Alles in allem eine Sache auf 15 Minuten, incl. Download
Ach ja, ein paar Include Pfade hab ich noch angepasst :-)