// Self-programming analog computer for chaotic Sprott Systems // Version 1.0 // Glen Kleinschmidt Feb 2016 // www.glensstuff.com #include <16f84.h> #use delay(clock=2000000) #use standard_io(A) #use standard_io(B) #FUSES NOWDT, PUT, NOPROTECT, XT // RA0 - initial condition // RA1 - relay power // RA2 - serial clock // RA3 - serial data // RB0 - system increment // RB1 - system decrement // RB2 - initial condition / reset int shift; int word; int16 system = 0; void strobe_serial_clock() { output_high(pin_A2); output_low(pin_A2); } void relay() // Serially shift decoded relay activation data { const char relay[] = {161, 8, 4, 32, 128, 16, 0, 16, // System A (0) 72, 44, 0, 64, 2, 1, 0, 16, // System B (1) 24, 44, 0, 64, 2, 1, 0, 16, // System C (2) 18, 9, 32, 64, 16, 9, 0, 0, // System D (3) 20, 44, 0, 0, 130, 0, 64, 16, // System E (4) 20, 64, 4, 32, 4, 129, 0, 0, // System F (5) 18, 64, 0, 2, 130, 0, 2, 1, // System G (6) 0, 52, 32, 64, 4, 128, 16, 0, // System H (7) 65, 0, 128, 64, 16, 129, 16, 0, // System I (8) 65, 192, 0, 0, 19, 4, 2, 1, // System J (9) 0, 42, 2, 64, 2, 32, 16, 0, // System K (10) 20, 0, 9, 128, 64, 0, 128, 8, // System L (11) 24, 0, 2, 0, 130, 0, 10, 4, // System M (12) 34, 0, 96, 64, 32, 128, 3, 2, // System N (13) 18, 0, 4, 64, 8, 1, 20, 0, // System O (14) 65, 64, 16, 32, 128, 0, 18, 0, // System P (15) 65, 0, 2, 64, 2, 65, 32, 0, // System Q (16) 68, 0, 32, 24, 16, 131, 0, 0, // System R (17) 34, 0, 0, 69, 128, 0, 16, 16}; // System S (18) for (word=0; word<8; word++) { for (shift=0; shift<8; shift++) { output_bit(pin_A3, bit_test(relay[(system*8)+(7-word)], 7-shift)); strobe_serial_clock(); } } } void led() // Serially shift decoded 16-segment LED-display data { const int16 led[] = {975, // System A (0) 19007, // System B (1) 243, // System C (2) 18495, // System D (3) 1011, // System E (4) 451, // System F (5) 763, // System G (6) 972, // System H (7) 18483, // System I (8) 124, // System J (9) 12736, // System K (10) 240, // System L (11) 5324, // System M (12) 9420, // System N (13) 255, // System O (14) 967, // System P (15) 8447, // System Q (16) 9159, // System R (17) 955}; // System S (18) for (shift=0; shift<16; shift++) { output_bit(pin_A3, bit_test(led[system], 15-shift)); strobe_serial_clock(); } } void set() { output_high(pin_A0); // Initial condition relays on output_high(pin_A1); // Programming relay power off delay_ms(20); relay(); led(); output_low(pin_A1); // Programming relay power on delay_ms(20); output_low(pin_A0); // Initial condition relays off delay_ms(300); // Delay for switch de-bounce } void MAIN() { output_low(pin_A2); // Shift register clock low set(); // Set to default system loop: if ((!input(pin_B0)) & (system<18)) // Detect system increment push button { system++; set(); } if ((!input(pin_B1)) & (system>0)) // Detect system decrement push button { system--; set(); } if (!input(pin_B2)) // Detect initial condition/reset push button { output_high(pin_A0); delay_ms(300); output_low(pin_A0); } goto loop; }