// File: UrineControl.c // // // MIT Media Lab // December, 05 2002 // // #case #include <16F877.H> // Configure PIC to use: HS clock, no Watchdog Timer, // no code protection, enable Power Up Timer // #fuses HS,NOWDT,NOPROTECT,PUT // Tell compiler clock is 20MHz. This is required for delay_ms() // and for all serial I/O (such as printf(...). These functions // use software delay loops, so the compiler needs to know the // processor speed. // #use DELAY(clock=20000000) // // #use fast_io(A) #use fast_io(B) #use fast_io(c) #use fast_io(d) #use fast_io(e) // Pins for piezscan // #define RS232_XMT PIN_C6 // (output) RS232 serial transmit #define RED_LED PIN_D7 // (output) Red LED (low true) #define RS232_RCV PIN_C7 // (input) RS232 serial receive #define PIEZO1 PIN_B0 // (input) piezo mic #define PIEZO2 PIN_B1 // (input) piezo mic #define PIEZO3 PIN_B2 // (input) piezo mic #define PIEZO4 PIN_B3 // (input) piezo mic #define PIEZO5 PIN_B4 // (input) piezo mic #define PIEZO6 PIN_B5 // (input) piezo mic #define PIEZO7 PIN_B6 // (input) piezo mic #define PIEZO8 PIN_B7 // (input) piezo mic #define PIEZO9 PIN_A0 // (input) piezo mic #define PIEZO10 PIN_A1 // (input) piezo mic #define PIEZO11 PIN_A2 // (input) piezo mic #define PIEZO12 PIN_A3 // (input) piezo mic #define PIEZO13 PIN_A4 // (input) piezo mic #define PIEZO14 PIN_A5 // (input) piezo mic #define PIEZO15 PIN_E0 // (input) piezo mic #define PIEZO16 PIN_E1 // (input) piezo mic // Macros to simplify I/O operations // #define RED_LED_ON output_low(RED_LED) #define RED_LED_OFF output_high(RED_LED) // Default tri-state port direction bits: all PORT B bits are // output except for RC232_RCV (port-Cbit 7). // port d output except d7 which is input for red led. #define IRX_A_TRIS 0b111111 #define IRX_B_TRIS 0b11111111 #define IRX_C_TRIS 0b10000000 #define IRX_D_TRIS 0b00000000 #define IRX_E_TRIS 0b011 // // Inform printf() and friends of the desired baud rate // and which pins to use for serial I/O. // #use rs232(baud=9600, xmit=RS232_XMT, rcv=RS232_RCV) //Global Varibles long state_packet1; long state_packet2; long i; //Functions void state_test() { state_packet1 = 0; state_packet2 = 0; for (i=0; i<800; i++) { if(input(PIEZO1)) state_packet1 |= 0b00000001; if(input(PIEZO2)) state_packet1 |= 0b00000010; if(input(PIEZO3)) state_packet1 |= 0b00000100; if(input(PIEZO4)) state_packet1 |= 0b00001000; if(input(PIEZO5)) state_packet1 |= 0b00010000; if(input(PIEZO6)) state_packet1 |= 0b00100000; if(input(PIEZO7)) state_packet1 |= 0b01000000; if(input(PIEZO8)) state_packet1 |= 0b10000000; if(input(PIEZO9)) state_packet2 |= 0b00000001; if(input(PIEZO10)) state_packet2 |= 0b00000010; if(input(PIEZO11)) state_packet2 |= 0b00000100; if(input(PIEZO12)) state_packet2 |= 0b00001000; if(input(PIEZO13)) state_packet2 |= 0b00010000; if(input(PIEZO14)) state_packet2 |= 0b00100000; if(input(PIEZO15)) state_packet2 |= 0b01000000; if(input(PIEZO16)) state_packet2 |= 0b10000000; } return; } void main() { // since we've declared #use fast_io(B) (above), we MUST // include a call to set_tris_b() at startup. // set_tris_a(IRX_A_TRIS); set_tris_b(IRX_B_TRIS); set_tris_c(IRX_C_TRIS); set_tris_d(IRX_D_TRIS); set_tris_e(IRX_E_TRIS); RED_LED_ON; // reality check at startup delay_ms(200); RED_LED_OFF; printf("Start up successful \r\n"); while(1) { state_test(); printf("%2x%2x \r\n", state_packet2, state_packet1); // print to serial port } }