: i need help its urgent
:
: a sourcecode for linux in c for the stepper motor
:
:
: pls....
:
: help
Here is the code for controlling stepper motor...Hope u can compile it in Linux 9 (2.4 ker)
/* Stepper.c */
#include <stdio.h> /* for printf() */
#include <sys/io.h> /* for ioperm() */
#include <unistd.h> /* for usleep() */
#include "port.h"
#define PORT 0x378
#define TIME 1000
void clockwise(){
int i;
/* i've got one rotor cycle in 12 loops */
for (i=0; i<12; i++){
port_out(PORT, 0x01); /* 0001 */
usleep(TIME);
port_out(PORT, 0x03); /* 0011 */
usleep(TIME);
port_out(PORT, 0x02); /* 0010 */
usleep(TIME);
port_out(PORT, 0x06); /* 0110 */
usleep(TIME);
port_out(PORT, 0x04); /* 0100 */
usleep(TIME);
port_out(PORT, 0x0c); /* 1100 */
usleep(TIME);
port_out(PORT, 0x08); /* 1000 */
usleep(TIME);
port_out(PORT, 0x09); /* 1001 */
usleep(TIME);
}
}
void counter_clockwise(){
int i;
for (i=0; i<12; i++){
port_out(PORT, 0x08); /* 1000 */
usleep(TIME);
port_out(PORT, 0x0c); /* 1100 */
usleep(TIME);
port_out(PORT, 0x04); /* 0100 */
usleep(TIME);
port_out(PORT, 0x06); /* 0110 */
usleep(TIME);
port_out(PORT, 0x02); /* 0010 */
usleep(TIME);
port_out(PORT, 0x03); /* 0011 */
usleep(TIME);
port_out(PORT, 0x01); /* 0001 */
usleep(TIME);
port_out(PORT, 0x09); /* 1001 */
usleep(TIME);
}
}
int main(){
int i;
if (ioperm(PORT, 1, 1) == -1)
printf("There's something wrong...\n");
for (i=0; i<30; i++)
clockwise();
return 0;
}
/* port.h */
#ifndef PORT_H
#define PORT_H
static inline int port_in( int port )
{
unsigned char value;
__asm__ volatile ("inb %1,%0"
: "=a" (value)
: "d" ((unsigned short)port));
return value;
}
static inline void port_out( unsigned short int port, unsigned char val ){
__asm__ volatile (
"outb %0,%1\n"
:
: "a" (val), "d" (port)
);
}
#endif
With Regards...
Sumit Shah.