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

write / read eeprom -- integers
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 27, 2005 12:37 pm     Reply with quote

Not sure exactly what task you're talking about. His complaint
was that he couldn't write numbers beyond 0-10 to his LCD, which
is a pretty weird complaint. However, it just dawned on me that
he was probably just sending hex values to the LCD, such as
00 01 02 03, etc., and his LCD is only 20 columns wide, and
it ran off the end of the row after 10 hex chars. In other words,
it wasn't an eeprom problem at all, it was a newbie problem.

With reference to your question, the following thread contains a demo
program for writing a couple bytes to data eeprom and reading them back.
http://www.ccsinfo.com/forum/viewtopic.php?t=17590&highlight=writeeeprom
Guestt
Guest







PostPosted: Mon Mar 28, 2005 4:12 am     Reply with quote

Forgetting for a moment that you are going to wear-out the EEPROM quickly with your code...--------
i need to write / save each value (number) after click and display this value on LCD. Each button click will replace old value and write the new one on the same place ( 1,2.. 500 ). If i read the text above then im doing something wrong.
--------
he was probably just sending hex values to the LCD
--------
If this is the problem then how would you save / display 500 presses
on button...


Manfred
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 28, 2005 5:28 pm     Reply with quote

This program will display the number of times a button has been
pushed. It writes the count to eeprom, and if the PIC is powered-down,
and then powered back up, it will restore the count value to the
previously saved value. I think this is what you want to do,
but I really don't know. Anyway, this should give you some ideas.
Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
//#use rs232(baud = 9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#include <lcd.c>

#ROM 0x2100 = {0x00}     // Initialize EEPROM address 0 = 0x00.

#define BUTTON_PIN  PIN_B0   // This pin must have a pull-up.
#define DEBOUNCE_PERIOD_IN_MS  10
#define DEBOUNCE_COUNT  2

void wait_for_keypress(void);

//====================================
void main()
{
int8 count;

port_b_pullups(TRUE);

lcd_init();

// Read count that was stored in EEPROM and display it.
count = read_eeprom(0);
lcd_gotoxy(1,1);
printf(lcd_putc, "%u  ", count);


while(1)
  {
   wait_for_keypress();
   count++;
   write_eeprom(0, count);

   lcd_gotoxy(1,1);
   printf(lcd_putc, "%u  ", count);
  }

}
//==================================

void wait_for_keypress(void)
{
char count;

// First, wait for the button to be released.   With the debounce
// values as given above, the button must be in the "up" state
// for two consecutive readings, spaced 10 ms apart.

count = 0;

while(1)
  {
   if(input(BUTTON_PIN) == 1)
      count++;
   else
      count = 0;
   
   if(count == DEBOUNCE_COUNT)
      break;

   delay_ms(DEBOUNCE_PERIOD_IN_MS);
  }

// Now that the button is up, wait until the user presses it.
// In order for the keypress to be considered valid, based
// on the debounce values listed at the beginning of the
// program, the button must be held down for two consecutive
// readings, spaced 10 ms apart.

count = 0;

while(1)
  {
   if(input(BUTTON_PIN) == 0)
      count++;
   else
      count = 0;
   
   if(count == DEBOUNCE_COUNT)
      break;

   delay_ms(DEBOUNCE_PERIOD_IN_MS);
  }

}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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