89c51 interface with lcd 16*2 via rs 232

Status
Not open for further replies.

ronkpatell

Member level 5
Joined
Feb 2, 2012
Messages
85
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
ahemdabad
www.epromsis.com
Activity points
1,894
hi
i want interface rs232 with 89c51 .
my main ajanda is what i writing in hyper terminal that may be display in LCD.
that is possible
pls help me.
 

It is.
1. Connect Tx, Rx and GND between serial port on PC or USB or serial convertor and ur microcontroller board RS232.
2. Set up an interrupt routine for RS232 communication in MCU, so that whenever u type in any letter the transmit receive register will receive the byte, save the byte in RAM and reset the interrupt flag bit.
3. Connect 16x2 LCD to MCU thru GPIO's (refer HD44780U_LCD_Controller datasheet on details of how to setup LCD for data write).
4. After initializing LCD, simply write to its data register at character position u wish by setting up address.
5. You are done.
 
thanks
but i already done the hardware connection .also interface lcd with 89c51.i.e i can show the my name on lcd what was i wrote in C progrming.
that may be show in hyper terminal?

- - - Updated - - -

can u give me some code for that?
 

ok, here is some code, i had written years ago for at89c51.

Code:
#include <at89s53.h>

unsigned char xdata serial_buf=0;

void serial_interrupt( )interrupt 4 using 3
{
	if( TI )
	{
		TI = 0;
		//SBUF = 'A';
	}
	if( RI )
	{
		RI = 0;
		serial_buf = SBUF;
		SBUF = serial_buf;
	
	}
}
void timer1_init(void)
{
	SCON = 0X50;
	TMOD = 0X20;
 	TH1 = 0XFD;
	TR1 = 1;
	TI = 1;
}
void main(void)
{
	EA = 1;
	ES = 1;
	timer1_init();
	while(1)
	{
		;
	}
}

here's another example:
Code:
#include<at898252.h>
unsigned char xdata temp;
bit recv = 0, finish = 1;

void serial_int() interrupt 4 using 3
{
	if(TI)
	{
		TI = 0;
		if(finish)
			return;
		SBUF = temp;
		finish = 1;
	}
	if(RI)
	{
		RI = 0;
		finish = 0;
		temp = SBUF;
		recv = 1;
	}
}

void main(void)
{
//	IE = 0x90;
	EA = 1;
	ES = 1;
	SCON = 0x5C;
	TMOD = 0x20;
	TH1 = 0xFA;
	TL1 = 0xFA;
//	T2CON = 0x30;
//	T2MOD = 0x00;
//	RCAP2H = 0xff;
//	RCAP2L = 0xdc;//0xe6;
	TR1 = 1;
	while(1)
	{
		if(recv)
		{
			recv = 0;
			TI = 1;
		}
	}
}

the serial_buf and temp variable value can then be sent to lcd_putc() function in ur code to display it on LCD. You can make a flag check in ur code for any data their in serial_buf and so if it is there, just write it to LCD.
hope that helps...
 
thanks

but i m using 89c51 controller can that code work with that?
i trying that code but still is not working
 
Last edited:

plz check the interrupt number for 89c51. I actually wrote this for at89c51 controller only but almost 3 years ago. im using timer to periodically send data to hyper terminal. If any key press at hyper terminal occurs, i send it to MCU. I currently dont have setup at me, so cant debug and send u code. Try debugging code, It will work.
BTW, whats the issue?
 
i was debug that code and load .hex file in 89c51 .when i was cannect rs232 with hyperterminal and gv Echo .but here i can write anythings but that can't show in lcd.
and i using 89c51 project kit.its crkt diagram is in the link **broken link removed**
 

yes i was just copy ur code
#include<at898252.h>
unsigned char xdata temp;
bit recv = 0, finish = 1;

void serial_int() interrupt 4 using 3
{
if(TI)
{
TI = 0;
if(finish)
return;
SBUF = temp;
finish = 1;
}
if(RI)
{
RI = 0;
finish = 0;
temp = SBUF;
recv = 1;
}
}

void main(void)
{
// IE = 0x90;
EA = 1;
ES = 1;
SCON = 0x5C;
TMOD = 0x20;
TH1 = 0xFA;
TL1 = 0xFA;
// T2CON = 0x30;
// T2MOD = 0x00;
// RCAP2H = 0xff;
// RCAP2L = 0xdc;//0xe6;
TR1 = 1;
while(1)
{
if(recv)
{
recv = 0;
TI = 1;
}
}
}

