Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Impulsy kroków odbierane na INT0 :: 4
- * Kierunek obrotów zależny od PD0 :: 2
- */
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #define F_CPU 1000000
- volatile uint8_t licznik = 0;
- volatile kroki[4];
- int main(void) {
- DDRD = 0x00;
- DDRC = 0x0f;
- PORTC = 0x00;
- MCUCR |= (1<<ISC01) | (1<<ISC00) ; // INT0 reaguje na zbocze narastajace
- GICR |= 1 << INT0; // włączenie INT0
- kroki[0] = 0b1010; // 0xA
- kroki[1] = 0b0110; // 0x6
- kroki[2] = 0b0101; // 0x5
- kroki[3] = 0b1001; // 0x9
- sei(); // włączenie przerwań
- while(1) {
- }
- }
- ISR(INT0_vect) { // obsługa przerwania INT0
- PORTC = 0x00; // krótkie wyłączenie wszystkich t.
- if( PIND & 0x01 ) {
- licznik = licznik < 3 ? licznik+1 : 0;
- } else {
- licznik = licznik > 0 ? licznik-1 : 3;
- }
- PORTC = kroki[licznik];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement