|
// This is the C code #1 (water sensing controller) for the interactive multimedia installation, 'Ten Worlds: Garden of Life'. #include <16F877A.H> #include <math.h> #fuses HS, NOWDT, NOPROTECT, NOBROWNOUT, NOPUT, NOLVP #use delay(clock=20000000) int i; int mask_portA; int mask_portC; int mask_clr; int mybyteA; int mybyteC; void main(){ while(1){ mask_clr = 00000000; // read input from portA and output to portB for(i=0;i<6;i++){ // loop 6 times output_b(mask_clr); // clear portB mask_portA = pow(2,i); // set mask to 2^i (1,2,4,8,16) mybyteA = input_a(); // read portA and setting value to mybyteA if(mybyteA & mask_portA){ // checking if any pins in portA are high output_high(PIN_D1); // output high dip pin #20 delay_ms(2000); // delay 1 second output_low(PIN_D1); // output low dip pin #20 output_high(PIN_D0); // output high dip pin #19 delay_ms(2000); // delay 1 second output_low(PIN_D0); // output low dip pin #19 while(mybyteA & mask_portA){ // checking if any pins in portA are high output_b(mybyteA); // mirror the input of portA to output portB mybyteA = input_a(); // reseting mybyteA to portA } } } // read input from portC and output to portD for(i=4;i<8;i++){ // loop 4 times output_d(mask_clr); // clear portD mask_portC = pow(2,i); // set mask to 2^i (16,32,64,128) mybyteC = input_c(); // read portC and setting value to mybyteC if(mybyteC & mask_portC){ // checking if any pins in portC are high output_high(PIN_D1); // output high dip pin #20 delay_ms(2000); // delay 1 second output_low(PIN_D1); // output low dip pin #20 output_high(PIN_D0); // output high dip pin #19 delay_ms(2000); // delay 1 second output_low(PIN_D0); // output low dip pin #19 while(mybyteC & mask_portC){ // checking if any pins in portC are high output_d(mybyteC); // mirror the input of portC to output portD mybyteC = input_c(); // reseting mybyteC to portD } } } } }
|