Minky
Joined: 29 Apr 2009 Posts: 3
|
16f877 eeprom problem |
Posted: Wed May 06, 2009 8:30 am |
|
|
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);
}
}
|
|
|