1 | /** I N C L U D E S ********************************/
|
2 | #include <p18f4550.h>
|
3 | #include "delay.h"
|
4 |
|
5 | /** Configuration **********************************/
|
6 | #pragma config PLLDIV = 5 // (20 MHz crystal on PICDEMFS USB board)
|
7 | #pragma config CPUDIV = OSC1_PLL2
|
8 | #pragma config USBDIV = 2 // Clock source from 96MHzPLL/2
|
9 | #pragma config FOSC = HSPLL_HS
|
10 | #pragma config FCMEN = OFF
|
11 | #pragma config IESO = OFF
|
12 | #pragma config PWRT = OFF
|
13 | #pragma config BOR = ON
|
14 | #pragma config BORV = 3
|
15 | #pragma config VREGEN = ON //USB Voltage Regulator
|
16 | #pragma config WDT = OFF
|
17 | #pragma config WDTPS = 32768
|
18 | #pragma config MCLRE = ON
|
19 | #pragma config LPT1OSC = OFF
|
20 | #pragma config PBADEN = OFF
|
21 | // #pragma config CCP2MX = ON
|
22 | #pragma config STVREN = ON
|
23 | #pragma config LVP = OFF
|
24 | // #pragma config ICPRT = OFF // Dedicated In-CircuitDebug/Programming
|
25 | #pragma config XINST = OFF // Extended Instruction Set
|
26 | #pragma config CP0 = OFF
|
27 | #pragma config CP1 = OFF
|
28 | // #pragma config CP2 = OFF
|
29 | // #pragma config CP3 = OFF
|
30 | #pragma config CPB = OFF
|
31 | // #pragma config CPD = OFF
|
32 | #pragma config WRT0 = OFF
|
33 | #pragma config WRT1 = OFF
|
34 | // #pragma config WRT2 = OFF
|
35 | // #pragma config WRT3 = OFF
|
36 | #pragma config WRTB = OFF // Boot Block Write Protection
|
37 | #pragma config WRTC = OFF
|
38 | // #pragma config WRTD = OFF
|
39 | #pragma config EBTR0 = OFF
|
40 | #pragma config EBTR1 = OFF
|
41 | // #pragma config EBTR2 = OFF
|
42 | // #pragma config EBTR3 = OFF
|
43 | #pragma config EBTRB = OFF
|
44 |
|
45 | /** F U N C T I O N S ******************************/
|
46 | void low_isr( void );
|
47 | void high_isr( void );
|
48 |
|
49 | /** I N T E R R U P T S ****************************/
|
50 | /*
|
51 | * Bei PIC18 ist der low Interrupt Vector bei
|
52 | * 00000018h.
|
53 | */
|
54 | #pragma code low_vector=0x18
|
55 | void interrupt_at_low_vector( void )
|
56 | {
|
57 | _asm GOTO low_isr _endasm
|
58 | }
|
59 | #pragma code
|
60 |
|
61 | #pragma interruptlow low_isr
|
62 | void low_isr( void )
|
63 | {
|
64 |
|
65 | }
|
66 |
|
67 | /*
|
68 | * Bei PIC18 ist der high Interrupt Vector bei
|
69 | * 00000008h.
|
70 | */
|
71 | #pragma code high_vector=0x08
|
72 | void interrupt_at_high_vector( void )
|
73 | {
|
74 | _asm GOTO high_isr _endasm
|
75 | }
|
76 | #pragma code
|
77 |
|
78 | #pragma interruptlow high_isr
|
79 | void high_isr( void )
|
80 | {
|
81 | if( INTCONbits.RBIF ) // PORTB Change Interrupt
|
82 | {
|
83 | INTCONbits.RBIF = 0; // Wenn ja Interruptflag löschen
|
84 | Delay_ms( 750 );
|
85 | PORTD += 1; // PORTD xor Verknüpfen
|
86 | }
|
87 | }
|
88 |
|
89 | /** D E C L A R A T I O N S ************************/
|
90 | #pragma code
|
91 |
|
92 | // **********************************************
|
93 | //
|
94 | // Hauptprogramm
|
95 | //
|
96 | //
|
97 | // **********************************************
|
98 | void main( void )
|
99 | {
|
100 | // Variablen definieren
|
101 | int test;
|
102 |
|
103 | //Einstellen der Ports
|
104 | // 0 = Output
|
105 | // 1 = Input
|
106 | TRISD = 0x00; //PORTD Ausgang
|
107 | PORTD = 0x00;
|
108 |
|
109 | TRISB = 0xFF; //PORTB Eingang
|
110 |
|
111 | test = PORTB;
|
112 |
|
113 | // Interrupt Konfigurieren
|
114 | INTCONbits.GIE = 1; // Interrupts generell erlauben
|
115 | //INTCONbits.GIEL = 1; // Peripheral Interrupt enable
|
116 | INTCONbits.RBIF = 0; // Interrupt on Change Flag aus
|
117 | INTCONbits.RBIE = 1; // Interrupt on Change an den PINs
|
118 | // PORTB(7:4)
|
119 | //INTCON2bits.RBIP = 0; // Low Priority
|
120 |
|
121 | RCONbits.IPEN = 0; // Interrupt Priority off
|
122 |
|
123 | while( 1 );
|
124 | }
|