// PIC24FJ256GB108 - uMOGI2 Configuration Bit Settings // CONFIG3 #pragma config WPFP = WPFP511 // Write Protection Flash Page Segment Boundary (Highest Page (same as page 170)) #pragma config WPDIS = WPDIS // Segment Write Protection Disable bit (Segmented code protection disabled) #pragma config WPCFG = WPCFGDIS // Configuration Word Code Page Protection Select bit (Last page(at the top of program memory) and Flash configuration words are not protected) #pragma config WPEND = WPENDMEM // Segment Write Protection End Page Select bit (Write Protect from WPFP to the last page of memory) // CONFIG2 #pragma config POSCMOD = HS // Primary Oscillator Select (HS oscillator mode selected) #pragma config DISUVREG = ON // Internal USB 3.3V Regulator Disable bit (Regulator is enabled) #pragma config IOL1WAY = ON // IOLOCK One-Way Set Enable bit (Write RP Registers Once) #pragma config OSCIOFNC = OFF // Primary Oscillator Output Function (OSCO functions as CLKO (FOSC/2)) #pragma config FCKSM = CSDCMD // Clock Switching and Monitor (Both Clock Switching and Fail-safe Clock Monitor are disabled) #pragma config FNOSC = PRIPLL // Oscillator Select (Primary oscillator (XT, HS, EC) with PLL module (XTPLL,HSPLL, ECPLL)) #pragma config PLL_96MHZ = ON // 96MHz PLL Disable (Enabled) #pragma config PLLDIV = DIV3 // USB 96 MHz PLL Prescaler Select bits (Oscillator input divided by 3 (12MHz input)) #pragma config IESO = OFF // Internal External Switch Over Mode (IESO mode (Two-speed start-up)disabled) // CONFIG1 #pragma config WDTPS = PS32768 // Watchdog Timer Postscaler (1:32,768) #pragma config FWPSA = PR128 // WDT Prescaler (Prescaler ratio of 1:128) #pragma config WINDIS = OFF // Watchdog Timer Window (Standard Watchdog Timer enabled,(Windowed-mode is disabled)) #pragma config FWDTEN = OFF // Watchdog Timer Enable (Watchdog Timer is disabled) #pragma config ICS = PGx2 // Comm Channel Select (Emulator functions are shared with PGEC2/PGED2) #pragma config GWRP = OFF // General Code Segment Write Protect (Writes to program memory are allowed) #pragma config GCP = OFF // General Code Segment Code Protect (Code protection is disabled) #pragma config JTAGEN = OFF // JTAG Port Enable (JTAG port is disabled) #include /* altalanos header a PIC24 csaladhoz */ // Hardver tulajdonsagok: // PLL utani orajel #define SYS_FREQ 32000000L #define FCY SYS_FREQ/2 // Masodlagos orajel forras - orakvarc #define F_SEC_OSC 32768 // Delay fuggvenyek #define DELAY_MS(ms) __delay_ms(ms); #define DELAY_US(us) __delay_us(us); #include // __delay_ms // LED-ek #define LED1 _LATG6 #define LED2 _LATG7 #define LED3 _LATG8 #define LED4 _LATG9 #define LEDR _LATD15 #define LEDG _LATF4 #define LEDB _LATF5 // Nyomogombok #define SW1 !_RC1 #define SW2 !_RC3 #define SW3 !_RE8 #define SW4 !_RE9 int main() { //Inicializalas - setup //Orajel forras beallitasa // PLL kimenete CLKDIVbits.CPDIV = 0; // 1:1 32MHz // megvarjuk amig a PLL modul vegez while(!OSCCONbits.LOCK) Nop(); // szoftveres WDT kikapcsolasa RCONbits.SWDTEN = 0; // Orakvarc engedelyezese //__builtin_write_OSCCONL(OSCCON | 0x02); // Periferia - lab osszerendeles PPS (pp.135) //__builtin_write_OSCCONL(OSCCON & 0xBF); //PPSUnLock; // //__builtin_write_OSCCONL(OSCCON | 0x40); //PPSLock; // Labak iranya _TRISG6 = 0; // LED1 kimenet _TRISG7 = 0; // LED2 kimenet _TRISG8 = 0; // LED3 kimenet _TRISG9 = 0; // LED4 kimenet _TRISD15 = 0; // LEDR kimenet _TRISF4 = 0; // LEDG kimenet _TRISF5 = 0; // LEDB kimenet _TRISC1 = 1; // SW1 bemenet _TRISC3 = 1; // SW2 bemenet _TRISE8 = 1; // SW3 bemenet _TRISE9 = 1; // SW4 bemenet //Végtelen ciklus - super loop while(1) { //ciklikus feladatok elvegzese LEDR = !LEDR; DELAY_MS(500); } return (0); } // ISR void __attribute__((interrupt(auto_psv))) _T1Interrupt() { _T1IF = 0; // interrupt flag torlese }