1 | #include <xc.h>
|
2 | #include "hdq.h"
|
3 |
|
4 | void MyOscCal(void);
|
5 |
|
6 | // #pragma config statements should precede project file includes.
|
7 | // Use project enums instead of #define for ON and OFF.
|
8 |
|
9 | // CONFIG1L
|
10 | #pragma config CPUDIV = NOCLKDIV// CPU System Clock Selection bits (No CPU System Clock divide)
|
11 | #pragma config USBDIV = OFF // USB Clock Selection bit (USB clock comes directly from the OSC1/OSC2 oscillator block; no divide)
|
12 |
|
13 | // CONFIG1H
|
14 | #pragma config FOSC = ERC // Oscillator Selection bits (External RC oscillator)
|
15 | #pragma config PLLEN = OFF // 4 X PLL Enable bit (PLL is under software control)
|
16 | #pragma config PCLKEN = ON // Primary Clock Enable bit (Primary clock enabled)
|
17 | #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor disabled)
|
18 | #pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
|
19 |
|
20 | // CONFIG2L
|
21 | #pragma config PWRTEN = OFF // Power-up Timer Enable bit (PWRT disabled)
|
22 | #pragma config BOREN = OFF // Brown-out Reset Enable bits (Brown-out Reset disabled in hardware and software)
|
23 | #pragma config BORV = 19 // Brown-out Reset Voltage bits (VBOR set to 1.9 V nominal)
|
24 |
|
25 | // CONFIG2H
|
26 | #pragma config WDTEN = OFF // Watchdog Timer Enable bit (WDT is controlled by SWDTEN bit of the WDTCON register)
|
27 | #pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768)
|
28 |
|
29 | // CONFIG3H
|
30 | #pragma config HFOFST = OFF // HFINTOSC Fast Start-up bit (The system clock is held off until the HFINTOSC is stable.)
|
31 | #pragma config MCLRE = ON // MCLR Pin Enable bit (MCLR pin enabled; RA3 input pin disabled)
|
32 |
|
33 | // CONFIG4L
|
34 | #pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
|
35 | #pragma config LVP = ON // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
|
36 | #pragma config BBSIZ = OFF // Boot Block Size Select bit (1kW boot block size)
|
37 | #pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
|
38 |
|
39 | // CONFIG5L
|
40 | #pragma config CP0 = OFF // Code Protection bit (Block 0 not code-protected)
|
41 | #pragma config CP1 = OFF // Code Protection bit (Block 1 not code-protected)
|
42 |
|
43 | // CONFIG5H
|
44 | #pragma config CPB = OFF // Boot Block Code Protection bit (Boot block not code-protected)
|
45 | #pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM not code-protected)
|
46 |
|
47 | // CONFIG6L
|
48 | #pragma config WRT0 = OFF // Table Write Protection bit (Block 0 not write-protected)
|
49 | #pragma config WRT1 = OFF // Table Write Protection bit (Block 1 not write-protected)
|
50 |
|
51 | // CONFIG6H
|
52 | #pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers not write-protected)
|
53 | #pragma config WRTB = OFF // Boot Block Write Protection bit (Boot block not write-protected)
|
54 | #pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not write-protected)
|
55 |
|
56 | // CONFIG7L
|
57 | #pragma config EBTR0 = OFF // Table Read Protection bit (Block 0 not protected from table reads executed in other blocks)
|
58 | #pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 not protected from table reads executed in other blocks)
|
59 |
|
60 | // CONFIG7H
|
61 | #pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot block not protected from table reads executed in other blocks)
|
62 |
|
63 | #include <xc.h>
|
64 | #include <pic18.h>
|
65 | #define _XTAL_FREQ 8000000
|
66 |
|
67 | int main(int argc, char** argv) {
|
68 | int i=0b01101010;
|
69 | TRISA=0xFF;
|
70 | TRISB=0xFF;
|
71 | TRISC=0xFF;
|
72 | LATA=0x00;
|
73 | LATB=0x00;
|
74 | LATC=0x00;
|
75 | TRISBbits.RB4=0;
|
76 | while(1){
|
77 | //batteryPercent(1);
|
78 | //PORTBbits.RB4=1;
|
79 | //LATB4=1;
|
80 | LATBbits.LATB4=1;
|
81 | for(i=0;i<500;i++){
|
82 | __delay_ms(1);
|
83 | }
|
84 | //PORTBbits.RB4=0;
|
85 | //LATB4=0;
|
86 | LATBbits.LATB4=0;
|
87 | for(i=0;i<500;i++){
|
88 | __delay_ms(1);
|
89 | }
|
90 | MyOscCal();
|
91 | }
|
92 | return 1;
|
93 | }
|
94 | void MyOscCal(void) @ 0x3FFF{
|
95 | asm("retlw 0x0000"); // Change 0x80 to something else if the oscillator is way off
|
96 | }
|