Microcontroller › 8051 › Problem in serial communication with 89S52
- This topic has 2 replies, 2 voices, and was last updated 10 years, 10 months ago by Aniket Kulkarni.
-
AuthorPosts
-
November 5, 2013 at 1:39 pm #3852Aniket KulkarniParticipant
Hello,
I am a beginner with 8051 family. I am trying to implement serial communication using 89S52 with PC. The string (rather a singel chracter at this stage) will be transmitted through Hyperterminal and after reception the received text (what ever it be) has to be displayed on LCD. The problem is when I am debugging the code in keil, it's showing proper output i.e. the values at the lcd port are proper ASCII values of particular chracter being entered. But when it comes to hardware, the LCD is showing chracters that seems like those sent by aliens. I am progisp for burning the code, and a kit from HPS electronics. The code i am usin g is as follows:
#include <REGX52.H>sbit rs= P2^0;sbit rw= P2^1;sbit en= P2^2;void msdelay(unsigned int itime){unsigned int i,j;for(i=0;i<itime;i++)for(j=0;j<1275;j++);}void lcdcmd(unsigned char value){P1=value;msdelay(5);rs=0;msdelay(5);rw=0;msdelay(5);en=1;msdelay(5);en=0;}void lcd_data(unsigned char value){P1=value;msdelay(5);rs=1;msdelay(5);rw=0;msdelay(5);en=1;msdelay(5);en=0;}void uart_init(){TMOD=0x20;TH1=0xFD;SCON=0x50;TR1=1;}void lcd_init(){lcdcmd(0x38);msdelay(10);lcdcmd(0x0E);msdelay(10);lcdcmd(0x01);msdelay(10);lcdcmd(0x06);msdelay(10);lcdcmd(0x80);msdelay(10);}void main(){unsigned char str;unsigned int i;uart_init();msdelay(250);lcd_init();msdelay(250);while(1){while(RI==0);RI=0;str=SBUF;msdelay(250);lcd_data(str);msdelay(250);}}
The reason behind introducing so many delays is I thought their may be some latency. Please help.
November 6, 2013 at 5:27 am #10574AJISH ALFREDParticipantHi Aniket,
The problem is there in your hardware itself. Please check the circuit for any misconnections, short circuit of the data pins etc. Check the enable pin and make sure that the voltage at the read/write pin is 0.
November 8, 2013 at 7:14 am #10586Aniket KulkarniParticipantThank you Sir for replying.
I did. And after that tried to run the most basic code to serially transmit the character ‘A’ continuously. To my surprise what i got is a heart and one more character. On keil simulation, it is perfectly transmitting ‘A’. I have checked the serial to USB converter that I am using by shorting its 2 & 3 pin. It transmits each and every character nicely. As far as the burner is concerned, my other simple code such as blinking LED and so on are working fine. I displayed hello world (basic one, just to check LCD) and worked out well. So I am quite puzzled now where the problem is. Changed my MAX232 as well thinking it to be the culprit.By the way, one more question, a strange thing I noticed with another program of getting an ECHO, once a character was received, the SCON value became 0x55(0101 0101) in place of 0x51 (as the RI sets, 0101 0001). Even after clearing RI, the value becomes 0x54 (0101 0100<–cleared RI) thus making all further communication meaning less and it doesn’t understand 8 bit data anymore because of TB8 or RB8 being set. though the problem can be solved by giving SCON 0x50 again and again, but that’s certainly not the solution.please help.PS:- It receives ‘c’, ‘d’ and ‘g’ nicely8-O -
AuthorPosts
- You must be logged in to reply to this topic.