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 CCS Technical Support

16f877 eeprom problem

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



Joined: 29 Apr 2009
Posts: 3

View user's profile Send private message

16f877 eeprom problem
PostPosted: Wed May 06, 2009 8:30 am     Reply with quote

Hi! I'm having some problems getting data from a function "bgetc" to an array "Log" and then write it down to the 16f877s internal eeprom. I know the LCD is working and I can get the string "Temp" out on the lcd, but I can't get the buffer-data out on the lcd for some reason. I would very much appreciate any feedback I can get!

Code:
#include <16F877.H>
#device *=16
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 12M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#org 0x1F00, 0x1FFF void loader16F877(void) {} //for the 8k 16F876/7

#include <flex_lcd.c>

#define BUFFER_SIZE 4
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;

#int_rda
void serial_isr() {
   int t;
   
   
   buffer[next_in]=getc();
   t=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;
   if(next_in==next_out)
     next_in=t;           // Buffer är full!
}

#define bkbhit (next_in!=next_out)

BYTE bgetc() {
   BYTE c;//

   while(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
}

void main() {

   int a=0;
   int j=0;
   int8 k;
   int8 buffer[5];
   
   int8 q;
   
   BYTE Log[5];
   lcd_init();  // Call lcd_init...
   enable_interrupts(int_rda);
   enable_interrupts(global);

   while(1) {
     
      lcd_putc("\f");
      lcd_putc("Temp:");  // put "Temp:" on LCD
      while(bkbhit)
     
     
      if (a==10)     // an if-case to save every 10:th value to a log
         {
            Log[j] = bgetc();  // save the value from the bgetc function to the array Log[j]
            j++;               // increment the J variable to get to next poss in the array
            if(j > 4)j =0;     // reset the counter once you reach the end of the array
            a=0;               // reset the a variable to be able to save the next "10:th" value
     
            for(k = 0; k < sizeof(Log); k++)   // write values in the array "Log" to the eeprom mem. pos 0-5 
            write_eeprom(k, Log[k]);
     
            for(k = 0; k < sizeof(Log); k++)   // read the values in eeprom (mem. pos) to the array "buffer"
            buffer[k] = read_eeprom(k);
     
            if (j==4)     // if the array (Log) is full, then print the values with a 2 sec delay on the LCD
            {
               for (q=0;q==4;q++)
               {
               lcd_putc(buffer[q]);  // print the array to LCD
              delay_ms(2000);
               }
            }
         
         }
      a++;
      delay_ms(3000);
     
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 06, 2009 10:26 am     Reply with quote

Quote:
for (q=0;q==4;q++)
{
lcd_putc(buffer[q]); // print the array to LCD
delay_ms(2000);
}
}

Look at your test in the for() loop.
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