[LCP]Parallel programming

Mohamed Raouf mohamed.raouf at link.net
Fri Jul 5 05:59:06 UTC 2002


Hi all 
I wrote a C code that controls a stepper motor connected to the parallel port ,First I made it under windows and it worked so fine 
but when I tried to convert it under linux, it was compiled but when I tried to run it , I had te following message " segmentation fault (core dumped)"
  
 I know that  a segmentation fault occurs when your program tries to access memory locations that haven't been allocated for the program's use or when you try to access an array index which is out of range.  

But I can't solve this problem in my code, So is there anyonewho could help me??.
Here is my code



// Stetp Motor control
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <asm/io.h>

int DATA=0x378;

char turnmot(char lstc,char dri);


int main()
{
 char usps; char lastcoil=0; int count=0;
 for(count=0;count<200;count++) {
 lastcoil=turnmot(lastcoil,0);
 usleep(30);
 } count=0;
 printf("\n\tPress (L) to turn, Press (R) to turn in opposite direction\n");
 printf("\tPress ESC to exit\n");
 while(1) {

  printf("count=%d, lastcoil=%d  ",count,lastcoil); 
  switch(usps) {
  case 'r':
  case 'R': lastcoil=turnmot(lastcoil,0);count=(count+1)%200; break;
  case 'l':
  case 'L': lastcoil=turnmot(lastcoil,1);count=(count-1+200)%200; break;
  case 27: exit(0);
  }  usleep(200); outb(0,DATA);
 }
}

char turnmot(char lstc, char dri) {
 char lst1,res;
 if (dri==1) lst1=(lstc+1) % 4; else lst1=(lstc-1+4) % 4;
 res=1<<lst1;
 outb(res,DATA);
 return(lst1);
}



Of course you know that to compile it you must use "gcc -O2 -o stepper stepper.c" where stepper  and stepper.c are the manes of the output file and the source file recpectively.

Waiting for your replies 
thanks alot.


__________________________________________________________________
MOHAMED RAOUF
ICQ#: 44365427
      Current ICQ status:     
+  More ways to contact me 
__________________________________________________________________

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.linux.org.au/pipermail/linuxcprogramming/attachments/20020705/48fe605b/attachment.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/octet-stream
Size: 105 bytes
Desc: not available
Url : http://lists.linux.org.au/pipermail/linuxcprogramming/attachments/20020705/48fe605b/attachment.obj 


More information about the linuxCprogramming mailing list