// PIC32MX530F128H Configuration Bit Settings

// DEVCFG3
#pragma config USERID = 0xFFFF          // Enter Hexadecimal value (Enter Hexadecimal value)
#pragma config PMDL1WAY = OFF           // Peripheral Module Disable Configuration (Allow multiple reconfigurations)
#pragma config IOL1WAY = OFF            // Peripheral Pin Select Configuration (Allow multiple reconfigurations)
#pragma config FUSBIDIO = OFF           // USB USID Selection (Controlled by Port Function)
#pragma config FVBUSONIO = OFF          // USB VBUS ON Selection (Controlled by Port Function)

// DEVCFG2
#pragma config FPLLIDIV = DIV_2         // PLL Input Divider (2x Divider)
#pragma config FPLLMUL = MUL_16         // PLL Multiplier (16x Multiplier)
#pragma config UPLLIDIV = DIV_2         // USB PLL Input Divider (2x Divider)
#pragma config UPLLEN = ON              // USB PLL Enable (Enabled)
#pragma config FPLLODIV = DIV_8       // System PLL Output Clock Divider (PLL Divide by 8)

// DEVCFG1
#pragma config FNOSC = PRI              // Oscillator Selection Bits (Primary Osc (XT,HS,EC))
#pragma config FSOSCEN = ON             // Secondary Oscillator Enable (Enabled)
#pragma config IESO = ON                // Internal/External Switch Over (Enabled)
#pragma config POSCMOD = HS             // Primary Oscillator Configuration (HS osc mode)
#pragma config OSCIOFNC = OFF           // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_8           // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/8)
#pragma config FCKSM = CSDCMD           // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
#pragma config WDTPS = PS1048576        // Watchdog Timer Postscaler (1:1048576)
#pragma config WINDIS = OFF             // Watchdog Timer Window Enable (Watchdog Timer is in Non-Window Mode)
#pragma config FWDTEN = OFF             // Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls))
#pragma config FWDTWINSZ = WINSZ_25     // Watchdog Timer Window Size (Window Size is 25%)

// DEVCFG0
#pragma config JTAGEN = OFF             // JTAG Enable (JTAG Disabled)
#pragma config ICESEL = ICS_PGx2        // ICE/ICD Comm Channel Select (Communicate on PGEC2/PGED2)
#pragma config PWP = OFF                // Program Flash Write Protect (Disable)
#pragma config BWP = OFF                // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF                 // Code Protect (Protection Disabled)

#include <xc.h> //XC32 prekladac

#define LED1_ANSEL ANSELBbits.ANSB8
#define LED2_ANSEL ANSELBbits.ANSB9
#define LED3_ANSEL ANSELBbits.ANSB10
#define LED4_ANSEL ANSELBbits.ANSB11
#define SW1_ANSEL ANSELBbits.ANSB12
#define SW2_ANSEL ANSELBbits.ANSB13

#define LED1_TRIS TRISBbits.TRISB8
#define LED2_TRIS TRISBbits.TRISB9
#define LED3_TRIS TRISBbits.TRISB10
#define LED4_TRIS TRISBbits.TRISB11
#define SW1_TRIS TRISBbits.TRISB12
#define SW2_TRIS TRISBbits.TRISB13
#define SW3_TRIS TRISDbits.TRISD11
#define SW4_TRIS TRISDbits.TRISD0

#define LED1 LATBbits.LATB8
#define LED2 LATBbits.LATB9
#define LED3 LATBbits.LATB10
#define LED4 LATBbits.LATB11

#define SW1 PORTBbits.RB12
#define SW2 PORTBbits.RB13
#define SW3 PORTDbits.RD11
#define SW4 PORTDbits.RD0

void main() {
    LED1_ANSEL = 0; //dig. pin
    LED2_ANSEL = 0;
    LED3_ANSEL = 0;
    LED4_ANSEL = 0;
    SW1_ANSEL = 0;
    SW2_ANSEL = 0;
    
    LED1_TRIS = 0; //vystup
    LED2_TRIS = 0;
    LED3_TRIS = 0;
    LED4_TRIS = 0;
    SW1_TRIS = 1;  //vstup
    SW2_TRIS = 1;
    SW3_TRIS = 1;
    SW4_TRIS = 1;
    
    while(1) {
        LED1 = 0;
        LED2 = 0;
        LED3 = 0;
        LED4 = 0;
        
        if(SW1 == 0) {
            LED1 = 1;
        }
        
        if(SW2 == 0) {
            LED2 = 1;
        }
        
        if(SW3 == 0) {
            LED3 = 1;
        }
        
        if(SW4 == 0) {
            LED4 = 1;
        }
    }
}