- - - Updated - - -

and anothere one code for only send data to hyp
#include "reg51.h"
void inici_serie (void)
{
PCON |= 0x80; // SMOD = 1; => transmition rate x2
SCON = 0x50; // Serial port in mode 1
TMOD |= 0x20; // Timer 1, in mode 2
// i. e., timer of 8 bits with autoreload
//TH1 = 256 - (((smod + 1) * f_xtal) / (384 * baud));
TH1 = 0xFA; // for baud = 9600
TL1 = TH0;
// Activa timer0
TR1 = 1;
}
char receive_char (void)
{
RI = 0;
return SBUF;
}
void send_char (char chr)
{
TI = 0;
SBUF = chr
while(!TI);// here i got some error like sytex error
TI = 0;
}
void send_msg (char *msg)
{
TI = 0;
while(*msg)
{
SBUF = *(msg++);
while (!TI);
TI = 0;
}
}
void main (void)
{
char chr;
inici_serie();
send_msg ("Hello!\n\0");
while (1)
{
if (RI) // do echo of the character received
{
chr = receive_char ();
send_char (chr);
}
}
}
 

sorry for late reply. BTW, which compilr are u using? i wrote this on keil uvision. if it is different for u, then plz check the interrupt number, since the code i sent is working. On the other hand, the second code u wrote does not show any serial interrupt routine. Try sending random character to hyper terminal, if it works then, try sending data from hyper terminal to MCU and back to hyper terminal. Also, i dont see the code for lcd character write i.e. lcd_putchar(char) getting called in ur code, why?

I think the only issue is different compiler codes and the way interrupt routines written in both of them is different.
 
yes i m also using keil u vision for compilr .
plz can u gv me code for that i cann't understand why that is not working plz?
bcz i m some newr in that all 8051.

- - - Updated - - -

yes i m also using keil u vision for compilr .
plz can u gv me code for that i cann't understand why that is not working plz?
bcz i m some newr in that all 8051.
 

sorry or late reply buddy.
this code may help u, this code is just sending data from hyper terminal to microcontroller:
Code:
#include <at89s53.h>

unsigned char xdata serial_buf=0;
bit data_flag=0;

void serial_interrupt( )interrupt 4 using 3
{
	if( TI )
	{
		TI = 0;
		//SBUF = 'A';
	}
	if( RI )
	{
		RI = 0;
		serial_buf = SBUF;
	}
}

void main(void)
{
	EA = 1;
	ES = 1;
	SCON = 0X50;
	while(1)
	{
		if(data_flag)
		{
			data_flag = 0;
			lcd_putchar(serial_buf);
		}
	}
}

This code will continuously send data to hyper terminal:
Code:
#include <at89s53.h>

unsigned char xdata serial_buf=0;
bit data_flag=0;

void serial_interrupt( )interrupt 4 using 3
{
	if( TI )
	{
		TI = 0;
		SBUF = 'A';
	}
	if( RI )
	{
		RI = 0;
		serial_buf = SBUF;
	}
}

void main(void)
{
	EA = 1;
	ES = 1;
	SCON = 0X50;
	while(1)
	{
	}
}

set the timer if u want to send data at periodic rate to hyper terminal. I could not find the interrupt information from latest keil user manual. I suggest please take use manual u have with keil, which will be in directory where u installed keil; to find about interrupt number. It may be that the interrupt number im using has been changed into new keil version u r using..!
Also, i see in ur code u used polling, to send and receive data. Plz change that code to interrupt based code.

hope that helps.
 
change the header file from at89s53.h to at89c51.h
and yes u can use the same code. But as i explained, plz check the interrupt number in keil manual.
 
how can check that interpt plz suggest me i dont kw?
i was edit that changes 89s53 to 89c51 but there are a lot of error like warning C318: can't open file 'at89c51.h'
 

make sure if the header file with that name exists in include folder for where the keil is installed.
check the user manual for keil compiler already installed with the compiler and IDE, it will be in the same location as the compiler installed location, the user manual contains all the information on compiler instructions and interrupt routine number since its a construct provided by keil only but no other compiler. The older user manual was named "Keil C51 compiler user guide", since i dont have that one installed, i cant tell u, since it was installed on my previous employers system as licensed copy. Otherwise, u can always go to keil compiler's website and find it, since u must be a licensed user.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…