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.

serial communication betwen 8051 and Arduino

Status
Not open for further replies.

tapu

Full Member level 4
Joined
Sep 15, 2014
Messages
234
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
india
Activity points
3,041
Dear All,
I want to send data like decimal numbers 0 to 99 from serial port of 89S52 to Serial port of arduino UNO .Is it possible?But how to write code.please reply.
Thanks,
Tepu
 

Yes, it can be done. UART to UART with or without RS232 it can be done. If the distance between 8051 and Arduino is small then you can use the TTL UART interface.

Your 0 to 99 value is byte-sized and so you just have to send byte data to Arduino from 8051.
 

I have written this code but data not detect on arduino.
8051 code:
Code:
#include <REGX52.H>

sbit e1=P1^7;
sbit e3=P2^1;
sbit e0=P2^0;
sbit e2=P2^2;
sbit e4=P2^3;
sbit buz=P1^7;

sbit sw=P1^3;
sbit sw1=P2^5;
sbit sw2=P2^6;
sbit sw3=P2^4;

//sbit rinc=P3^3;
//sbit rdec=P3^2;
//sbit rset=P3^1;
bit ring=0;

bit a;
//#define off P2=0x00
unsigned int min;
unsigned char dat;
unsigned char message;
	 void display();
  void loop();

void Seg8_decimal2(min);
Send2lcd(unsigned char value);
 void delay_ms(unsigned int ms_count);
   void delay_us(unsigned int us_count);
 unsigned char pt,pt1,pt2,pt3,span;
//unsigned char num[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};

void main()
	
{


	min=00;
	
	
	/*
		SCON=0x50;
    TMOD=0x20;
		TH1=253;
    TR1=1;
*/
	
	TMOD |= 0X20;                       // Timer 1 in mode 2 
	TH1=-24;                            // Baud rate of 1200
	SCON = 0X50;                         //Asynchronous 8-bit data 
	TR1 = 1;                             // Turn ON the timer
         
	while(1)
{
	/*
	if(ring==1)
	{
		SBUF=message;
		ring=0;
	}
	*/
		SBUF =min;
	while(TI==0);
	TI=0;

 loop();
	
		if(a==1)
		{
		span++;
    buz=0;
	delay_ms(10);
    buz=1;

		if(span==70)
		{
a=0;		
	buz=1;	
			span=0;
		}			
	  }
		
}
}






  void loop()
	{
		
		//delay_ms(100);

		 Send2lcd(min);
 Seg8_decimal2(min);
		
		//if(sw==0)
		//rinc=0;
		//else
			//rinc=1;
	
		//if(sw1==0)
		//rset=0;
		//else
		//rset=1;

		
		//if(sw2==0)
		//rdec=0;
		//else
			//rdec=1;
	

	pt=1;
while(!sw)
{
	
	if(pt==1)
	{
min++;
ring=1;		
	
	pt=0;

	}
	 Send2lcd(min);
 Seg8_decimal2(min);
	//delay_ms(10);

	a=1;
	
}

while(!sw1)
{
//while(sw==0);

	if(pt==1)
	{
min--;
		pt=0;
	}
	 Send2lcd(min);
 Seg8_decimal2(min);
	//delay_ms(10);
	if(min==0xffff)
		min=999;
	
}


while(!sw2)
{
	
	if(pt==1)
	{
min=0;
	pt=0;

	}
	 Send2lcd(min);
 Seg8_decimal2(min);
	//delay_ms(10);

	a=1;
}





/*
while(!sw3)
{
	
	if(pt==1)
	{ 
min=0;
	pt=0;

	}
	 Send2lcd(min);
 Seg8_decimal2(min);
	//delay_ms(10);

	a=1;
}
*/
	//rinc=1;


}

void Seg8_decimal2(min)

