Advertisement
tagartgames

Untitled

Oct 20th, 2019
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <avr/interrupt.h>
  3. #include <util/delay.h>
  4.  
  5. #define LED (1<<PD0)
  6. #define TOG PORTD ^= LED
  7. #define LED_OFF PORTD |= LED    //wyłączenie
  8. #define LED_ON PORTD &= ~LED    //włączenie
  9. #define KEY_PIN (1<<PB0)
  10. #define KEY_DOWN ! (PINB & KEY_PIN)
  11.  
  12. volatile uint8_t licznik;
  13. uint8_t Button_On();
  14. uint8_t miganie = 0;
  15. uint8_t stanP=0; //poprzedni stan przcisku
  16. uint8_t pin=0;
  17.  
  18. int main(void){
  19.     DDRD |= LED;            //LED jako wyjscie
  20.     PORTD |= ~LED;      //wygaszenie LED
  21.     DDRB &= ~KEY_PIN;
  22.     PORTB |= KEY_PIN;
  23.     //timer///////////////////////////////////////////////////
  24.     TCCR0 |= (1<<CS02); //preskaler = 256
  25.     TIMSK |= (1<<TOIE0);
  26.     sei();
  27.     //timer///////////////////////////////////////////////////
  28.     LED_OFF;
  29.     while(1){
  30.         //obsl. przycisk
  31.         pin = KEY_DOWN;
  32.  
  33.         if(pin != stanP) {//wykr. zmiany stanu
  34.  
  35.             if(pin == 0){//zb opadaj. przycisk wcisniety
  36.                 miganie = !miganie;
  37.                 //pin=1;
  38.                 //miganie=1;
  39.                 //TOG;
  40.             }
  41.             stanP=pin;
  42.         }//if(PIN != stanP)
  43.  
  44.  
  45.         if(miganie==1){
  46.             //TOG;
  47.             //_delay_ms(500);
  48.             if(licznik >= 15){
  49.                 TOG;
  50.                 licznik = 0;
  51.             }
  52.         }
  53.  
  54.  
  55.  
  56.  
  57.     }
  58. }
  59.  
  60. ISR(TIMER0_OVF_vect) { licznik++; }
  61.  
  62. uint8_t Button_On(void) {
  63.     if(KEY_DOWN) {
  64.         _delay_ms(80);
  65.         if(KEY_DOWN) return 1;
  66.     }
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement