Problem in Stepper Motor code (step angle)

Discussion in 'Embedded Systems and Microcontrollers' started by theumer, Mar 30, 2012.

  1. theumer

    Thread Starter New Member

    Mar 29, 2012
    2
    0
    I need to drive a stepper motor that would rotate with a step angle of 7.5 degrees. The code that I wrote has an error even though I am unable to locate anything in the code. Here's the error:

    Error [500] ; . undefined symbols:
    _delay (stepper.obj)_digitalWrite (stepper.obj)_digitalRead (stepper.obj)_analogRead (stepper.obj)_pinMode (stepper.obj)

    The code:

    Code ( (Unknown Language)):
    1.  
    2. #include <pic.h>
    3.  
    4. #define yellow 15  //Q1
    5. #define orange 16  //Q2
    6. #define brown 17  // Q3
    7. #define black 18 // Q4
    8.  
    9. #define CW 33 // SW0 in schematic
    10. #define CCW 34  //SW1 in schematic
    11.  
    12. void all_coils_off()  
    13. {
    14.   digitalWrite(black, 0);
    15.   digitalWrite(brown, 0);
    16.   digitalWrite(orange, 0);
    17.   digitalWrite(yellow, 0);
    18.  
    19. }
    20.  
    21.  
    22. void reverse(int i) {
    23.  
    24.   while (1)   {
    25.  
    26.     digitalWrite(black, 1);
    27.     digitalWrite(brown, 0);
    28.     digitalWrite(orange, 1);
    29.     digitalWrite(yellow, 0);
    30.     delay(analogRead(0)/4 + 10);  
    31.     i--;
    32.     if (i < 1) break;
    33.  
    34.  
    35.     digitalWrite(black, 0);
    36.     digitalWrite(brown, 1);
    37.     digitalWrite(orange, 1);
    38.     digitalWrite(yellow, 0);
    39.     delay(analogRead(0)/4 + 10);
    40.     i--;
    41.     if (i < 1) break;
    42.  
    43.  
    44.     digitalWrite(black, 0);
    45.     digitalWrite(brown, 1);
    46.     digitalWrite(orange, 0);
    47.     digitalWrite(yellow, 1);
    48.     delay(analogRead(0)/4 + 10);  
    49.     i--;
    50.     if (i < 1) break;
    51.  
    52.     digitalWrite(black, 1);
    53.     digitalWrite(brown, 0);
    54.     digitalWrite(orange, 0);
    55.     digitalWrite(yellow, 1);
    56.     delay(analogRead(0)/4 +10);
    57.     i--;
    58.     if (i < 1) break;
    59.   }
    60.  
    61. }
    62.  
    63. void forward(int i) {
    64.  
    65.   while (1)   {
    66.  
    67.     digitalWrite(black, 1);
    68.     digitalWrite(brown, 0);
    69.     digitalWrite(orange, 0);
    70.     digitalWrite(yellow, 1);
    71.     delay(analogRead(0)/4 +10);
    72.     i--;
    73.     if (i < 1) break;
    74.  
    75.     digitalWrite(black, 0);
    76.     digitalWrite(brown, 1);
    77.     digitalWrite(orange, 0);
    78.     digitalWrite(yellow, 1);
    79.     delay(analogRead(0)/4 +10);
    80.     i--;
    81.     if (i < 1) break;
    82.  
    83.     digitalWrite(black, 0);
    84.     digitalWrite(brown, 1);
    85.     digitalWrite(orange, 1);
    86.     digitalWrite(yellow, 0);
    87.     delay(analogRead(0)/4 +10);
    88.     i--;
    89.     if (i < 1) break;
    90.  
    91.     digitalWrite(black, 1);
    92.     digitalWrite(brown, 0);
    93.     digitalWrite(orange, 1);
    94.     digitalWrite(yellow, 0);
    95.     delay(analogRead(0)/4 +10);
    96.     i--;
    97.     if (i < 1) break;
    98.   }
    99. }
    100.  
    101. void setup()  
    102. {
    103.   pinMode(CW, RB0);
    104.   pinMode(CCW, RB1);
    105.  
    106. //  digitalWrite(CW, 1); // pull up on
    107. //  digitalWrite(CCW,1); // pull up on
    108.  
    109.   pinMode(black, PORTC);
    110.   pinMode(brown, PORTC);
    111.   pinMode(orange, PORTC);
    112.   pinMode(yellow, PORTC);
    113.  
    114.   // all coils off
    115.   digitalWrite(black, 0);
    116.   digitalWrite(brown, 0);
    117.   digitalWrite(orange, 0);
    118.   digitalWrite(yellow, 0);
    119.  
    120. }
    121.  
    122. void loop()
    123. {
    124.  
    125.   if (!digitalRead(CW))  
    126.     {
    127.  
    128.     forward(200);
    129.     all_coils_off();  
    130.       }
    131.  
    132.  
    133.   if (!digitalRead(CCW))  
    134.     {
    135.  
    136.     reverse(200);
    137.     all_coils_off();  
    138.   }      
    139.  
    140. } // end loop
    141.  
    142. void main ()
    143.  
    144. {
    145.  
    146.  PORTC=0x00;
    147.  PORTB=0xFF;
    148.  setup();
    149.  loop();
    150. }
    151.  
    Any help would be appreciated.
     
  2. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    It looks very simple. You've used a number of functions in your code which aren't recognizable to the compiler:

    _delay
    _digitalWrite
    _digitalRead
    _analogRead
    _pinMode
     
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    It looks to me that you are trying to use some Arduino code in a Microchip MPLAB/HI-Tech C setting. You can not do that. But I am sure we kan help you out. As the code you posted should be easy to port
     
Loading...