Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/23/10 17:24
Read: times


 
#175332 - RS232 to PC
Hi all,

I have a problem with RS232 to PC. Actually, I got the data from PC to 8051 but no data from 8051 to PC. I am using Hyber Terminal to test my program. I believe it is because of the setting of Hyber Terminal, but not sure. Can you guys to check my program.

thanks,


Harrison

...insert code here
 

/*The program is written for testing the communication between 8051 to PC by serial RS232 protocol. When PC sends a data to 8051, it will show on 7-segments display and send back data to PC.*/

#include <reg52.h>
#include <intrins.h>

#define uchar unsigned char
#define uint unsigned int

uchar code LEDData[ ] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E };
uchar temp,buf;

uchar data disbuf[]={0x00,0x00};

/**********************************************************/
void delayms(uint ms)

{
uchar k;
while(ms--)
{
for(k = 0; k < 120; k++);
}
}
/*********************************************************/
void senddata(uchar dat)
{
SBUF =dat;
while(!TI);
TI = 0;
}

/*********************************************************/
void serial() interrupt 4
{
ES = 0; //disable serial interrupt
RI = 0; //reset receiver
buf = SBUF; //get data

switch(buf)
{
case 0x31: senddata('H');break; //got 1£then send H
case 0x32: senddata('E');break; //got 2, then send E
case 0x33: senddata('L');break; //got 3, then send L
case 0x34: senddata('L');break; //got 4, then send L
case 0x35: senddata('O');break; //got 5, then send O
case 0x36: senddata('!');break; //got 6, then send !
default: senddata(buf);break; //got the rest, then send the same data back
}

if(buf!=0x0D)
{
if(buf!=0x0A)
temp =buf;
}

ES = 1; //enable serial interrupt
}
/*********************************************************/
void play() //display on 7 segments
{
disbuf[0]=temp & 0x0f;
P0=LEDData[disbuf[0]];
P2 = 0x7f;
delayms(1);
disbuf[1]=(temp & 0xf0)>>4;
P0=LEDData[disbuf[1]];
P2 = 0xbf;
delayms(1);
P2=0xff;
}
/*********************************************************/
void main(void)
{
P0 = 0xff;
P2 = 0xff;

SCON=0x50;
PCON=0x00;

TMOD=0x20;
EA=1;
ES = 1; //enable serial interrupt
TL1=0xfd;
TH1=0xfd; //baud rate 9600
TR1=1;

while(1) //wait for serial interrupt activate
{
play(); //display
}
}

/*********************************************************/


List of 5 messages in thread
TopicAuthorDate
RS232 to PC            01/01/70 00:00      
   It runs in simulator, but            01/01/70 00:00      
      handshake            01/01/70 00:00      
         To change the handshake            01/01/70 00:00      
            Hyperterminal loop back test            01/01/70 00:00      

Back to Subject List