Storing in PIC16F72 Memory ...?

Discussion in 'Programmer's Corner' started by RRITESH KAKKAR, Oct 2, 2014.

  1. RRITESH KAKKAR

    Thread Starter Senior Member

    Jun 29, 2010
    2,831
    89
    Hi,

    I want to store in PIC16F72 Flash memory which should delete after power off.
    Actually my project is counter based using Hitech C.
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,357
    If you want to temporarily save data, use the SRAM data memory.
     
  3. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,500
    380
    hi Ritesh,
    Have you considered a flash memory erase routine at power up.?

    E
     
  4. RRITESH KAKKAR

    Thread Starter Senior Member

    Jun 29, 2010
    2,831
    89
    Hi All nice to see you again,
    Sorry,what..?
     
  5. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,500
    380
    hi,
    You said: Flash memory which should delete after power off.
    Normally Flash is not self erasing, as Mr C' points out its only SRAM data that is lost at power off.

    Can you say which memory type you mean and why do you want to delete/erase flash memory data at power off.?
    E
     
  6. RRITESH KAKKAR

    Thread Starter Senior Member

    Jun 29, 2010
    2,831
    89
    I am sorry, it should be
    I want to make two digit Counter up down saving in PIC16F72 Memory.
     
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    To do this you open up the data sheet for the device and look for the section about accessing the flash directly.

    If all you find is a section on how to read the memory then you need to find another device capable of the function you require.
     
    absf likes this.
  8. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,023
    Good call! Checking the datasheet shows NO internal EEPROM and the program flash can NOT be written by the program so there is no way to store data in non-volatile space. Battery backup for the RAM or a different PIC is in order.

    Good luck.
     
    absf likes this.
  9. RRITESH KAKKAR

    Thread Starter Senior Member

    Jun 29, 2010
    2,831
    89
    Hello,
    PIC16f877A has internal EEPROM. can we make two counter from one micro controller of two digit each..?
     
  10. RRITESH KAKKAR

    Thread Starter Senior Member

    Jun 29, 2010
    2,831
    89
    Hello,
    PIC16f877A has internal EEPROM. can we make two counter from one micro controller of two digit each..?
     
  11. adam555

    Active Member

    Aug 17, 2013
    858
    39
    I think the HI-TECH C functions you are looking for are eeprom_write(address, value) and eeprom_read(address).
     
  12. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    Also think about the write endurance, you cant possibly expect the eeprom to last more than a few hundred thousand overwrites. If you need to do reliable storage of last state then make a capacitor backup such that when main power fails you trigger an interrupt and store the last value in eeprom. The cap needs to be big enough to provide charge for the write cycle with generous overhead.
    Or just use an FRAM.
     
  13. RRITESH KAKKAR

    Thread Starter Senior Member

    Jun 29, 2010
    2,831
    89
    Code (Text):
    1.  #include <htc.h>
    2. #include <stdio.h>
    3.  
    4. __CONFIG( BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS & CP_OFF );
    5.  
    6. #define _XTAL_FREQ 20000000
    7. char data[12]={0xDE,0X50,0b10111010,0b11111000,0b01110100,0b11101100,0b11101110,0b01011000,0b11111110,0b11111100} ;
    8. main()
    9.     {
    10.     TRISB = 0 ;
    11.     TRISC = 0 ;
    12. ADCON0=0X00;
    13. ADCON1=0B11111111;
    14. TRISA = 0b11111100 ;
    15. __delay_ms(500);
    16. unsigned char a=0;
    17.     while(1){
    18.  
    19. PORTA=0b00000010;//digit one multiplex
    20. PORTB=data[a];// counter loaded value
    21. __delay_ms(10);
    22.  
    23.  
    24. PORTA=0b00000001;//digit one multiplex
    25. PORTB=data[0]; // just used for test working fine or not
    26. __delay_ms(10);
    27.  
    28.  
    29.  
    30. if(RA2==1){
    31.  
    32. __delay_ms(400);
    33. a=a+1;
    34.  
    35.  
    36. }
    37.   if(RA3==1){
    38.  
    39. __delay_ms(400);
    40. a=a-1;
    41.  
    42. }
    43.  
    44.         }
    45.     }
    46.  
    Hello,

    I am using these code connected with seven segment display multiplex is working fine.
    but i want to increment and decrement the counter as per switch.
     
  14. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,675
    2,722
    I use "write-leveling" protocols to solve this problem...i.e I distribute the writes throughout the entire EEROM so as to increase the write endurance.

    For instance, suppose I have 256 bytes of EE, and only 8 bytes of data to be stored. Each write occurs at the last write address + 8, then wraps around at the top. I use a checksum or time stamp to know which is the active record. In doing this, the write endurance will be multiplied by the EEROM size divided by the record size.

    I also only process a write action only when the persistent data actually changes.
     
  15. RRITESH KAKKAR

    Thread Starter Senior Member

    Jun 29, 2010
    2,831
    89
    job done..



    Code (C):
    1. #include <htc.h>
    2. #include <stdio.h>
    3.  
    4. __CONFIG( BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS & CP_OFF );
    5.  
    6. #define _XTAL_FREQ 20000000
    7. char data[12]={0xDE,0X50,0xBA,0XF8,0X74,0XEC,0XEE,0X58,0XFE,0XFC} ;
    8. main()
    9.     {
    10.     TRISB = 0 ;
    11.     TRISC = 0 ;
    12. ADCON0=0X00;
    13. ADCON1=0B11111111;
    14. TRISA = 0b11111100 ;
    15. __delay_ms(500);
    16. unsigned char a=0;
    17. unsigned char div=0;
    18. unsigned char rem=0;
    19.     while(1){
    20. rem = a%10;
    21. PORTA=0b00000010;
    22. PORTB=data[rem];
    23. __delay_ms(10);
    24.  
    25. div=a/10;
    26. PORTA=0b00000001;
    27. PORTB=data[div];
    28. __delay_ms(10);
    29.  
    30. if(RA2==1){
    31. __delay_ms(80);
    32. a=a+1;
    33. if(a>99){
    34. a=99;
    35. }
    36.  
    37. }
    38.  
    39.  
    40.   if(RA3==1){
    41. __delay_ms(80);
    42. a=a-1;
    43. if(a>99){
    44. a=0;
    45. }
    46. }
    47.  
    48.                 }
    49.                 }
    50.            
     
Loading...