Help with 8051 Stepper Motor Controller

Discussion in 'Embedded Systems and Microcontrollers' started by Ishah, Jan 14, 2013.

  1. Ishah

    Thread Starter New Member

    Jan 3, 2013
    3
    0
    Hi can someone help me to understand this code. I found it in Proteus file :
    VSM for 8051
    8051 Stepper Motor Controller

    Also can you explain the operation of ULN2003A?

    Code ( (Unknown Language)):
    1.  
    2.  /********************************
    3. FILE NAME:        stepper.c
    4. CHIP TYPE:        AT89C51
    5. CLOCK FREQUENCY:  12MHZ
    6. IDE:              VSMStudio
    7. COMPILER:         IAR for 8051
    8. TIME:             September 2010
    9. ********************************/
    10.  
    11. #include "ioAT89C51.h"
    12.  
    13. // Definition for output port and input pins
    14. #define out_port  (P2)
    15. #define key_for   (P0_bit.P0_0)
    16. #define key_rev   (P0_bit.P0_1)
    17.  
    18. // Define new types
    19. typedef unsigned char   uchar;
    20. typedef unsigned int    uint;
    21.  
    22. void delayms(uint);
    23.  
    24. // Array of Stepping Sequences
    25. uchar const sequence[8] = {0x02,0x06,0x04,0x0c,0x08,0x09,0x01,0x03};
    26.  
    27. void main(void)
    28.  { uchar i;
    29.    out_port = 0x03;
    30.    while(1)
    31.     { // Has the forward key been pressed ?
    32.       if (!key_for)
    33.        { i = i<8 ? i+1 : 0;
    34.          out_port = sequence[i];
    35.          delayms(50);
    36.        }
    37.       // Has the reverse key been pressed ?
    38.       else if (!key_rev)
    39.        { i = i>0 ? i-1 : 7;    
    40.          out_port = sequence[i];
    41.          delayms(50);
    42.        }    
    43.     }
    44.  }
    45.  
    46. void delayms(uint j)
    47.  { uchar i;
    48.    for(; j>0; j--)
    49.     { i = 120;
    50.       while (i--);  
    51.     }
    52.  }
    53. [/i][/i]


    TQ.
     
    Last edited by a moderator: Jan 15, 2013
  2. John P

    AAC Fanatic!

    Oct 14, 2008
    1,634
    224
    Don't hijack threads.
    Do use code tags.
     
  3. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,346
  4. John P

    AAC Fanatic!

    Oct 14, 2008
    1,634
    224
    Well, now that you've got legible code in a new thread, you're asking about the program and the ULN2003. It's a simple program and a pretty easy chip to use--what have you figured out so far?
     
Loading...