[LCP]Parallel programming problem

Mohamed Raouf mohamed.raouf at link.net
Sat Jul 6 05:35:07 UTC 2002


 I  ran the gdb and it gave me the following message "program received
signal SIGSEGV Segmentation fault   0x08048607 in turnmot( )"
I tried to modify the "turnmot" function but I still have the same message
displayed
Is there any one who could tell me the right syntax at which i can write the
function "turnmot"

Here is my program again


 // 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);
}



----- Original Message -----
From: "Greg Black" <gjb at gbch.net>
To: <linuxcprogramming at lists.linux.org.au>
Sent: Friday, July 05, 2002 4:37 AM
Subject: Re: [LCP]Parallel programming


> "Mohamed Raouf" wrote:
>
> | 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)"
>
> So run it under gdb and see where the problem occurs.  Then step
> through the code leading up to the crash and see what you've
> done wrong.  Then fix it.
>
> _______________________________________________
> This is the Linux C Programming List
> :  http://lists.linux.org.au/listinfo/linuxcprogramming List





More information about the linuxCprogramming mailing list