nigam
Newbie level 1
- Joined
- Mar 11, 2013
- Messages
- 1
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,295
Hi sir,
I am trying to implement a serial communication between PC and microcontroller at89s52.for this I am Initializing SCON,TMOD,TH1,TR1 registers. i am sending a data from hyper terminal in small letters .according to program controller should receive data send it back in capital letters .but I am not getting the result.
At hyper terminal I am getting the same data I am sending, it means there is a close circuit and data is loop back. i have checked the baud rate too, both are working on same baud rate i.e. 9600.I have checked the books, in forums ,and on the websites. there they are giving the same logic and code I am using.
I am not getting how to resolve this problem. please help me
my code is:: the uart.c file
#include<reg51.h>
void uart_tx(unsigned char);
unsigned char * uart_rx(void);
void TXCHAR(unsigned char);
void init_uart(void)
{
//EA=0;
SCON=0x50;
TMOD=0X20;
TH1=0Xfd;
TR1=1;
//ES=1;
//EA=1;
//TI=1;
}
void uart_tx(unsigned char c)
{
SBUF=c;
while(TI==0);
//delayms(2);
TI=0;
return;
}
unsigned char * uart_rx()
{
unsigned char P;
while(!RI);
RI=0;
P= SBUF-32
return P;
}
TXSTR(unsigned char c[])
{
unsigned int i=0;
while(c)
{
uart_tx(c);
i++;
}
}
the main.c file
#include<reg51.h>
#include<string.h>
#include"DELAY.h"
#include"uart.c"
main()
{
unsigned char buff[]={"ankit"};
unsigned char *buff_rcv;
init_uart();
while(1)
{
buff_rcv=uart_rx();
TXSTR(buff_rcv);
}
}
I am trying to implement a serial communication between PC and microcontroller at89s52.for this I am Initializing SCON,TMOD,TH1,TR1 registers. i am sending a data from hyper terminal in small letters .according to program controller should receive data send it back in capital letters .but I am not getting the result.
At hyper terminal I am getting the same data I am sending, it means there is a close circuit and data is loop back. i have checked the baud rate too, both are working on same baud rate i.e. 9600.I have checked the books, in forums ,and on the websites. there they are giving the same logic and code I am using.
I am not getting how to resolve this problem. please help me
my code is:: the uart.c file
#include<reg51.h>
void uart_tx(unsigned char);
unsigned char * uart_rx(void);
void TXCHAR(unsigned char);
void init_uart(void)
{
//EA=0;
SCON=0x50;
TMOD=0X20;
TH1=0Xfd;
TR1=1;
//ES=1;
//EA=1;
//TI=1;
}
void uart_tx(unsigned char c)
{
SBUF=c;
while(TI==0);
//delayms(2);
TI=0;
return;
}
unsigned char * uart_rx()
{
unsigned char P;
while(!RI);
RI=0;
P= SBUF-32
return P;
}
TXSTR(unsigned char c[])
{
unsigned int i=0;
while(c)
{
uart_tx(c);
i++;
}
}
the main.c file
#include<reg51.h>
#include<string.h>
#include"DELAY.h"
#include"uart.c"
main()
{
unsigned char buff[]={"ankit"};
unsigned char *buff_rcv;
init_uart();
while(1)
{
buff_rcv=uart_rx();
TXSTR(buff_rcv);
}
}