Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] hi i want to recive 5byte data on sbuf of 89c52

Status
Not open for further replies.

ud23

Advanced Member level 3
Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
185
Reputation
370
Reaction score
180
Trophy points
1,323
Activity points
6,138
hi i want to on /off led when i finsided 5 byte data received on serial port of 89c 52 can any one hav code for it
 

Run a loop for receiving 5 bytes of data or write a program to receive a byte of data and put it in a loop of 5 and then do the operation you wish to do....
 

#include<reg51.h>

unsigned char mydata[5];
unsigned char string[5];
unsigned char rd1[5]={"down_"};
unsigned char rd2[5]={"up___"};
unsigned char rd3[5]={"right"};
unsigned char rd4[5]={"left_"};
//unsigned char mydata["right"]=R;
//unsigned char mydata["left_"]=L;




//unsigned char mydata[5];

sbit led_d=P2^0;
sbit led_l=P2^1;
sbit led_r=P2^2;
sbit led_u=P2^3;

void delay(unsigned int value)
{

int i,j;
for(i=0;i<=value;i++)
for(j=0;j<=1275;j++);
}

void main()
{

P2=0xff; //set p2 as o/p


TMOD=0x20; //Enable Timer 1
TH1=0XFD;
SCON=0x50;
TR1=1;

while(1)
{
unsigned int y;//k;


for(y=0;y<5;y++)
{
while(RI==0);
mydata[y]=SBUF;
// delay(1);
P1=mydata[y];
RI=0;
}

//for(k=0;k<5;k++)
{
// if(P1==rd1[k])
if(P1==rd1[5])
{
led_d=~led_d;
}

//else if(P1==rd4[k])
else if(P1==rd4[5])
{

led_l=~led_l;
}
// else if(P1==rd3[k])
else if(P1==rd3[5])
{

led_r=~led_r;

}

// else if(P1==rd2[k])
else if(P1==rd2[5])
{

led_u=~led_u;

}

}
}

}


here my code pls any suggestion i on/off led after five recived data
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top