Use L293D or TLE4726 for interface and this algorithm (full pass) for control (CCS Compiler):
char port_a;
#byte port_a = 0x05 //Initial address of Porta_A
char port_c;
#byte port_c = 0x07 //Initial address of Porta_C
// It's depends of pins that are you using
#define BOB1B port_a,4
#define BOB1A port_a,5
#define BOB2B port_c,4
#define BOB2A port_c,5
// Variables
static unsigned int8 flag_step; //Motor position flag;
static unsigned int32 steps; //pass counter
void Close_Motor(void)
{
switch(flag_step) // Next pass
{
case 1:
bit_set(BOB1B); // Pass 1
bit_clear(BOB1A);
bit_clear(BOB2B);
bit_set(BOB2A);
flag_step = 2;
steps--; // Dec pass number variable
break;
case 2:
bit_clear(BOB1B); // Pass 2
bit_set(BOB1A);
bit_clear(BOB2B);
bit_set(BOB2A);
flag_step = 3;
steps--; // Dec pass number variable
break;
case 3:
bit_clear(BOB1B); // Pass 3
bit_set(BOB1A);
bit_set(BOB2B);
bit_clear(BOB2A);
flag_step = 4;
steps--; // Dec pass number variable break;
case 4:
bit_set(BOB1B); // Pass 4
bit_clear(BOB1A);
bit_set(BOB2B);
bit_clear(BOB2A);
flag_step = 1;
steps--; // Dec pass number variable
break;
}
return;
}
void Open_Motor(void)
{
switch(flag_step) // Next pass
{
case 1: // Pass 1
bit_clear(BOB1B);
bit_set(BOB1A);
bit_set(BOB2B);
bit_clear(BOB2A);
flag_step = 4;
steps++; // Inc pass number variable
break;
case 2: // Pass 2
bit_set(BOB1B);
bit_clear(BOB1A);
bit_set(BOB2B);
bit_clear(BOB2A);
flag_step = 1;
steps++; // Inc pass number variable
break;
case 3: // Pass 3
bit_set(BOB1B);
bit_clear(BOB1A);
bit_clear(BOB2B);
bit_set(BOB2A);
flag_step = 2;
steps++; // Inc pass number variable
break;
case 4: // Pass 4
bit_clear(BOB1B);
bit_set(BOB1A);
bit_clear(BOB2B);
bit_set(BOB2A);
flag_step = 3;
steps++; // Inc pass number variable
break;
}
return;
}
void main(void)
{
steps = 1; //Initial value of pass
}
Then you need put a delay routine between pass (obeyed the maximum operational frequency of motor) and speed that you need.
leomecma