1 | //------HEADER-----------------
|
2 | #include <stdio.h>
|
3 | #include <stdlib.h>
|
4 | #include <p18cxxx.h>
|
5 | #include <delays.h>
|
6 |
|
7 | //------CPU SETTINGS-------------
|
8 | #pragma config MCLRE = OFF //RE3 input pin enabled; MCLR disabled
|
9 | #pragma config XINST = OFF
|
10 | //#pragma config FOSC = INTIO1 //Internal oscillator block, CLKOUT function on RA6, port function on RA7
|
11 | #pragma config FOSC = INTIO2 //Internal oscillator block, port function on RA6 and RA7
|
12 | #pragma config INTOSCSEL = LOW //LF-INTOSC in Low-power mode during Sleep
|
13 | #pragma config RETEN = OFF //Ultra low-power regulator is Disabled (Controlled by REGSLP bit)
|
14 | #pragma config WDTEN = OFF //WDT is controlled by SWDTEN bit of the WDTCON register
|
15 | #pragma config WDTPS = 2048 //Watchdog Timer Postscale Select bits 4ms*2048
|
16 | #pragma config FCMEN = OFF //Fail-Safe Clock Monitor disabled
|
17 | #pragma config IESO = OFF //Oscillator Switchover mode disabled
|
18 | #pragma config PWRTEN = ON //enable Power-up Timer
|
19 | #pragma config BOREN = OFF //Brown-out Reset disabled in hardware and software
|
20 | #pragma config SOSCSEL = DIG //Digital (SCLKI) mode; I/O port functionality of RC0 and RC1 is enabled
|
21 |
|
22 | //-----FORWARD------------------------------------------------------------------------------
|
23 | void main (void);
|
24 | void InterruptHandlerHigh (void); //Interrupt
|
25 |
|
26 | //-------main-------------------------------------------------------------------------------
|
27 | void main(void)
|
28 | {
|
29 | //init pins
|
30 | TRISA=0x00;
|
31 | TRISB=0xff;
|
32 | TRISC=0x00;
|
33 |
|
34 | PORTA=0xff;
|
35 | PORTC=0xff;
|
36 |
|
37 | INTCONbits.GIE=0; //disable all interrupts
|
38 | //init Debug Messages
|
39 | OSCCON=0b01100000; //8MHz
|
40 | OSCTUNEbits.PLLEN=0; //x4 off
|
41 | // OSCCON=0b00110000; //1MHz
|
42 | // OSCTUNEbits.PLLEN=0; //x4 off
|
43 |
|
44 | //activate all interrupts
|
45 |
|
46 | INTCON3bits.INT1IE=1; //Enables the INT1 external interrupt
|
47 | // INTCON3bits.INT2IE=1; //Enables the INT2 external interrupt
|
48 | INTCONbits.GIE=1;
|
49 |
|
50 | while(1) //endless loop
|
51 | {
|
52 | PORTC=0xff;
|
53 | Delay10KTCYx(1000);
|
54 | PORTC=0x00;
|
55 | Delay10KTCYx(1000);
|
56 | }//end while
|
57 |
|
58 | }//end main
|
59 |
|
60 | //===========================================================================================
|
61 | //-------------------------------------------------------------------------------------------
|
62 | // High priority interrupt vector
|
63 | #pragma code InterruptVectorHigh = 0x08
|
64 | void InterruptVectorHigh (void)
|
65 | {
|
66 | _asm
|
67 | goto InterruptHandlerHigh //jump to interrupt routine
|
68 | _endasm
|
69 | }
|
70 | //-------------------------------------------------------------------------------------------
|
71 | // High priority interrupt routine
|
72 | #pragma code
|
73 | #pragma interrupt InterruptHandlerHigh
|
74 | void InterruptHandlerHigh ()
|
75 | {
|
76 | /*
|
77 | //extern interrtupt INT2
|
78 | if (INTCON3bits.INT2IF)
|
79 | {//check for INT2
|
80 | INTCON3bits.INT2IF = 0; //clear ext interrupt flag
|
81 |
|
82 |
|
83 | }
|
84 | */
|
85 | //extern interrtupt INT1
|
86 | if (INTCON3bits.INT1IF)
|
87 | {//check for INT1
|
88 | INTCON3bits.INT1IF = 0; //clear ext interrupt flag
|
89 | PORTA=0x00;
|
90 | Delay10KTCYx(100);
|
91 | PORTA=0xFF;
|
92 | }
|
93 | }
|