Discussion in "8051 Discussion Forum" started by    Ansh12    Feb 25, 2018.
Sun Feb 25 2018, 10:06 pm
#1
I want to see character back to terminal whatever I type on terminal. My code is not working

#include <reg51.h>


void uart_init();          
char getc();              
void putc (char c);          
void puts(char *s);        

void uart_init()                  // Initializes UART peripheral
{
  TMOD = 0x20;                    // Timer1, mode 2
  TH1  = 0xFD;                    // 9600 bps 11059200 Clock, core(12cycle), uart(SMOD=0)
  TL1  = 0xFD;                    // First byte timing
  SCON = 0x52;                    // 0x52 : 0101 0010  Receive Enable, TI as 1 (set as ready)
  TR1  = 1;
}

char getc()                       // Polled method to Receive a byte(8bit)
{
  while (RI == 0);                // Wait until a byte has been received                        
  RI = 0;                         // Acknowledge RI
  return SBUF;                   
}

void putc (char c)           
{
  while (TI == 0);                                  
  SBUF = c;                      
	
}

void puts(char *s)           // Typical puts for uart Transmit a string-null-terminated
{
  while (*s!=0)                   // Check for null byte termination
  putc(*s++);                // and send each byte using uart
}


void main ()
{
   char c;

   uart_init();             // Init UART to desired settings
   puts("Anssh");

   while (1) 
	{                         // This loop echoes back whatever is typed on PC Keyboard
     c = getc();            //    get next byte from PC
     putc(c);               //    and send it back as echo
  }

}

How to get echo character on terminal?

Attachment
Mon Feb 26 2018, 04:21 am
#2
You need to reset TI

void putc (char c)           
{
  while (TI == 0);                                  
  TI = 0;
  SBUF = c;                      
}
 
 Ansh12 like this.
Mon Feb 26 2018, 06:58 am
#3


You need to reset TI

ExperimenterUK



Can you give a little more information about this. How to do it ?
Wed Feb 28 2018, 04:22 am
#4
Use the code in my last post.
Wed Feb 28 2018, 04:58 am
#5


Use the code in my last post.

ExperimenterUK


I did but code is not working
#include <reg51.h>

 
 
void uart_init();          
char getc();              
void putc (char c);          
void puts(char *s);        
 
void uart_init()                  // Initializes UART peripheral
{
  TMOD = 0x20;                    // Timer1, mode 2
  TH1  = 0xFD;                    // 9600 bps 11059200 Clock, core(12cycle), uart(SMOD=0)
  TL1  = 0xFD;                    // First byte timing
  SCON = 0x52;                    // 0x52 : 0101 0010  Receive Enable, TI as 1 (set as ready)
  TR1  = 1;
}
 
char getc()                       // Polled method to Receive a byte(8bit)
{
  while (RI == 0);                // Wait until a byte has been received                        
  RI = 0;                         // Acknowledge RI
  return SBUF;                   
}
 

 
void putc (char c)           
{
  while (TI == 0);                                  
  TI = 0;
  SBUF = c;                      
}
 
void puts(char *s)           // Typical puts for uart Transmit a string-null-terminated
{
  while (*s!=0)                   // Check for null byte termination
  putc(*s++);                // and send each byte using uart
}
 
 
void main ()
{
   char c;
 
   uart_init();             // Init UART to desired settings
   puts("Anssh");
 
   while (1) 
	{                         // This loop echoes back whatever is typed on PC Keyboard
     c = getc();            //    get next byte from PC
     putc(c);               //    and send it back as echo
  }
 
}
Wed Feb 28 2018, 05:45 am
#6
I tested the code you posted in Proteus and it works.
Be sure Proteus is loading the correct code.
If it still does not work, post your Proteus and Keil files.
Wed Feb 28 2018, 06:11 am
#7


I tested the code you posted in Proteus and it works.
Be sure Proteus is loading the correct code.
If it still does not work, post your Proteus and Keil files.

ExperimenterUK


Please look at the attached file

Attachment
Wed Feb 28 2018, 07:18 am
#8
In the rar file you just posted,
the routine "void putc (char c) "
does not contain the line "TI=0;"
Add it.
Wed Feb 28 2018, 09:02 am
#9


In the rar file you just posted,
the routine "void putc (char c) "
does not contain the line "TI=0;"
Add it.

ExperimenterUK


sorry for posting wrong file but still I am not getting echo character

look at this file
Attachment
Thu Mar 01 2018, 03:42 am
#10
TI= 0 is still missing
from putc (char c)

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Oariorrca
Wed Oct 16 2024, 01:14 am
Oariorvln
Wed Oct 16 2024, 12:59 am
Jamesrat
Wed Oct 16 2024, 12:56 am
Cazrwam
Tue Oct 15 2024, 04:50 pm
Cazrlby
Tue Oct 15 2024, 04:34 pm
Ameliaror
Tue Oct 15 2024, 03:02 pm
GlendaInvaf
Tue Oct 15 2024, 02:30 pm
Georgepucky
Tue Oct 15 2024, 12:11 am