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 port communication using rs232

Status
Not open for further replies.

akshay985

Member level 4
Joined
Jan 6, 2011
Messages
68
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,288
Location
maharastra,india
Activity points
1,676
I m using 89c51 for serial port communication.
I m taking binary data from port2 and converting it to ascii and then sending it to serial buffer ,
for binary(00)b ascii code is 0x30 , but the data read at vterminal is unreadable .
plz help me with correct code. i m sending the current code i have developed.View attachment rs232 com.txt
 

#include<REG51.H>
#include<stdio.h>
#include<string.h>

unsigned char data_upper,data_lower,data_convert_lower,data_convert_upper;
void delay_1ms(unsigned int);

void lcdcmd(unsigned char);

void serial_init(); //initialise rs232 communication with com1
void lcddata();
sbit enable = P3^6 ;
sbit rs = P3^7;
unsigned char data_sent;
unsigned char port_data;
// enable equ P2^0;
void main()
{
P0=0xFF;
// P2=0xFF;
P1=0xFF;
/* lcdcmd(0x38);
// delay_1ms(5);
lcdcmd(0x0F);
// delay_1ms(2);
lcdcmd(0x80);
// delay_1ms(2);
lcdcmd(0x06); */
serial_init(); //serial port initialiase

while(1){

// P1=P2;

port_data=P2; //read data from port2 and send to serial port
data_lower = port_data & 0x0F;
data_convert_lower = data_lower | 0x30; //convert to hex code 0x30 to 0x39 for digits
data_sent = data_convert_lower;
P1= data_sent;
/*
data_upper = port_data & 0xF0;
data_upper = data_upper >> 4;
data_convert_upper = data_upper | 0x30;
data_convert_upper = data_convert_upper << 4;
data_sent = data_convert_upper | data_convert_lower;
*/
SBUF=data_sent; // send hex data to serial buffer
// delay();

// lcddata();
// lcddata();
while(TI==0);
TI=0;

}
}

void serial_init()
{
TMOD = 0x20; // 0x20 for serial data transmit mode
TH1=0xFD; // set baud rate to 9600
SCON=0x50;
TR1=1;
TI=0;

}

void lcdcmd(unsigned char cmd)
{
P0=cmd;
rs=0;
enable=1;
delay_1ms(1);
enable=0;
}

void lcddata()
{
unsigned char var1;

P0=data_sent;
rs=1;
enable=1;
delay_1ms(5);
enable=0;

}

void delay_1ms(unsigned int x)
{
unsigned char i;
for(i=0;i<=x;i++)
{
TMOD=0x01;
TL0=0xAA;
TH0=0xFF;
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
}
}

please verify this modified code.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top