Da ist doch kaum was drin... An Adresse 0x33 die ISR für die
PCA-Einheit, das war's auch schon. Insgesamt ist der gegebene Code aber
noch recht unvollständig.
In C in etwa so:
1 | #include <controller-spezifisches.h>
|
2 | bit Flag;
|
3 | unsigned char Capture; // oder braucht es hier einen INT??
|
4 | unsigned char Pulse_Width; // alles als Globale Variablen deklariert....
|
5 |
|
6 | void main (void)
|
7 | {
|
8 | // PCA INIT: ; Initialize PCA timer
|
9 | CMOD = 0x00; // Input to timer 4 1/12 X Fosc
|
10 | CH = 0x00;
|
11 | CL = 0x00;
|
12 |
|
13 | // Initialize Module 0 in capture mode
|
14 | CCAPM0 = 0x21; // Capture positive edge first
|
15 | // for measuring pulse width
|
16 |
|
17 | EC = 1; // Enable PCA interrupt
|
18 | EA = 1;
|
19 | CR = 1; // Turn PCA timer on
|
20 | FLAG = 0; // clear test flag
|
21 |
|
22 | while (1){} // warte auf Interrupts
|
23 | // die Hauptschleife fehlt aber in dem obigen Ausschnitt!!
|
24 |
|
25 | }
|
26 |
|
27 | void ISR_PCA(void) interrupt 6 // nachschauen, wie das Dein Compiler haben will!!
|
28 | {
|
29 | CCF0 =0; // Clear Module 0's event flag
|
30 | if (FLAG==0) // Check if this is the first
|
31 | { // capture or second
|
32 | // FIRST CAPTURE:
|
33 | CAPTURE = CCAP0L; // Save 16-bit capture value
|
34 | CAPTURE01 = CCAP0H; // in RAM ------ die wurde gar nicht deklariert!!
|
35 | CCAPM0 = 0x11; // Change module to now capture
|
36 | // falling edges
|
37 | FLAG = 1; // Signify 1st capture complete
|
38 | }
|
39 | else // SECOND CAPTURE:
|
40 | {
|
41 | Pulse_Width = CAPTURE - CCAP0L; // oder so ähnlich...
|
42 | Pulse_Width01 = CCAP0H - CAPTURE; // Pulse_Width01 ist nicht definiert!!
|
43 | CCAPM0 = 0x21; // OptionalÐneeded if user wants to
|
44 | FLAG = 0; // measure next pulse width
|
45 | }
|
46 | }
|
Insgesamt ist die 16-Bit Subtraktion in C natürlich einfacher machbar.
Schau, was in der Anwendung eigentlich wirklich gemacht werden soll! Der
Rest ist dann Hausaufgabe.