<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hi all </FONT></DIV>
<DIV><FONT face=Arial size=2>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 </FONT></DIV>
<DIV><FONT face=Arial size=2>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)"</FONT></DIV>
<DIV><FONT face=Arial size=2> </FONT></DIV>
<DIV><FONT face=Arial size=2> I know that </FONT><FONT
face=Arial size=2>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. </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>But I can't solve this problem in my code, So is
there anyonewho could help me??.</FONT></DIV>
<DIV><FONT face=Arial size=2>Here is my code</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>// Stetp Motor control<BR>#include
<stdlib.h><BR>#include <stdio.h><BR>#include
<unistd.h><BR>#include <asm/io.h></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>int DATA=0x378;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>char turnmot(char lstc,char dri);</FONT></DIV>
<DIV> </DIV><FONT face=Arial size=2>
<DIV><BR>int main()<BR>{<BR> char usps; char lastcoil=0; int
count=0;<BR> for(count=0;count<200;count++)
{<BR> lastcoil=turnmot(lastcoil,0);<BR> usleep(30);<BR> }
count=0;<BR> printf("\n\tPress (L) to turn, Press (R) to turn in opposite
direction\n");<BR> printf("\tPress ESC to exit\n");<BR> while(1)
{</DIV>
<DIV> </DIV>
<DIV> printf("count=%d, lastcoil=%d ",count,lastcoil); <BR>
switch(usps) {<BR> case 'r':<BR> case 'R':
lastcoil=turnmot(lastcoil,0);count=(count+1)%200; break;<BR> case
'l':<BR> case 'L': lastcoil=turnmot(lastcoil,1);count=(count-1+200)%200;
break;<BR> case 27: exit(0);<BR> } usleep(200);
outb(0,DATA);<BR> }<BR>}</DIV>
<DIV> </DIV>
<DIV>char turnmot(char lstc, char dri) {<BR> char lst1,res;<BR> if
(dri==1) lst1=(lstc+1) % 4; else lst1=(lstc-1+4) %
4;<BR> res=1<<lst1;<BR> outb(res,DATA);<BR> return(lst1);<BR>}<BR></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>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.</DIV>
<DIV> </DIV>
<DIV>Waiting for your replies </DIV>
<DIV>thanks alot.</DIV>
<DIV> </DIV>
<DIV> </DIV></FONT>
<DIV><FONT face='"Verdana", Geneva, MS sans-serif' color=#448593
size=-2><B>__________________________________________________________________</B><BR><FONT
face='"Verdana", Geneva, MS sans-serif' color=#448593 size=-1><B>MOHAMED
RAOUF</B></FONT><BR><B>ICQ#: <FONT color=#4051c8>44365427</FONT></B><BR>
<TABLE border=0>
<TBODY>
<TR>
<TD vAlign=top><FONT face="Verdana,Geneva, MS sans-serif" color=#448593
size=-2><B>Current ICQ status:</B> </FONT></TD>
<TD vAlign=bottom><IMG
src="http://web.icq.com/whitepages/online?icq=44365427&img=21">
</TD></TR></TBODY></TABLE><FONT face=Wingdings size=3><B>+</B></FONT> <A
href="http://wwp.icq.com/44365427"><B>More ways to contact me
</B></A><BR><B>__________________________________________________________________</B><BR></FONT></DIV></BODY></HTML>