Hallo an alle
Ich hab ein Programm geschrieben, das alle ~5 Sekunden einen Wert über A2D einließt (Timergesteuert). Wenn dieser Wert unter 614 ist, wird dieser im Eeprom abgelegt und ein Zähler um 1 erhöht. Doeser wird auch im Eeprim abgelegt. Erst wenn der Wieder einmal über 614 war, kann der Wert und der Zähler um eins erhöht werden. Das ganze hab ich für 2 A2D Kanäle gemacht. Weiters hab ich eine Unterfunktion zum Auslesen der Wert aus dem Eeprom. (FUnktionsaufruf wenn PD7 gedrückt ist).
Nur leider funktioniert es nicht wie sollte. Bei jeder MEssungen kommen zusätzlich Zeichen aufs Display die eigentlich nicht dort hingehören. Ich weiß aber nicht warum 
Sobald ein falsches Zeichen aus der main (messfunktion) am Display ist, werden bei der lesefunktion auch falsche Zeichen Dargestellt.
Das Abspeichern im Eeprom funktioniert auch nicht.
Hie nun mal der Code:
Code:
#include <avr/io.h>
#include <stdlib.h>
#include <avr/eeprom.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include "avrlibdefs.h"
#include "avrlibtypes.h"
#include "a2d.h"
#include "lcd.h"
volatile uint16_t zelle[1];
volatile uint16_t counter =0;
int lcd_maske(void);
int lcd_put_f(uint16_t adc);
int timer_init (void);
int timer_init(void)
{
TIMSK = (1<<TOIE0);
TCNT0 = 0;
TCCR0 = (1<<CS02);
return(0);
}
int lcd_maske (void)
{
lcd_init(LCD_DISP_ON);
lcd_home();
lcd_clrscr();
lcd_puts(" Unterspannungsanzeige");
lcd_gotoxy(0,1);
lcd_puts("Zelle 1:");
lcd_gotoxy(0,2);
lcd_puts("Zelle 2:");
return(0);
}
int lcd_put_f (uint16_t adc) //Zum anzeigen der Spannungen am Display
{
float ganzzahl,komma;
uint8_t int_ganzzahl, int_komma;
ganzzahl = (adc/1024.0) * 5;
komma = (ganzzahl - (int) ganzzahl)*100;
int_ganzzahl = (int)ganzzahl;
int_komma = komma;
lcd_put_d(int_ganzzahl);
lcd_putc('.');
lcd_put_d(int_komma);
return(0);
}
SIGNAL (SIG_OVERFLOW0)
{
counter++;
if(counter == 600) //5s
{
counter=0;
zelle[0] = a2dConvert10bit(0);
zelle[1] = a2dConvert10bit(1);
PORTD ^= (1<<0);
}
}
int lesen (void)
{
cli();
lcd_clrscr();
lcd_home();
lcd_puts("Auslesen der Werte");
lcd_gotoxy(0,1);
lcd_puts("Niedrigster Wert Anzahl\n");
lcd_puts("Zelle 1:\n");
lcd_puts("Zelle 2:");
lcd_gotoxy(9,2);
lcd_put_f(eeprom_read_word((uint16_t*) 2));
lcd_gotoxy(9,3);
lcd_put_f(eeprom_read_word((uint16_t*) 4));
lcd_gotoxy(20,2);
lcd_put_d(eeprom_read_byte((uint8_t*)0));
lcd_gotoxy(20,3);
lcd_put_d(eeprom_read_byte((uint8_t*)1));
loop_until_bit_is_set(PIND, PD7);
lcd_clrscr();
lcd_home();
lcd_maske();
sei();
return(0);
}
int main (void)
{
uint8_t i, istpositiv[1], zaehler[1];
istpositiv[0] = 1;
istpositiv[1] = 1;
DDRC &=~ ((1<<PC0) | (1<<PC1));
PORTC &=~ ((1<<PC0) | (1<<PC1));
DDRD |= (1<<0);
a2dInit();
a2dSetPrescaler(ADC_PRESCALE_DIV32);
a2dSetReference(ADC_REFERENCE_AVCC);
lcd_maske();
timer_init();
sei();
while(1)
{
if(bit_is_clear(PIND, PD7) == 1)
lesen();
for(i=0; i <2; i++)
{
if(zelle[i] > 614)
istpositiv[i] = 1;
if(istpositiv[i] == 1)
{
if(zelle[i] < 614)
{
zaehler[i]++;
cli();
eeprom_write_byte((uint8_t*)i, zaehler[i]);
eeprom_write_word((uint16_t*)(i*2)+2, zelle[i]);
sei();
istpositiv[i] =0;
}
}
}
lcd_gotoxy(9,1);
lcd_put_f(a2dConvert10bit(0));
lcd_putc('V');
lcd_gotoxy(9,2);
lcd_put_f(a2dConvert10bit(1));
lcd_putc('V');
}
return(0);
}
Als Prozessor verwende ich einen Mega8
Danke im Voraus
Gruß Robert
Lesezeichen