// remote.c // Wichit Sirichote // Circuit for experimenting with Easy-Server // PIC16F84 connects Easy-Server via serial port // with 9600 8n1 // the i/o for testing is as follows; // RA0 LED1 active low // RA1 LED2 active low // RB0 K1 12V relay active high // RB1 sw1 momentary switch normally high // RB2 sw2 same as RB1 // serial port 9600 8n1 // RB6 TxD // RB5 RxD unsigned int command; #define LED1 PIN_A0 #define LED2 PIN_A1 #define K1 PIN_B0 #define sw1 PIN_B1 #define sw2 PIN_B2 #include print_help(){ puts("command function"); puts(" 1 set LED1"); puts(" 2 clr LED1"); puts(" 3 set LED2"); puts(" 4 clr LED2"); puts(" 5 on K1"); puts(" 6 off K1"); puts(" 7 read sw1"); puts(" 8 read sw2"); puts(" ? help"); } send_ok(){ putc(7); // send bell back printf("\n\rcommand %c ok",command); } service1(){ output_low(LED1); send_ok(); } service2(){ output_high(LED1); send_ok(); } service3(){ output_low(LED2); send_ok(); } service4(){ output_high(LED2); send_ok(); } service5(){ output_high(K1); send_ok(); } service6(){ output_low(K1); send_ok(); } main() { setup_counters(RTCC_INTERNAL,RTCC_DIV_2); output_high(LED1); output_high(LED2); output_low(K1); while(1){ command = getc(); switch(command){ case 13: printf(" REMOTE[RS232]\n\n\r"); break; case '?': print_help(); break; case '1': service1(); break; case '2': service2(); break; case '3': service3(); break; case '4': service4(); break; case '5': service5(); break; case '6': service6(); break; case '7': printf("\n\rsw1=%c",input(sw1)+0x30); break; case '8': printf("\n\rsw2=%c",input(sw2)+0x30); break; } } }