Advertisement
patryk

INDIGO

Apr 13th, 2015
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <avr/delay.h>
  3.  
  4.  
  5. void prepare_system() {
  6.     DDRB |= (1<<PB0);
  7.     DDRC = 0xff;
  8. }
  9.  
  10.  
  11. void arm_move(int degree) {
  12.  
  13.     if (degree > 0) {
  14.         for (int i = 0; i < degree; i++) {
  15.             PORTC = 0x21;
  16.             _delay_ms(4);
  17.             PORTC = 0x20;
  18.             _delay_ms(20);
  19.         }
  20.     } else if (degree < 0 ) {
  21.         for (int i = 0; i < degree; i++) {
  22.             PORTC = 0x10;
  23.             _delay_ms(2);
  24.             PORTC = 0x00;
  25.             _delay_ms(2);
  26.         }
  27.     }
  28.  
  29. }
  30.  
  31.  
  32. int main(void) {
  33.  
  34.     prepare_system();
  35.  
  36.     while (1) {
  37.         PORTB ^= (1<<PB0);
  38.         arm_move(60);
  39.         _delay_ms(1000);
  40.     }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement