hello, i'm working on pic16f684 and i need to store my temperature time stamps inside EEPROM
here the code of displaying my temperature and how to store it?
here the code of displaying my temperature and how to store it?
Rich (BB code):
#include <pic.h>
#define DIGIT1 RA0
#define DIGIT2 RA1
#define DIGIT3 RA2
#define ON 0
#define OFF 1
/*
RA5 - Segment a
RC5 - Segment b
RC4 - Segment c
RC3 - Segment d
RC2 - Segment e
RC1 - Segment f
RC0 - Segment g
RA4 - Thermistor
*/
__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \
& UNPROTECT & BORDIS & IESODIS & FCMDIS);
const char LEDDigit[10] = {
0b0000001, // Digit Zero
0b1001111, // Digit One
0b0010010, // Digit Two
0b0000110, // Digit Three
0b1001100, // Digit Four
0b0100100, // Digit Five
0b0100000, // Digit Six
0b0001111, // Digit Seven
0b0000000, // Digit Eight
0b0000100}; // Digit Nine
int Temperature, TempDigit, DisplayPos, D1, j;
int ADCState;
int i, j, d, t, temp;
main()
{
/////////// INIT ////////////
PORTA = 0;
PORTC = 0;
TRISA = 0b010000; // All Bits of PORTA are Outputs except RA4
TRISC = 0; // All Bits of PORTC are Outputs
CMCON0 = 7; // Turn off Comparators
ANSEL = 1 << 4; // RA4 is ADC input
ADCON0 = 0b00001101; // Left justify, Use Vdd, Channel 4 (AN3), Do not start, Turn on
ADCON1 = 0b00010000; // run oscillatr as 8 x prescalar
DisplayPos = 0;
j = 0;
Temperature = 0;
ADCState = 0;
//// MAIN LOOP ////
while(1)
{
/////////// DISPLAY READOUT ///////////
DIGIT1 = OFF;
DIGIT2 = OFF;
DIGIT3 = OFF;
if(DisplayPos == 0) //Light 1st segment
{
TempDigit = Temperature % 10; //Just get "1"s place
RA5 = LEDDigit[TempDigit] >> 6; //Turn on digit
PORTC = LEDDigit[TempDigit];
DIGIT3 = ON;
for(D1=0;D1<414;D1++); //Delay for 7ms
}else if(DisplayPos == 1) //Light 2nd segment
{
TempDigit = Temperature % 100; //Just get "10"s place (strip off "100"s place)
TempDigit = TempDigit / 10; // and convert to "1"s place
RA5 = LEDDigit[TempDigit] >> 6; //Turn on digit
PORTC = LEDDigit[TempDigit];
DIGIT2 = ON;
for(D1=0;D1<400;D1++); //Delay for 7ms
}else //Light 3rd segment
{
TempDigit = Temperature / 100; //Just get "100"s place
RA5 = LEDDigit[TempDigit] >> 6; //Turn on digit
PORTC = LEDDigit[TempDigit];
DIGIT1 = ON;
for(D1=0;D1<400;D1++); //Delay for 7ms
}
DisplayPos = (DisplayPos + 1) % 3; //Next segment
j++;
if(j == 50) //Time to update temp?
{
j = 0;
switch(ADCState)
{
case 0: //Start ADC operation
GODONE = 1;
ADCState = 1;
break;
case 1:
ADCState = 0;
Temperature = ADRESH - 82;
break;
}
}
}
}