Hier 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"
!!! Du greifst auf zelle[0] und zelle[1] zu, definierst zelle[] aber nur zu Länge1, das crasht!!! Es muss mindestens Länge 2 haben!
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;
cli();
ganzzahl = (adc/1024.0) * 5;
komma = (ganzzahl - (int) ganzzahl)*100;
sei();
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;
cli();
zelle[0] = a2dConvert10bit(0);
zelle[1] = a2dConvert10bit(1);
PORTD ^= (1<<0);
sei();
}
}
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++)
{
cli();
if(zelle[i] > 614)
sei();
istpositiv[i] = 1;
if(istpositiv[i] == 1)
{
cli();
if(zelle[i] < 614)
{
sei();
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;
}
}
sei(); !!! IRQs müssen auch wieder eingeschaltet werden, wenn if(...) falsch ist.
}
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);
}
Ich hoffe mir kann jemand helfen
Gruß Robert