Help with 8051 Stepper Motor Controller

Thread Starter

Ishah

Joined Jan 3, 2013
3
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?

Rich (BB code):
 /********************************
FILE NAME:        stepper.c
CHIP TYPE:        AT89C51
CLOCK FREQUENCY:  12MHZ
IDE:              VSMStudio
COMPILER:         IAR for 8051
TIME:             September 2010
********************************/

#include "ioAT89C51.h"

// Definition for output port and input pins
#define out_port  (P2)
#define key_for   (P0_bit.P0_0) 
#define key_rev   (P0_bit.P0_1)

// Define new types
typedef unsigned char   uchar;
typedef unsigned int    uint;

void delayms(uint);

// Array of Stepping Sequences 
uchar const sequence[8] = {0x02,0x06,0x04,0x0c,0x08,0x09,0x01,0x03};

void main(void)
 { uchar i;
   out_port = 0x03;
   while(1)
    { // Has the forward key been pressed ? 
      if (!key_for)
       { i = i<8 ? i+1 : 0;
         out_port = sequence;
         delayms(50);
       }
      // Has the reverse key been pressed ?
      else if (!key_rev)
       { i = i>0 ? i-1 : 7;    
         out_port = sequence;
         delayms(50);
       }    
    }
 }

void delayms(uint j)
 { uchar i;
   for(; j>0; j--)
    { i = 120;
      while (i--);  
    }
 }


TQ.
 
Last edited by a moderator:

John P

Joined Oct 14, 2008
2,026
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?
 
Top