/* Kleines Barometer mit dem Tiny26 Neue Version mit zusätzlichem LT1286 D. Sperling 2005 */ #include "lcd.h" #include #include #include #include #define SETBIT(p, b) (p) |=BIT(b) #define CLRBIT(p, b) (p) &= ~BIT(b) #define TOGGLE(p, b) (p) ^=BIT(b) #define BIT(x) (1<<(x)) #define AREF 5065 //Referenzspannung in mV #define OFFSET 115 //Offset MP4115 in mBar*10 #define MPX 4954 //VSS Drucksensor in mV unsigned long druck, summe; unsigned int zaehler, trend, wert, alt; char output[5]; uint32_t volt(void); //Prototype SIGNAL(SIG_OVERFLOW0) //Handler für Timer Interrupt { zaehler++; } //Delay Funktion int delay_count=250; //Prozessortakt in Hz geteilt durch 4000 void delay(uint8_t ms) { uint16_t cnt; asm volatile ( "\n" "L_dl1%=:" "\n\t" "mov %A0, %A2" "\n\t" "mov %B0, %B2" "\n" "L_dl2%=:" "\n\t" "sbiw %A0, 1" "\n\t" "brne L_dl2%=" "\n\t" "dec %1" "\n\t" "brne L_dl1%=" "\n\t" : "=&w" (cnt) : "r" (ms), "r" (delay_count) ); } // Ende Delay Funktion //ADC Ansteuerung int adc(void) { int abfrage=0; CLRBIT(PORTA,0); //CS auf 0 asm volatile ("nop"); asm volatile ("nop"); for(int i=0;i<14;i++) { SETBIT(PORTB,2); //CLK auf 1 asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); CLRBIT(PORTB,2); //CLK auf 0 abfrage=(abfrage<<1); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); if (bit_is_set(PINB,0)) abfrage|=1; //DATA abfragen } SETBIT(PORTA,0); //CS auf 1 return(abfrage); } //Ende ADC int main (void) { TCCR0= (1<800) //Gibt an wie weit die Messwerte für den Trend auseinander liegen { if (trend>1000) alt=wert; trend=(alt+wert); alt=trend/2; trend=0; } if (alt>wert+5) lcd_putc('-'); else if (alt