#include <p32xxxx.h>
#include <plib.h>

#if 1
//         internal    8    / 2              * 20               / 1 = 80
#pragma config FPLLIDIV = DIV_2, FPLLMUL = MUL_20, FPLLODIV = DIV_1, FWDTEN = OFF
#pragma config POSCMOD = OFF, FNOSC = FRCPLL, FPBDIV = DIV_2
#else
//         external    8    / 2              * 20               / 1 = 80
#pragma config FPLLIDIV = DIV_2, FPLLMUL = MUL_20, FPLLODIV = DIV_1, FWDTEN = OFF
#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_2
#endif

void func(void)
{
    int i;
    unsigned long volatile k = 0;
    while(1)
    {
        for(i=0; i<256; i++)
        {
            k++;
            k++;
            k++;
            k++;
            k++;
            k++;
            k++;
            k++;
        }
        PORTB = (~(k>>12)) & 0xFFFF;
     }
}

main()
{
    // disable JTAG port
    DDPCONbits.JTAGEN = 0;

    TRISA = 0;      // all PORTA as output
    TRISB = 0x00FF; // higher PORTB is output, lower PORTB is input

    SYSTEMConfigPerformance(80000000L);

    func();

} // main
