#define BIT0 (1 << 0) #define BIT1 (1 << 1) #define BIT2 (1 << 2) #define BIT3 (1 << 3) #define BIT4 (1 << 4) #define BIT5 (1 << 5) #define BIT6 (1 << 6) #define BIT7 (1 << 7) static unsigned char i; // Main clock static signed int x0, x1, x2; static signed int y0, y1, y2; void main(void) { // Calibrate internal oscillator asm { bsf STATUS, RP0 call $3FF movwf OSCCAL bcf STATUS, RP0 } OPTION_REG.NOT_GPPU = 0; // Enable pull-ups on GPIOs OPTION_REG.T0CS = 0; // Clock from Fosc/4 OPTION_REG.PSA = 1; // Prescaler to WDT (not TMR0) TRISIO = ~(BIT0 | BIT1 | BIT2); // GPIOs 0 and 1 as outputs WPU = (BIT0 | BIT1 | BIT2); // Enable pull-ups // Seed oscillators x0 = 0; x1 = 11; y0 = 177; y1 = 181; for (i = 0; ; i++) { unsigned char val = 0; if (i == 0) { val |= BIT0; x2 = (x1 << 1) - (x1 >> 7) - x0; x0 = x1; x1 = x2; y2 = (y1 << 1) - (y1 >> 7) - y0; y0 = y1; y1 = y2; } if (i < (x2 + 66)) { val |= BIT1; } if (i < (y2 + 66)) { val |= BIT2; } GPIO = val; } }