rotina no sdcc ler rx serial e comparar p tomada de decisão!

alguem tem alguma rotina q faça isto:
#include <8051a.h>
#include <stdio.h>
#include <intrpt.h>
unsigned char x;
int c;
int d;
int i, index;
int buffer[3];
int t;
void umseg() {for(t=1;t<1875;t++); }
void tempo()
{ int tempox;
for (tempox=1; tempox < 200; tempox++);
}
void tx (char c) // funcao para transmitir pela serial
{
TI = 0;
SBUF = c;
while ( TI == 0);
}
void write (char *c)
{
for(;*c!=0;c++) tx(*c);
}
interrupt recser (void) // interrupcao da serial sempre que chega um dado
{
if (RI == 1)
{ RI = 0;
buffer[index]=SBUF;
index++;
} }
void ln() {write("\x0A"); write("\x0D");}
void lf() {write("\x0A"); }
void cr() {write("\x0D"); }
void main(void) // Programa principal
{ set_vector(SINT,recser);
EA=1; // habilita interrupcao geral
ES=1; // habilita interrupcao geral
SCON = 0X50;
TMOD=0x20;
TR1=1;
REN = 1;
TH1 = 253; // 232 seleciona o baud rate
PS=1; // da prioridade para interrupcao serial
P2=255;
P0=255;
P3_BITS.B4=0;
index=0;
P2_BITS.B0=0;
P2_BITS.B1=0;
P2_BITS.B2=0;
P2_BITS.B3=0;
for (;;) { /*if (buffer[0]!='$') {index=0; }
if (index >= 3) { // rele p2.0
if ((buffer[0]=='$') && (buffer[1]=='L') && (buffer[2]=='0')) {P2_BITS.B0=1;}
if ((buffer[0]=='$') && (buffer[1]=='D') && (buffer[2]=='0')) {P2_BITS.B0=0;}
// rele p2.1
if ((buffer[0]=='$') && (buffer[1]=='L') && (buffer[2]=='1')) {P2_BITS.B1=1;}
if ((buffer[0]=='$') && (buffer[1]=='D') && (buffer[2]=='1')) {P2_BITS.B1=0;}
// rele p2.2
if ((buffer[0]=='$') && (buffer[1]=='L') && (buffer[2]=='2')) {P2_BITS.B2=1;}
if ((buffer[0]=='$') && (buffer[1]=='D') && (buffer[2]=='2')) {P2_BITS.B2=0;}
// rele p2.3
if ((buffer[0]=='$') && (buffer[1]=='L') && (buffer[2]=='3')) {P2_BITS.B3=1;}
if ((buffer[0]=='$') && (buffer[1]=='D') && (buffer[2]=='3')) {P2_BITS.B3=0;}
index=0;
}
/*
if (P0_BITS.B0==0)
{ write("A"); tempo(); } if (P1_BITS.B0==1) { write("P10L"); tempo(); }
if (P0_BITS.B1==0)
{ write("P11D"); tempo(); } if (P1_BITS.B1==1) { write("P22L"); tempo(); }
/* if (P2_BITS.B0==0)
{ write("P20D"); tempo(); } if (P2_BITS.B0==1) { write("P20L"); tempo(); }
if (P2_BITS.B1==0)
{ write("P21D"); tempo(); } if (P2_BITS.B1==1) { write("P21L"); tempo(); }
if (P2_BITS.B2==0)
{ write("P22D"); tempo(); } if (P2_BITS.B2==1) { write("P22L"); tempo(); }
if (P2_BITS.B3==0)
{ write("P23D"); tempo(); } if (P2_BITS.B3==1) { write("P23L"); tempo(); }
}}
este era com o compilador antigo que eu usava, mudei p o sdcc pois não aguentava mais ter que programar no win98 e não tenho esta rotina p o sdcc.
Alguem pode me ajudar?
#include <8051a.h>
#include <stdio.h>
#include <intrpt.h>
unsigned char x;
int c;
int d;
int i, index;
int buffer[3];
int t;
void umseg() {for(t=1;t<1875;t++); }
void tempo()
{ int tempox;
for (tempox=1; tempox < 200; tempox++);
}
void tx (char c) // funcao para transmitir pela serial
{
TI = 0;
SBUF = c;
while ( TI == 0);
}
void write (char *c)
{
for(;*c!=0;c++) tx(*c);
}
interrupt recser (void) // interrupcao da serial sempre que chega um dado
{
if (RI == 1)
{ RI = 0;
buffer[index]=SBUF;
index++;
} }
void ln() {write("\x0A"); write("\x0D");}
void lf() {write("\x0A"); }
void cr() {write("\x0D"); }
void main(void) // Programa principal
{ set_vector(SINT,recser);
EA=1; // habilita interrupcao geral
ES=1; // habilita interrupcao geral
SCON = 0X50;
TMOD=0x20;
TR1=1;
REN = 1;
TH1 = 253; // 232 seleciona o baud rate
PS=1; // da prioridade para interrupcao serial
P2=255;
P0=255;
P3_BITS.B4=0;
index=0;
P2_BITS.B0=0;
P2_BITS.B1=0;
P2_BITS.B2=0;
P2_BITS.B3=0;
for (;;) { /*if (buffer[0]!='$') {index=0; }
if (index >= 3) { // rele p2.0
if ((buffer[0]=='$') && (buffer[1]=='L') && (buffer[2]=='0')) {P2_BITS.B0=1;}
if ((buffer[0]=='$') && (buffer[1]=='D') && (buffer[2]=='0')) {P2_BITS.B0=0;}
// rele p2.1
if ((buffer[0]=='$') && (buffer[1]=='L') && (buffer[2]=='1')) {P2_BITS.B1=1;}
if ((buffer[0]=='$') && (buffer[1]=='D') && (buffer[2]=='1')) {P2_BITS.B1=0;}
// rele p2.2
if ((buffer[0]=='$') && (buffer[1]=='L') && (buffer[2]=='2')) {P2_BITS.B2=1;}
if ((buffer[0]=='$') && (buffer[1]=='D') && (buffer[2]=='2')) {P2_BITS.B2=0;}
// rele p2.3
if ((buffer[0]=='$') && (buffer[1]=='L') && (buffer[2]=='3')) {P2_BITS.B3=1;}
if ((buffer[0]=='$') && (buffer[1]=='D') && (buffer[2]=='3')) {P2_BITS.B3=0;}
index=0;
}
/*
if (P0_BITS.B0==0)
{ write("A"); tempo(); } if (P1_BITS.B0==1) { write("P10L"); tempo(); }
if (P0_BITS.B1==0)
{ write("P11D"); tempo(); } if (P1_BITS.B1==1) { write("P22L"); tempo(); }
/* if (P2_BITS.B0==0)
{ write("P20D"); tempo(); } if (P2_BITS.B0==1) { write("P20L"); tempo(); }
if (P2_BITS.B1==0)
{ write("P21D"); tempo(); } if (P2_BITS.B1==1) { write("P21L"); tempo(); }
if (P2_BITS.B2==0)
{ write("P22D"); tempo(); } if (P2_BITS.B2==1) { write("P22L"); tempo(); }
if (P2_BITS.B3==0)
{ write("P23D"); tempo(); } if (P2_BITS.B3==1) { write("P23L"); tempo(); }
}}
este era com o compilador antigo que eu usava, mudei p o sdcc pois não aguentava mais ter que programar no win98 e não tenho esta rotina p o sdcc.
Alguem pode me ajudar?