//#define HS_Osc //The board has the High Speed = 20MHz Crystal Oscillator //#include "16F876a.h" // device dependent interrupt definitions //#pragma config|= 0x3F32 //HS Ocs //the following line is to not overwrite the PIC boot loader part in the program memory #pragma origin 4 #define RELAY PORTA.1 #define OFF 0 #define ON 1 //RX routine for receiving data over the Serial Port unsigned char ReadByte(void) { // wait to receive character while(!RCIF); // return received character return RCREG; } void main(void) { unsigned char command; INTCON = 0x0;// Disable inerupt CMCON = 0x07;// Comparators Off ADCON1 = 0x06;// Port as Digital IO TRISA = 0b.0000.0000;//0 = Output, 1 = Input TRISB = 0b.1110.1111;// All as input, except LED pin TRISC = 0b.1000.0000;//RC7 is RX which is input and RC6 is TX which is output // RX Setting, 8bit, enable receive, RCSTA = 0x90; // TX Setting, 8bit, Asynchronous mode, High speed TXSTA = 0x24; // Set Baudrade - 9600 (from datasheet baudrade table) SPBRG = 129; while(1) { command = ReadByte();//receive a character if(command == 27) { //if the character is TV ON, 0x27 RELAY = ON; //Turning ON the pin that is connected to the relay } else if (command == 28) { RELAY = OFF; } } }