Sie sind nicht angemeldet.
![]() |
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
#include <avr/io.h> #include <avr/signal.h> #include <avr/interrupt.h> #include <stdlib.h> #include <stdio.h> #include "lcd.c" //taster3 pressed=bit_is_clear(PINB, PINB1) //taster2 pressed=bit_is_clear(PINB, PINB2) //taster1 pressed=bit_is_clear(PINB, PINB3) //led 2 an cbi(PORTC,PINC4); //led 2 aus sbi(PORTC,PINC4); //led 1 an cbi(PORTC,PINC5); //led 1 aus sbi(PORTC,PINC5); //ls an sbi(PORTC,PINC3); //ls aus cbi(PORTC,PINC3); SIGNAL (SIG_INPUT_CAPTURE1)//wenn mikrophon was bekommen { cli(); //interrupts aus cbi(PORTC,PINC3);//ls aus } int main( void ) { DDRC=0xff;//out DDRB=0x00;//in sbi(PORTC,PINC4);//led aus sbi(PORTC,PINC5);//led aus cbi(PORTC,PINC3);//ls aus lcd_init(LCD_DISP_ON); lcd_clrscr(); unsigned volatile int i,j; char act[20]; unsigned char l,h; unsigned int wert; for(;;) { if(bit_is_clear(PINB, PINB3))//taster 1 { lcd_clrscr(); outb(TCCR1A, 0); outb(TCCR1B, (1<<ICES1 | 1<<CS10));// rising edge for ICP, full speed outb(TIMSK, 1<<TICIE1);// ICP interrupt enable ICR1H=0; ICR1L=0; TCNT1H=0; TCNT1L=0; sbi(PORTC,PINC3);//ls an sei();//interrupt an for(i=0;i<65000;i++)for(j=0;j<10;j++)//pause, waerendessen interrupt { asm volatile("nop"); } l=ICR1L; h=ICR1H; wert=256*h+l; sprintf(act,"%u %u %u\n",l, h,wert); lcd_puts(act); } } return 0; } |
![]() |
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
#include <avr/io.h> #include <avr/signal.h> #include <avr/interrupt.h> #include <stdlib.h> #include <stdio.h> #include "lcd.c" //taster3 pressed=bit_is_clear(PINB, PINB1) //taster2 pressed=bit_is_clear(PINB, PINB2) //taster1 pressed=bit_is_clear(PINB, PINB3) //led 2 an cbi(PORTC,PINC4); //led 2 aus sbi(PORTC,PINC4); //led 1 an cbi(PORTC,PINC5); //led 1 aus sbi(PORTC,PINC5); //ls an sbi(PORTC,PINC3); //ls aus cbi(PORTC,PINC3); unsigned volatile char l,h; unsigned volatile char first=0; SIGNAL (SIG_INPUT_CAPTURE1) { cli(); //interrupts aus if(first==0)//nur den ersten wert nehmen { first=1; l=ICR1L; h=ICR1H; } cbi(PORTC,PINC3);//ls aus } int main( void ) { DDRC=0xff;//out DDRB=0x00;//in sbi(PORTC,PINC4);//led aus sbi(PORTC,PINC5);//led aus cbi(PORTC,PINC3);//ls aus lcd_init(LCD_DISP_ON); lcd_clrscr(); lcd_puts("..."); unsigned volatile int i,j,mess; char act[20]; unsigned volatile int t=0; unsigned int wert=0; for(;;) { if(bit_is_clear(PINB, PINB3))//taster 1 { lcd_clrscr(); lcd_puts("Messe"); t=0; for(mess=0;mess<10;mess++) { lcd_puts("."); first=0; TCCR1A=0; TCCR1B=(1<<ICES1 | 1<<CS11);// rising edge for ICP,CPU/8 TIMSK=(1<<TICIE1);// ICP interrupt enable ICR1H=0; ICR1L=0; TCNT1H=0; TCNT1L=0; sbi(PORTC,PINC3);//ls an sei();//interrupt an for(i=0;i<65000;i++)for(j=0;j<10;j++)//pause, waerendessen interrupt { asm volatile("nop"); } wert=256*h+l; //sprintf(act,"%u %u %u\n",l, h,wert-550); t+=wert-364; //lcd_puts(act); } sprintf(act,"\n%u",t); lcd_puts(act); } } return 0; } |
-