convertion

sir help me to convert this code to arduino. btw im using gizduino328

// Compiler: Keil, Processor any 8051 core
#include <REGX51.H> // standard 8051 defines
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// -=-=-=-=- Hardware Defines -=-=-=-=-=-=-=
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

char sbuffer[30], ch;
unsigned char pos;
unsigned char read1, read2, read3;

//receive serial character from serial port
char mygetchar(void)
{
char c;
while(!RI);
RI =0;
c = SBUF;
return SBUF;
}

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// -=-=-=-=- Main Program -=-=-=-=-=-=-=
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void main()
{
// -=-=- Intialize variables -=-=-=
pos = 0;

// -=-=- Intialise Serial Port -=-=-=
//Sets up MCU to use 9600 bps @ 11.059 MHz Crystal
SCON = 0x52; // 8-bit UART mode
TMOD = 0x20; // timer 1 mode 2 auto reload
TH1= 0xfd; // 9600 8-n-1
TR1 = 1; // run timer1

// -=-=- Program Loop -=-=-=
while(1)
{
ch = mygetchar(); //loop till character received
if(ch==0x0A) // if received character is , 0x0A, 10 then process buffer
{
pos = 0; // buffer position reset for next reading

// extract data from serial buffer to 8 bit integer value
// convert data from ASCII to decimal
read1 = ((sbuffer[1]-'0')*100) + ((sbuffer[2]-'0')*10) +(sbuffer[3]-'0');
read2 = ((sbuffer[6]-'0')*100) + ((sbuffer[7]-'0')*10) +(sbuffer[8]-'0');
read3 = ((sbuffer[11]-'0')*100) + ((sbuffer[12]-'0')*10) +(sbuffer[13]-'0');

// Do whatever you wish to do with this sensor integer variables
// Show on LCD or Do some action as per your application
// Value of variables will be between 0-255

} else { //store serial data to buffer
sbuffer[pos] = ch;
pos++;
}
} // end while
}// end main

from Blood Pressure Sensor - Serial output [1437] : Sunrom Electronics

im new to this kind of software i just want to explore.

Did you get tired of the responses you got in your other thread?

Code tags man!

Why don't you explain what you want to do instead. That looks like someone was trying to recreate parseInt(). The entire thing may be able to be replaced with a single function call.

A literal conversion, compiles but untested. Also added buffer overflow checking. You will NOT be able to use the serial port to connect to a PC to see the results as the code stands.

char sbuffer[30], ch;
byte pos, read1, read2, read3;


void setup()
{
  Serial.begin(9600);
  // -=-=- Intialize variables -=-=-=
  pos = 0;
}

// -=-=- Program Loop -=-=-=
void loop()
{
  while(Serial.available() > 0)
  {
    ch = Serial.read(); //loop till character received
    if(ch == 0x0A) // if received character is <LF>, 0x0A, 10 then process buffer
    {
      pos = 0; // buffer position reset for next reading
      
      // extract data from serial buffer to 8 bit integer value
      // convert data from ASCII to decimal
      read1 = ((sbuffer[1]-'0')*100) + ((sbuffer[2]-'0')*10) +(sbuffer[3]-'0');
      read2 = ((sbuffer[6]-'0')*100) + ((sbuffer[7]-'0')*10) +(sbuffer[8]-'0');
      read3 = ((sbuffer[11]-'0')*100) + ((sbuffer[12]-'0')*10) +(sbuffer[13]-'0');
      
      // Do whatever you wish to do with this sensor integer variables
      // Show on LCD or Do some action as per your application
      // Value of variables will be between 0-255
      
    } 
    else 
    { //store serial data to buffer
      sbuffer[pos++] = ch;
      if(pos > sizeof(sbuffer))
      {
        pos = 0;
      }
      
    }
  } // end while
}

ocate:
what thread????

http://forum.arduino.cc/index.php?topic=351348.0

That one. Or do we have two people from the same class asking us to do the same homework for each of them?

Riva:
A literal conversion, compiles but untested. Also added buffer overflow checking. You will NOT be able to use the serial port to connect to a PC to see the results as the code stands.

char sbuffer[30], ch;

byte pos, read1, read2, read3;

void setup()
{
  Serial.begin(9600);
  // -=-=- Intialize variables -=-=-=
  pos = 0;
}

// -=-=- Program Loop -=-=-=
void loop()
{
  while(Serial.available() > 0)
  {
    ch = Serial.read(); //loop till character received
    if(ch == 0x0A) // if received character is , 0x0A, 10 then process buffer
    {
      pos = 0; // buffer position reset for next reading
     
      // extract data from serial buffer to 8 bit integer value
      // convert data from ASCII to decimal
      read1 = ((sbuffer[1]-'0')*100) + ((sbuffer[2]-'0')*10) +(sbuffer[3]-'0');
      read2 = ((sbuffer[6]-'0')*100) + ((sbuffer[7]-'0')*10) +(sbuffer[8]-'0');
      read3 = ((sbuffer[11]-'0')*100) + ((sbuffer[12]-'0')*10) +(sbuffer[13]-'0');
     
      // Do whatever you wish to do with this sensor integer variables
      // Show on LCD or Do some action as per your application
      // Value of variables will be between 0-255
     
    }
    else
    { //store serial data to buffer
      sbuffer[pos++] = ch;
      if(pos > sizeof(sbuffer))
      {
        pos = 0;
      }
     
    }
  } // end while
}

Thanq So Much Riva your updated code helped us alot