{
unsigned int Lcd_hr,Lcd_t,Lcd_o;

Lcd_hr=min%100;
Lcd_t=Lcd_hr/10;
Lcd_o=Lcd_hr%10;

	
dat=Lcd_t+0x30;
		display();

	//P1=0x04;
	e3=1;	
	
	delay_ms(5);
	e0=e2=e3=0;
dat=Lcd_o+0x30;
		display();

//P1=0x08;
	e2=1;	

delay_ms(5);
		e0=e2=e3=0;


if(min>99)
	if(min<=199)
{
	
P0=0xf9;
	//P0=0xf9;
e0=1;

delay_ms(5);

		e0=e1=e2=e3=0;
}



if(min>199)
	if(min<=299)
{
	
P0=0xa4;
	//P0=0xf9;
e0=1;

delay_ms(5);

		e0=e1=e2=e3=0;
}

if(min>299)
	if(min<=399)
{
	
P0=0xb0;
	//P0=0xf9;
e0=1;

delay_ms(5);

		e0=e1=e2=e3=0;
}

if(min>399)
	if(min<=499)
{
	
P0=0x99;
	//P0=0xf9;
e0=1;

delay_ms(5);

		e0=e1=e2=e3=0;
}









if(min>499)
	if(min<=599)
{
	
P0=0x92;
	//P0=0xf9;
e0=1;

delay_ms(5);

		e0=e1=e2=e3=0;
}



if(min>599)
	if(min<=699)
{
	
P0=0x82;
	//P0=0xf9;
e0=1;

delay_ms(5);

		e0=e1=e2=e3=0;
}

if(min>699)
	if(min<=799)
{
	
P0=0xf8;
	//P0=0xf9;
e0=1;

delay_ms(5);

		e0=e1=e2=e3=0;
}

if(min>799)
	if(min<=899)
{
	
P0=0x80;
	//P0=0xf9;
e0=1;

delay_ms(5);

		e0=e1=e2=e3=0;
}


if(min>899)
	if(min<=999)
{
	
P0=0x90;
	//P0=0xf9;
e0=1;

delay_ms(5);

		e0=e1=e2=e3=0;
}








if(min>999)
{
min=00;
	
	
	
}

}



Send2lcd(unsigned char value)
	
{
unsigned char buf1,buf2,buf = 0;

buf1 = value & 0xF0; /* Filter for high byte */
buf1 = (buf1>>4); /* Convert to ascii code */
buf2 = value & 0x0F; /* Filter for low byte */
buf=(buf1*10)+buf2;

return buf;
}


	
	




 void delay_ms(unsigned int ms_count)
 {
        while(ms_count!=0)
         {
            delay_us(112);   //delay_us is called to generate 1ms delay
             ms_count--;
            }
   }
 
	 
	 
  void delay_us(unsigned int us_count)
 {  
    while(us_count!=0)
      {
         us_count--;
      }												   
 }
 
	 void display()
	 {
		 if(dat==0x30)
		P0=0xc0;
		//P0=0x3f;	 
		 
		 
		 if(dat==0x31)
		P0=0xf9;
		//P0=0x06;	 

			 
		 if(dat==0x32)
		P0=0xa4;	
		//P0=0x5b;	 

	 
		 if(dat==0x33)
		P0=0xb0;
		//P0=0x4f;	 

	 
		 if(dat==0x34)
		P0=0x99;
		// P0=0x66;	 

 
		 if(dat==0x35)
		P0=0x92;
		//P0=0x6d;	 

 
		 if(dat==0x36)
		P0=0x82;
		//P0=0x7d;	 

	 
		 if(dat==0x37)
		P0=0xf8;
		//P0=0x07;	 
		 
	 
		 if(dat==0x38)
		P0=0x80;	
		//P0=0x7f;	 

	 
		 if(dat==0x39)
		P0=0x90;
		//P0=0x6f;	 
		 

		 }
	
Arduino code:
[CODE]

int incommingByte=0;
void setup() {
  // put your setup code here, to run once:

 Serial.begin(9600);
 pinMode(13, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:

Serial.read();
incommingByte=Serial.read();
if(incommingByte==2)
 digitalWrite(13, HIGH);


}


circuit diagram:
[ATTACH]157692._xfImport[/ATTACH]

[/CODE]
 
Last edited:

I can't study these codes like this.

If you want me to debug your code and find out the bug and tell you what needs to be fixed or if you want me to fix the code then zip 8051 Keil and Arduino sketches separately (all project files zipped) and attach it here.

I will then make a Proteus simulation file to debug and fix your code.
 
Last edited:

I agree, the code is very badly formatted and confusing to say the least.

Additionally, the resistor packs in the schematic seem to do nothing useful.

The Arduino end should work but all it does is make pin 13 high when it receives 0x02, note this is not the character '2' which has ASCII code 0x32.
I can't make any sense of the 8051 end, the schematic is an LED driver but the code says LCD and it refers to 'ring' which I assume is to do with the ring detect signal on a modem link but none is present. The comment also says the baud rate is set to 1200 in the 8051 but 9600 at the Arduino end, they must be set to the same speed.

Brian.
 

Thank you for Reply
Here are my project files
 

Attachments

  • MyfirstArduino.rar
    3.4 KB · Views: 108

Maybe you don't know how to zip and post a complete Keil project.

You have attached only .uvproj file. What is the use of it without other project files?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top