convert .c to .pde

sir i need to convert the c code to pde arduino format …plz help me

ext0.c (3.77 KB)

(deleted)

Which microcontroller was this written for and which C compiler was used?

You're going to have problems converting it to Arduino C.
First, there is no system library called reg52.h so you'll have to find out what it does. Presumably it defines what "sbit" means.

sbit lmotorp = P2^7;

I suspect that this statement means that lmotorp is bit 7 of P2. But unless reg52.h does some clever definitions (including what P2 is), it isn't going to mean that to the C compiler used by the Arduino IDE which defines '^' to be the exclusive-or operation.

You can delete the delay function in your code because there is a delay function included with the Arduino header which delays the specified number of milliseconds.

Pete

Here is a good start:

#include <stdlib.h>
#include <string.h>

// Pin number declarations
const byte lmotorpPin = 7;
const byte lmotornPin = 6;
const byte rmotorpPin = 5;
const byte rmotornPin = 4;
const byte tesPin = 3;
const byte intrPin = 2;
const byte pen1Pin = 9;
const byte pen2Pin = 8;
const byte indicationPin = 10;

char pa[20], pacopy[20]; // = '\0'

int count, angle = 0, dist = 0, cw, acw, fwd;

// Attach this ISR to the interrupt 0 (pin 2)
void ex0_isr (void) {         //count pulses
  count++;                           // Increment the count
  digitalWrite(indicationPin, !digitalRead(indicationPin));
}

void compute(char str[15]) {          //separate angle and distance
  int angle = 0, dist = 0, i = 0, j = 0;
  char dis[5], angl[5];
  for (i = 1, j = 0; str[i] != 'd'; i++, j++) //distance
  {
    dis[j] = str[i];
  }
  dist = atoi(dis);
  //P1 = dist;
  j = 0;
  for (i = i + 1; str[i] != 'a'; i++, j++)     //angle
  {
    angl[j] = str[i];
  }
  angle = atoi(angl);
  //P1 = angle;
  //indication = ~indication;
}

void rotate(int cw)                         //rotate clokwise
{
  count = 0;
  while (count <= cw)
  {
    digitalWrite(lmotorpPin, HIGH);
    digitalWrite(lmotornPin, LOW);
    digitalWrite(rmotorpPin, LOW);
    digitalWrite(rmotornPin, LOW);
    //indication = ~indication;
    //delay(500);
    count++;
  }
}

void revrotate(int acw)                           //rotate anti-clockwise
{
  count = 0;
  while (count <= acw)
  {
    digitalWrite(lmotorpPin, LOW);
    digitalWrite(lmotornPin, HIGH);
    digitalWrite(rmotorpPin, LOW);
    digitalWrite(rmotornPin, LOW);
    //indication = ~indication;
    //delay(500);
    count++;
  }
}

void drive(int fwd)                              //forward movement
{
  count = 0;
  while (count <= fwd)
  {
    digitalWrite(lmotorpPin, HIGH);
    digitalWrite(lmotornPin, LOW);
    digitalWrite(rmotorpPin, HIGH);
    digitalWrite(rmotornPin, LOW);
    //indication = ~indication;
    //delay(500);
    count++;
  }
}

void rest()
{
  digitalWrite(lmotorpPin, LOW);
  digitalWrite(lmotornPin, LOW);
  digitalWrite(rmotorpPin, LOW);
  digitalWrite(rmotornPin, LOW);
}


void stoppen()
{
  digitalWrite(pen1Pin, LOW);
  digitalWrite(pen2Pin, LOW);
}

void setup() {
  //Declaring Outputs
  digitalWrite(lmotorpPin, LOW);
  digitalWrite(lmotornPin, LOW);
  digitalWrite(rmotorpPin, LOW);
  digitalWrite(rmotornPin, LOW);
  digitalWrite(pen1Pin, LOW);
  digitalWrite(pen2Pin, LOW);
  digitalWrite(indicationPin, LOW);
  digitalWrite(tesPin, LOW);

  //Interrupts Enabling
  attachInterrupt(0, ex0_isr, RISING);

  digitalWrite(intrPin, LOW);

  //Initialise UART
  Serial.begin(19200);
}

void loop() {
  Serial.readBytesUntil('\n', pa, sizeof pa);

  compute(pa);

  if (pa[0] == 'g') {
    digitalWrite(pen1Pin, LOW);
    digitalWrite(pen2Pin, HIGH);
    //delay(100);
    //indication = 0;
    stoppen();
  }
  else if (pa[0] == 'd') {
    digitalWrite(pen1Pin, HIGH);
    digitalWrite(pen2Pin, LOW);
    //delay(100);
    //indication = 1;
    stoppen();
  }

  rotate(angle);
  delay(250);
  drive(dist);
  delay(250);
  revrotate(angle);
  delay(250);
  //rest();
  digitalWrite(pen1Pin, LOW);
  digitalWrite(pen2Pin, LOW);
  stoppen();
}