Temperature store data

Discussion in 'Embedded Systems and Microcontrollers' started by lizzy, Apr 12, 2010.

  1. lizzy

    Thread Starter New Member

    Apr 12, 2010
    4
    0
    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?


    Code ( (Unknown Language)):
    1. #include <pic.h>
    2.  
    3. #define    DIGIT1    RA0    
    4. #define    DIGIT2    RA1    
    5. #define     DIGIT3    RA2    
    6. #define    ON            0
    7. #define    OFF        1
    8.  
    9. /*
    10. RA5 - Segment a
    11. RC5 - Segment b
    12. RC4 - Segment c
    13. RC3 - Segment d
    14. RC2 - Segment e
    15. RC1 - Segment f
    16. RC0 - Segment g
    17.  
    18. RA4 - Thermistor
    19. */
    20.  
    21. __CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \
    22.   & UNPROTECT & BORDIS & IESODIS & FCMDIS);
    23.  
    24.  
    25. const char LEDDigit[10] = {
    26.     0b0000001,                  //  Digit Zero
    27.     0b1001111,                  //  Digit One
    28.     0b0010010,                  //  Digit Two
    29.     0b0000110,                  //  Digit Three
    30.     0b1001100,                  //  Digit Four
    31.     0b0100100,                  //  Digit Five
    32.     0b0100000,                  //  Digit Six
    33.     0b0001111,                  //  Digit Seven
    34.     0b0000000,                  //  Digit Eight
    35.     0b0000100};                 //  Digit Nine
    36.    
    37.  
    38. int Temperature, TempDigit, DisplayPos, D1, j;
    39. int ADCState;
    40.  
    41. int i, j, d, t, temp;
    42. main()
    43. {
    44.     ///////////  INIT  ////////////
    45.    
    46.     PORTA = 0;
    47.     PORTC = 0;
    48.     TRISA = 0b010000;              //  All Bits of PORTA are Outputs except RA4
    49.    TRISC = 0;                   //  All Bits of PORTC are Outputs
    50.    
    51.    CMCON0 = 7;                //  Turn off Comparators
    52.    ANSEL = 1 << 4;            //  RA4 is ADC input
    53.    ADCON0 = 0b00001101;            //  Left justify, Use Vdd, Channel 4 (AN3), Do not start, Turn on
    54.    ADCON1 = 0b00010000;            //  run oscillatr as 8 x prescalar
    55.    
    56.    DisplayPos = 0;
    57.    j = 0;
    58.    Temperature = 0;
    59.    ADCState = 0;
    60.  
    61.  
    62.    ////  MAIN LOOP  ////
    63.    
    64.    while(1)
    65.    {
    66.        ///////////  DISPLAY READOUT  ///////////
    67.        
    68.        DIGIT1 = OFF;
    69.        DIGIT2 = OFF;
    70.        DIGIT3 = OFF;
    71.        
    72.         if(DisplayPos == 0)                                    //Light 1st segment
    73.         {
    74.             TempDigit = Temperature % 10;                    //Just get "1"s place
    75.             RA5 = LEDDigit[TempDigit] >> 6;                //Turn on digit
    76.             PORTC = LEDDigit[TempDigit];
    77.             DIGIT3 = ON;
    78.             for(D1=0;D1<414;D1++);                            //Delay for 7ms
    79.            
    80.         }else if(DisplayPos == 1)                            //Light 2nd segment
    81.         {
    82.             TempDigit = Temperature % 100;                //Just get "10"s place (strip off "100"s place)
    83.             TempDigit = TempDigit / 10;                    //   and convert to "1"s place
    84.             RA5 = LEDDigit[TempDigit] >> 6;                //Turn on digit
    85.             PORTC = LEDDigit[TempDigit];
    86.             DIGIT2 = ON;
    87.             for(D1=0;D1<400;D1++);                            //Delay for 7ms
    88.         }else                                                        //Light 3rd segment
    89.         {    
    90.             TempDigit = Temperature / 100;                //Just get "100"s place
    91.             RA5 = LEDDigit[TempDigit] >> 6;                //Turn on digit
    92.             PORTC = LEDDigit[TempDigit];
    93.             DIGIT1 = ON;
    94.             for(D1=0;D1<400;D1++);                            //Delay for 7ms
    95.         }
    96.  
    97.         DisplayPos = (DisplayPos + 1) % 3;                //Next segment
    98.        
    99.        
    100.         j++;
    101.         if(j == 50)                                                //Time to update temp?
    102.         {
    103.             j = 0;
    104.        
    105.             switch(ADCState)
    106.             {
    107.                 case 0:                        //Start ADC operation
    108.                     GODONE = 1;
    109.                     ADCState = 1;
    110.                     break;
    111.                 case 1:
    112.                     ADCState = 0;
    113.                     Temperature = ADRESH - 82;
    114.                     break;
    115.             }
    116.         }
    117.     }
    118. }
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    I don't use C but from a quick google search it seems that the below might be useful:
    internal_eeprom.c
     
    lizzy likes this.
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Hi
    I guess you use HI-TECH C compiler, and then you can use EEPROM_READ, and EEPROM_WRITE. You find more about the functions in the manual
    Code ( (Unknown Language)):
    1.  
    2. [LEFT][FONT=NimbusMonL-Regu][SIZE=2][FONT=NimbusMonL-Regu][SIZE=2]#include <htc.h>[/SIZE][/FONT]
    3. [SIZE=2][FONT=NimbusMonL-Regu]void eetest(void){[/FONT][/SIZE]
    4. [SIZE=2][FONT=NimbusMonL-Regu]unsigned char value = 1;[/FONT][/SIZE]
    5. [SIZE=2][FONT=NimbusMonL-Regu]unsigned char address = 0;[/FONT][/SIZE][/SIZE][/FONT][/LEFT][FONT=NimbusMonL-Regu][SIZE=2]
    6.  
    7. [SIZE=2][FONT=NimbusMonL-Regu]// Initiate writing [/FONT][/SIZE]
    8. [/SIZE][/FONT][LEFT][FONT=NimbusMonL-ReguObli][SIZE=2][FONT=NimbusMonL-ReguObli][SIZE=2]value [/SIZE][/FONT][/SIZE][/FONT][FONT=NimbusMonL-Regu][SIZE=2][FONT=NimbusMonL-Regu][SIZE=2]to [/SIZE][/FONT][/SIZE][/FONT][FONT=NimbusMonL-ReguObli][SIZE=2][FONT=NimbusMonL-ReguObli][SIZE=2]address[/SIZE][/FONT][/SIZE][/FONT][FONT=NimbusMonL-ReguObli][SIZE=2]
    9. [LEFT][/LEFT][/SIZE][LEFT][/left][/FONT][LEFT][FONT=NimbusMonL-Regu][SIZE=2][FONT=NimbusMonL-Regu][SIZE=2]EEPROM_WRITE(address,value);[/SIZE][/FONT]
    10. [SIZE=2][FONT=NimbusMonL-Regu]// wait for end-of-write before EEPROM_READ[/FONT][/SIZE]
    11. [/SIZE][/FONT][B][FONT=NimbusMonL-Bold][SIZE=2][FONT=NimbusMonL-Bold][SIZE=2]while(WR) continue;[/SIZE][/FONT][/SIZE][/FONT][/B][FONT=NimbusMonL-Bold][SIZE=2]
    12. [/SIZE][/FONT][FONT=NimbusMonL-Regu][SIZE=2][FONT=NimbusMonL-Regu][SIZE=2]// read from EEPROM at [/SIZE][/FONT][/SIZE][/FONT][/LEFT][FONT=NimbusMonL-Regu][SIZE=2][FONT=NimbusMonL-Regu][SIZE=2]
    13. [/size][/font][/size][/font][/LEFT][FONT=NimbusMonL-Regu][SIZE=2][FONT=NimbusMonL-Regu][SIZE=2]
    14. [/SIZE][/FONT][/SIZE][/FONT][LEFT][FONT=NimbusMonL-ReguObli][SIZE=2][FONT=NimbusMonL-ReguObli][SIZE=2]address[/SIZE][/FONT][/SIZE][/FONT][FONT=NimbusMonL-ReguObli][SIZE=2]
    15. [LEFT][/LEFT][/SIZE][LEFT][/left][/FONT][LEFT][FONT=NimbusMonL-Regu][SIZE=2][FONT=NimbusMonL-Regu][SIZE=2]value = EEPROM_READ(address);[/SIZE][/FONT]
    16. [SIZE=2][FONT=NimbusMonL-Regu]}[/FONT][/SIZE][/SIZE][/FONT][/LEFT][FONT=NimbusMonL-Regu][SIZE=2]
    17. [/SIZE][/FONT][/LEFT]

     
    lizzy likes this.
  4. lizzy

    Thread Starter New Member

    Apr 12, 2010
    4
    0
    sir, how to include this code inside my code?
     
Loading...