Advertisement
Guest User

Untitled

a guest
Mar 24th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. /*
  2.  *  Impulsy kroków odbierane na INT0 :: 4
  3.  *  Kierunek obrotów zależny od PD0 :: 2
  4.  */
  5.  
  6. #include <avr/io.h>
  7. #include <avr/interrupt.h>
  8.  
  9. #define F_CPU 1000000
  10.  
  11. volatile uint8_t licznik = 0;
  12. volatile kroki[4];
  13.  
  14. int main(void) {
  15.     DDRD = 0x00;
  16.     DDRC = 0x0f;
  17.    
  18.     PORTC = 0x00;
  19.        
  20.     MCUCR |= (1<<ISC01) | (1<<ISC00) ; // INT0 reaguje na zbocze narastajace
  21.     GICR |= 1 << INT0; // włączenie INT0
  22.    
  23.     kroki[0] = 0b1010; // 0xA
  24.     kroki[1] = 0b0110; // 0x6
  25.     kroki[2] = 0b0101; // 0x5
  26.     kroki[3] = 0b1001; // 0x9
  27.    
  28.     sei(); // włączenie przerwań
  29.    
  30.     while(1) {
  31.        
  32.     }
  33. }
  34.  
  35. ISR(INT0_vect) { // obsługa przerwania INT0
  36.    
  37.         PORTC = 0x00; // krótkie wyłączenie wszystkich t.
  38.        
  39.        
  40.         if( PIND & 0x01 ) {
  41.             licznik = licznik < 3 ? licznik+1 : 0;
  42.         } else {
  43.             licznik = licznik > 0 ? licznik-1 : 3;
  44.         }
  45.        
  46.         PORTC = kroki[licznik];
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement