///////////////////////////////////////////////////////////////////////// //// Project_1 | Heamchand Subryan //// //// Using two temperature sensor inputs and store their //// //// values in EEPROM ///// //// This program reads and writes to internal eeprom //// //////////////////////////////////////////////////////////////////////////// #include <16F877.h> // match to your chip #include // include to use "printf" statement #fuses HS,NOPROTECT,NOLVP,NOWDT // setup fuses #use delay(clock=20000000) // match to crystal speed #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // setup serial port // The following initializes the first 4 locations of the data EERPOM // using the #ROM directive #rom 0x2100={1,1,7,7} main() { byte poll,i,j,address,value,a2dvalue; // create variables set_tris_d(0b00000000); // setup PORTD for TestLED setup_port_a(ALL_ANALOG); //Set up Port A as A2D setup_adc(adc_clock_internal); //Set up clock for ADC set_adc_channel( 0 ); //Set the channel/Pin Number for ADC a2dvalue = read_adc(); address = 0; while (TRUE) { output_high(pin_d1); // blink TestLED to see that PIC is looping delay_ms(1000); output_low(pin_d1); delay_ms(1000); output_high(pin_d1); delay_ms(1000); output_low(pin_d1); delay_ms(1000); //set a conditional statement which produces data at opposite ends. if (a2dvalue <= 50) // if a2dvalue is < 50, blink led and write to eeprom { OUTPUT_B(0b00001111); } else if (a2dvalue >= 128) // if a2dvalue is > 128 blink led and write to eeprom { OUTPUT_B(0b11110000); } // Wait until polled before advancing // submitting data via analog and writing it to EEPROM: for(address=0; address<=255; address++) // bytes of the data EEPROM in hex { write_eeprom(address, a2dvalue); // writes values to eeprom } } }