#define F_CPU 8000000UL #include #include #include #include unsigned char DOLE = 12; unsigned char NAHORE = 20; unsigned char linka; unsigned char cisloPrikazu; unsigned char id; unsigned char ks; unsigned char p = 18; unsigned char dioda; unsigned char citacTimeru1; signed char poziceMotoru1; signed char poziceMotoru2; unsigned char reletivniPozicePocatkuX = 0; unsigned char relativniPozicePocatkuY = 0; unsigned short x; unsigned short y; signed char zx; signed char zy; signed short dx; signed short dy; unsigned char x1; unsigned char x2; unsigned char y11; unsigned char y2; unsigned short xp; unsigned short yp; unsigned short citacTimeru2; unsigned char XJeVetsiNezY; unsigned short hodnota; unsigned char pole[] = {0b00001000, 0b00001001, 0b00000001, 0b00000101, 0b00000100, 0b00000110, 0b00000010, 0b00001010}; // send char void uart_putc(unsigned char data ) { while ( !( UCSR0A & (1< 20) { PORTD ^= 0x80; dioda = 0; } } ISR (TIMER1_COMPA_vect){ citacTimeru1 += 1; citacTimeru1 = citacTimeru1 % 200; if (citacTimeru1 < p) { PORTC |= (1 << 5); } else { PORTC &= (~(1 << 5)); } } ISR (TIMER2_OVF_vect) { citacTimeru2 +=1; //1/(f*1000000/(2^8*1024[preddelicka]))*1000*citac [ms] if (citacTimeru2 >= 6) { citacTimeru2 = 0; } } signed short ABS(signed short x){ if (x<0) { return -x; } else { return x; } } void pozice (void) { if (p != NAHORE) { p = NAHORE; _delay_ms(100); } while ( (!(PINB & (1< dy) { XJeVetsiNezY = 1; hodnota = dx; TIMSK2 = (1< 0) || (dy - ay > 0)) { if (dy * ax > ay * dx) { poziceMotoru2 += zy; poziceMotoru2 = (poziceMotoru2 + 8) % 8; PORTB = pole[poziceMotoru2]; y += zy; } } } else { XJeVetsiNezY = 0; hodnota = dy; TIMSK2 = (1< 0) || (dy - ay > 0)) { if (dy * ax > ay * dx) { poziceMotoru1 += zx; poziceMotoru1 = (poziceMotoru1 + 8) % 8; PORTC &= 0b11110000; PORTC |= pole[poziceMotoru1]; x += zx; } } } TIMSK2 = 0; //zakázání přerušení od přetečení timeru 2 } int main(void) { DDRD = 0x80; PORTD = 0x00; DDRB = (1<