avrdude script:
#avrdude -c usbasp -p t2313
avrdude -c usbasp -p t2313 -Uflash:w:attiny2313.hex:a
ATTiny2313 C program:
#include#include #include #include ISR(INT0_vect) { //PORTD &= ~(1<} //ISR(INT1_vect) { // PORTD &= ~(1 int cSeconds = 0; // char cSecondsIni = 0; char cStart = 0; char cSecondsDelay = 0; char toggle = 0; char cBuzzerCount = 0; //decgafb //0100001 char cData[10]={ 0b00001000, //0 0b01101110, //1 0b00010010, //2 0b00100010, //3 0b01100100, //4 0b00100001, //5 0b00000001, //6 0b01101010, //7 0b00000000, //8 0b00100000 //9 }; void checkTimer(void) { if (TIFR & 0x01) { // timer timed out? TIFR |= 0x01; // reset timer flag if(toggle++>3) { toggle = 0; if(cStart) { cSeconds--; if(cSeconds < 0) { cSeconds = 0; } } if(cStart == 0) { cSecondsDelay++; } else { cSecondsDelay = 0; } soundIfBuzzer(); } } } //------------------- void listenKeys(void) { if((PIND & 1< cSeconds-=60; if((PIND & 1< cSeconds+=60; if((PIND & 1< cSeconds-=600; if((PIND & 1< cSeconds+=600; if(cSeconds < 0) cSeconds = 5940; if(cSeconds > 5940) { cSeconds = 0; } if((PIND & 1< { if(cStart <= 0 && cSeconds > 0) cStart = 1; cBuzzerCount = 0; } while( (PIND & 1< { _delay_ms(50); cStart = 0; cSecondsDelay = 0; cBuzzerCount = 0; } } //-------------------- void showSeconds(void) { char c1 = cSeconds /60 /10; char c2 = cSeconds /60 %10; PORTB = cData[c2]; PORTA |= 1< PORTA &= ~(1< _delay_ms(1); PORTB = cData[c1]; PORTA |= 1< PORTA &= ~(1<} //------------------------------- void sleepMode(char seconds_) { if(cBuzzerCount > 0) seconds_ = 30; if(cSecondsDelay < seconds_) return; cSecondsDelay = 0; //indicator PORTA &= ~(1< PORTA &= ~(1< //buzzer PORTD &= ~(1< cBuzzerCount = 0; //#define SLEEP_MODE_IDLE 0 //#define SLEEP_MODE_PWR_DOWN (_BV(SM0) | _BV(SM1)) //#define SLEEP_MODE_STANDBY только при установке внешнего резонатора //sei(); set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_enable(); //sleep_cpu(); sleep_mode(); sleep_disable(); } //-------------- void soundIfBuzzer(void) { if(cSeconds <= 0 && cStart == 1) { cBuzzerCount = 1; cStart = 0; } if(cBuzzerCount > 0) { PORTD |= 1< _delay_ms(100); PORTD &= ~(1< _delay_ms(100); PORTD |= 1< _delay_ms(100); PORTD &= ~(1< } } //-------------- int main(void) { sei(); // enable external interrupt 0 GIMSK |= (1 << INT0); //GIMSK |= (1 << INT1); //PIND0:IN: + //PIND1:IN: - //PIND2:IN: start/stop //PIND3: //PIND4:IN: + //PIND5:IN: - //PIND6:OUT:LED/buzzer DDRD = 0b01000000; PORTD = 0b00111111; //indicator DDRB = 0xFF; PORTB = 0x00; //indicator power DDRA = 0xFF; PORTA = 0xFF; TCCR0A = 0x02; // Clear Timer on Compare Match (CTC) mode OCR0A = 194; // number to count up to TCCR0B = 0x05; // clock source CLK/1024, start timer while(1) { checkTimer(); listenKeys(); showSeconds(); sleepMode(5); _delay_ms(1); } return 0;}
No comments:
Post a Comment