Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- #define LED (1<<PD0)
- #define TOG PORTD ^= LED
- #define LED_OFF PORTD |= LED //wyłączenie
- #define LED_ON PORTD &= ~LED //włączenie
- #define KEY_PIN (1<<PB0)
- #define KEY_DOWN ! (PINB & KEY_PIN)
- volatile uint8_t licznik;
- uint8_t Button_On();
- uint8_t miganie = 0;
- uint8_t stanP=0; //poprzedni stan przcisku
- uint8_t pin=0;
- int main(void){
- DDRD |= LED; //LED jako wyjscie
- PORTD |= ~LED; //wygaszenie LED
- DDRB &= ~KEY_PIN;
- PORTB |= KEY_PIN;
- //timer///////////////////////////////////////////////////
- TCCR0 |= (1<<CS02); //preskaler = 256
- TIMSK |= (1<<TOIE0);
- sei();
- //timer///////////////////////////////////////////////////
- LED_OFF;
- while(1){
- //obsl. przycisk
- pin = KEY_DOWN;
- if(pin != stanP) {//wykr. zmiany stanu
- if(pin == 0){//zb opadaj. przycisk wcisniety
- miganie = !miganie;
- //pin=1;
- //miganie=1;
- //TOG;
- }
- stanP=pin;
- }//if(PIN != stanP)
- if(miganie==1){
- //TOG;
- //_delay_ms(500);
- if(licznik >= 15){
- TOG;
- licznik = 0;
- }
- }
- }
- }
- ISR(TIMER0_OVF_vect) { licznik++; }
- uint8_t Button_On(void) {
- if(KEY_DOWN) {
- _delay_ms(80);
- if(KEY_DOWN) return 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement