Discussion in "8051 Discussion Forum" started by    Ansh12    Feb 25, 2018.
Sun Feb 25 2018, 04:36 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
Sun Feb 25 2018, 10:51 PM
#2
You need to reset TI

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


You need to reset TI

ExperimenterUK



Can you give a little more information about this. How to do it ?
Tue Feb 27 2018, 10:52 PM
#4
Use the code in my last post.
Tue Feb 27 2018, 11:28 PM
#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, 12:15 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, 12:41 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, 01:48 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, 03:32 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
Wed Feb 28 2018, 10:12 PM
#10
TI= 0 is still missing
from putc (char c)

Get Social

Information

Powered by e107 Forum System

Conversation

ExperimenterUK
Thu Mar 14 2019, 08:44 PM
We don't send code,but you can ask for help in the 8051 forum
Thu Mar 14 2019, 11:00 AM
Jui Sanjay Kapare
Hello sir, I want code of interfacing DS18B20 with 8051.plz send the code as early as possible
ExperimenterUK
Mon Jan 07 2019, 03:31 AM
@REVOCATUS please post in the AVR forum
Mon Dec 24 2018, 09:25 AM
REVOCATUS MATEMU
sorry I mean referee boards for player substitution
Mon Dec 24 2018, 09:24 AM
REVOCATUS MATEMU
hi am.looking how to build referee by using Atmega 328 and its codes
Sat Dec 15 2018, 01:45 PM
Arslan ayoub
Hii ,, can I get the simulation of numeric keypad lock on proteus
ExperimenterUK
Mon Dec 03 2018, 05:17 PM
Please post questions in the forum. The chat box is for chat
Mon Dec 03 2018, 06:43 AM
help!me!
help! I don't understand busy flag!
Sun Dec 02 2018, 08:01 PM
ile
hello
Mon Nov 12 2018, 05:58 AM
Pavan_user
i have seen your replica of I2C programming using AT89C51 but i am unable to understand the "ack_bit" variable usage ...looks like it is always 1...can you elaborate how acknowledgment is working....

Downloads

Comments

tutu10
Tue Mar 12 2019, 07:11 AM
Raj243
Fri Mar 08 2019, 02:08 AM
bharatsb
Thu Mar 07 2019, 04:34 PM
Yass7
Thu Mar 07 2019, 03:55 PM
mashabed
Mon Mar 04 2019, 11:08 PM
AccelMotion
Tue Feb 26 2019, 06:06 PM
turbovps
Mon Feb 25 2019, 06:26 AM
the_Doker
Thu Feb 14 2019, 02:21 PM

Online

Guests: 40, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38052
Newest member: tutu10
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Mar 22 2019, 09:10 PM
Using the external interrupt on pin B0 is the best...
Ansh12 Avatar
Posted By Ansh12
Fri Mar 22 2019, 03:45 PM
I have pic16f877a and MPLABX8 and I want to count ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Mar 13 2019, 02:32 AM
HiI looked at" Atmel AVR042: AVR Design Considera...
tutu10 Avatar
Posted By tutu10
Tue Mar 12 2019, 07:13 AM
Hi...My firmware upgradable code lock seems to be ...
Yass7 Avatar
Posted By Yass7
Sat Mar 09 2019, 12:52 AM
It's exactly that ! it's my teacher who asked me t...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Mar 09 2019, 12:27 AM
As I understand it, you want to use a P89LPC952 /...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Mar 09 2019, 12:21 AM
After you get the string what do you want to do wi...
bharatsb Avatar
Posted By bharatsb
Thu Mar 07 2019, 04:40 PM
help me to write code for 8051 to receive string ...
Yass7 Avatar
Posted By Yass7
Thu Mar 07 2019, 03:59 PM
Hello everyone,here I made a 3-axis CNC with 3 ste...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Jan 26 2019, 07:19 PM
Yes that helps a lot.At first sight I can't see th...