CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

help me for starting from last state parameter

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

help me for starting from last state parameter
PostPosted: Sun Nov 27, 2011 2:07 am     Reply with quote

Hello all

I've made a counter which has a button to give the parameter and another for counting total. Its working.

But I want to implement
once the power off and on again system is starting from last state. As example
I change the parameter to 8 and get the value of total is 7543 . If I off the circuit and ON again, I want to start from here.

Expecting your valued advice and guideline with example

My circuit is Building with 16f877a and a LCD
As reference, here is my code:
Code:

#include <16F877A.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#include <flex_LCD420.c>   

 unsigned int8 BSize=0;  // using this variable to change parameter

void main()
{
   
unsigned int8 status_1,status_2,count;
unsigned int32 total=0;          // variable to count of total

lcd_init();

// Clear the LCD.
printf(lcd_putc, "\f");
delay_ms(50);

while(true)
            // this block of code for changing the BSize
  {
   if (!input(pin_D0)&& status_2==0) //input push button with switch debounce
   
   {status_2 = 1;
    delay_ms(2);
   BSize ++;}
   if(BSize == 13)
   {BSize = 1;}
    if (input(pin_D0))
    {
    status_2=0;}

     lcd_gotoxy(8,4);
     printf(lcd_putc, "%02u",BSize);
     
      // this block of code for counting the total
     
   if (!input (PIN_D4) && status_1==0) //input push button with switch debounce
     {
      status_1=1;
      delay_ms(2);
      count++;
      total=count+BSize;
     
     lcd_gotoxy(14, 4);
     printf(lcd_putc, "%Lu",total);
     }

    if (input (PIN_D4))
    {
    status_1=0;
    }
  }
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Nov 27, 2011 7:45 am     Reply with quote

We are not going to do your project for you, but here are some tips:
The PIC16F877A is very old and not recommended for new designs. Newer models exist with more memory, more advanced options, less power AND cheaper. For example:
PIC16F877A at 1000 pieces = $4.41
PIC16F887 at 1000 pieces = $2.05

A debounce delay of 2ms is short. It might work with your switches, but if you have another type of switches in the future or the switches become older your circuit might fail for unknown reasons.
Here is a nice article with practical data: http://www.ganssle.com/debouncing.htm

Saving the counter value requires some non-volatile memory. Using the internal EEPROM of the PIC seems the most logical solution but beware of some drawbacks:
- Writing to EEPROM is relative slow, 4ms per byte.
- EEPROM wears out. Every time you write to a cell it becomes a little bit more damaged until finally it is broken. For the PIC16F877A this is garuanteed a minimum of 100k, typical 1 million writes per cell.

Workarounds are:
- Write only every 10 counts.
- Write a max. of 100k to 1 cell and then advance to the next cell.
More info: http://www.ccsinfo.com/forum/viewtopic.php?t=31778
- Write only on power down (requires a larger capacitor on power pins and a 'power sense' input).
http://www.ccsinfo.com/forum/viewtopic.php?t=38936
http://www.ccsinfo.com/forum/viewtopic.php?t=44147&view=previous
http://www.ccsinfo.com/forum/viewtopic.php?t=44247&view=next
Many more articles to be found in this forum and internet.
- Use another non-volatile storage medium, for example the spare RAM bytes in a Real Time Clock chip like the DS1307. Or use an external FRAM chip, these have no write limit and are very fast in write speed.
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

PostPosted: Mon Nov 28, 2011 2:35 am     Reply with quote

Quote:
We are not going to do your project for you, but here are some tips:


Many thank ckielstra

I never expect that some one write down my code or complete the project.

I just expect from the experts to show me the guideline and advice on some terms.

I'm a new born baby as I am working with this only for 4 months and start with 16f877a so ..................................

Expecting more guideline and advice on this issue
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group