/* * zaj3.c * * Created: 29.10.2018 15:07:38 * Author : student */ #include #include #include #include volatile float res; volatile float val; volatile int x1=0; volatile int x2=0; ISR(INT0_vect) { x1=1; x2=0; } ISR(INT1_vect) { x2=1; x1=0; } int main(void) { DDRB=0xFF; GICR = _BV(INT0) | _BV(INT1); MCUCR = _BV(ISC11) | _BV(ISC01); ADCSRA = _BV(ADEN); //ADMUX = _BV(MUX0); sei(); PORTB = _BV(0) | _BV(1) | _BV(2) | _BV(3) | _BV(4) | _BV(5); while (1) { sleep_mode(); if(x1==1) // INT0 { ADCSRA |= _BV(ADSC) | _BV(ADPS1) | _BV(ADPS0); //preskaler 8 loop_until_bit_is_clear( ADCSRA,ADSC); uint16_t wynik= ADCW; val = (wynik /1024.0) * 5.20; res=(int)val; } if(x2==1) // INT1 { //PORTB = _BV(0) | _BV(2) | _BV(3) | _BV(5) |_BV(6); res=(val-(int)val)*10; res=(int) (res); } // while( ADCSRA & _BV(ADSC) ); // uint16_t wynik= ADCW; // val = wynik * 1024 / 5.25; // PORTB = _BV(0) | _BV(1) | _BV(2) | _BV(3) | _BV(4) | _BV(5) |_BV(6); if(res == 0) PORTB = _BV(0) | _BV(1) | _BV(2) | _BV(3) | _BV(4) | _BV(5) |_BV(6); if(res==1) PORTB =_BV(1) | _BV(2); if(res == 2) PORTB = _BV(0) | _BV(1) | _BV(3) | _BV(4) | _BV(6); if(res==3) PORTB = _BV(0) | _BV(1) | _BV(2) | _BV(3) | _BV(6); if(res==4) PORTB = _BV(2) | _BV(5) |_BV(6); if(res==5) PORTB = _BV(0) | _BV(2) | _BV(3) | _BV(5) |_BV(6); if(res==6) PORTB = _BV(0) | _BV(2) | _BV(3) | _BV(4) | _BV(5) |_BV(6) ; if(res==7) PORTB = _BV(0) | _BV(1) | _BV(2); if(res==8) PORTB = _BV(0) | _BV(1) | _BV(2) | _BV(3) | _BV(4) | _BV(5) |_BV(6); if(res ==9) PORTB = _BV(0) | _BV(1) | _BV(2) | _BV(3) | _BV(5) |_BV(6); } return 0; }