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

Newbee write_eeprom question

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







Newbee write_eeprom question
PostPosted: Sat Feb 26, 2005 9:21 am     Reply with quote

Hi to all!
I want to write integers into memory and after ich button click i want to encrease the value in the memory, and then print the value out..

------------------------------
address 0x2100;


...
short int value;
value=0;
if (input(PIN_D1))
{
value++;
write_eeprom(address,value)
}

What do i have to add so that this can work...
p.s. Now is the value 0 and wenn you click on same button again the memory value is the same. Why?
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sat Feb 26, 2005 10:44 am     Reply with quote

Guest wrote:
Quote:

after ich button click i want to encrease the value in the memory

You define:
short int value;
The size of a short int in CCS is a single bit. (0-1)
So you need to replace it by:
int8 value; // range (0-255)

write_eeprom(address,value) // is plain text
write_eeprom(address,value); // is a proposition

Quote:

What do i have to add so that this can work...

Code:

int8 value;
int8 value_stored;

 while(1)
        {
          if (input(PIN_D1))                  // Need a HIGH 
            {                                       //  Need to debounce
              delay_ms(100);
              value++;
              write_eeprom(address,value);
            }
         
          delay_ms(1000);
          value_stored = read_eeprom(address);
          printf("\r\n %D", value_stored);
        }


This code is just what you ask. Not the best way to do it.
Read and practice the examples provided by CCS.

Humberto
Guest
Guest







PostPosted: Sun Feb 27, 2005 7:09 am     Reply with quote

Thank you i will try it!
I found ex_intee.c file as some example from CCS.

Whats the "best way" to do this ?
Ttelmah
Guest







PostPosted: Sun Feb 27, 2005 7:27 am     Reply with quote

Note also, that an address of '0x2100', is not legitimate for the 'write_eeprom' function. This function talks to the eeprom data memory, which is only 256 bytes long (addresses 0..255). This memory is 'mapped' into the programming space (when you are programming the chip in an external programmer), at address 0x2100 (on some chips - the 16F family in general), but you would only need an address of '0' to talk to this byte.

Best Wishes
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Feb 27, 2005 8:58 am     Reply with quote

Guest wrote:
Quote:

Whats the "best way" to do this ?

The code I posted was only to "satisffy" this:
Quote:

What do i have to add so that this can work...


To "see" how run this code you need to apply a HIGH in PIN_D1 through
a switch or something else. If you do it it with a mechanical switch, you
will realize that every time you press the switch the counter value will
have more than 1 increment because the "bounce" of the internal contacts
of the switch.
To override this will be necesary to add a delay to "wait" until the contacts
stop bouncing and after that you can validate a "steady state". To
implement a debounce software technique you will see that fortunatelly
there are different ways so your question:
Quote:

Whats the "best way" to do this ?

Doesnīt have a single answer, that is one of the reason why C language
is still alive, because it has all that you need to develop what you want
following a logic criteria, depending of your knowlede and creativity. I
have some devices that I made 7 years ago, they are still running fine,
but when I read the code that I wrote, I realize that it need some changes
here and there, and that such function I would do it in that way, etc, etc.
All the codes are perfective, improvable and upgradable.

Donīt worry, every time I read a code I ask myself:
"Whats the "best way" to do this ?" Very Happy

Humberto
Guest
Guest







PostPosted: Sun Feb 27, 2005 4:34 pm     Reply with quote

This is the code am using. I have listed questions under code part.

Code:

#define countdown hour
...
int sec=0,hour=10,day=5,dayset=0;
int1 debounce=0;

#int_TIMER1
TIMER1_isr()
{
  set_timer1(0xF000);
  secs++;
  if (secs==3600)
  {
   secs=0;
   hours--;
  }
 /*
  if (hours==24)
  {
   hours=0;
   days--;
  }
*/
  if (countdown==dayset)
  {
   disable_interrupts(global);
   output_high(PIN_D6);
   for (secs=0;secs<60;secs++)
     delay_ms(100);
   output_high(PIN_D6);

  }
}
void main()
{
   int8 iVal=0, iValS, brTab, brTabS;

   port_b_pullups(TRUE);
   setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
   setup_timer_1(T1_EXTERNAL|T1_DIV_BY_2);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(global);

//--------------------------------------------------------
while(1)
{
    //-- > CONFIRMATION BUTTON-------
    if(INPUT(PIN_D6))
     {
        delay_ms(100);
        brTab++;
        write_eeprom(f_e_a,100);
        //-- close button access for 10 hours
       
   brTabS=read_eeprom(f_e_a);
        printf(displayPUTC,"%D",brTabS);
        displayDO();

     }

    //---FIRST PART OF SECOND BUTTON is activ until first CONFIRMATION click------
    if (INPUT(PIN_D7) && read_eeprom(b_pr)==00)
      {
           printf(displayPUTC,"0");
           displayDO();
           write_eeprom(b_pr,1);
      }
    //--------------------------------------------
   
    else
      {

         iValS=read_eeprom(b_pr);

         if (INPUT(PIN_D7) && read_eeprom(b_pr)==01)
         { 
       //- show rest of countdown time
            printf(displayPUTC,dayset);       //-- not formated
            displayDO();
            write_eeprom(b_pr,2);
         }

         if (INPUT(PIN_D7) && read_eeprom(b_pr)==02)
         {
             //-- show number of clicks on confirmation button
        printf(displayPUTC,read_eeprom(brTab));
             displayDO();
             write_eeprom(b_pr,1);
         }

      }


    } // --while
}




q1.) When you click first time on confirmation button the eeprom value
is encreasing without stop.

q.2) Why can't i solve this tree state button clicks(second button) like in the example above. Do you have better idea to solve this?
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Feb 27, 2005 6:05 pm     Reply with quote

Quote:

q1.) When you click first time on confirmation button the eeprom value
is encreasing without stop.

1)We donīt know your hardware. Pull up/down resistor? etc.
2)A proposition like
Code:
 
if(INPUT(PIN_D6))
  {
    .....
    your stuff
    .....
  }

is expecting a HIGH whenever you push the switch, and when you
release it the input PIN_D6 must be LOW. Try to solve this before
take any action.

3)Divide your code in small tasks, test that each function is running
properly and then join all together according to the function criteria.
Pls try this practice for yourself. Very Happy

Humberto
Guest
Guest







PostPosted: Mon Feb 28, 2005 3:07 am     Reply with quote

1)We donīt know your hardware. Pull up/down resistor? etc.
All of them are pull UP resistors on 16F877 chip...

Im using simulator thefore i can make changes i view them in real time , but i just need to now what is the "right way" to solve this. Thefore i need some help in this part...
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon Feb 28, 2005 4:25 am     Reply with quote

Quote:

All of them are pull UP resistors on 16F877 chip...

1) Only PORTB has pull up resistors. To activate you must enable them.
2) You have the switch connected in PORTD.
3) According to your code you need a pull DOWN. Not a pull UP resistor.

Quote:

Thefore i need some help in this part...

I assume you have a pull DOWN resistor (aprox 10K) in PIN_D6 and a
switch wired to +5V and try this:
Code:

if(input(PIN_D6)) // means if INPUT PIN_D6 is HIGH....
  {
    output_high(PIN_D1);   
  }
else
  {
    output_low(PIN_D1);
  }

This is basic schooling, try to practice and understand the simplest
examples and get some books to learn from.
This way is not easy for you nor for us. Very Happy

Best wishes,

Humberto
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