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
Sat Oct 12 2019, 10:23 PM
Log in.. then post your code in the 8051 forum
Sat Oct 12 2019, 10:18 AM
Bhadra Sajikumar
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 07:37 AM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Wed Sep 18 2019, 08:48 PM
Caryn Kover
Thank you for your time,
ExperimenterUK
Mon Aug 05 2019, 07:09 PM
@Ismail ..post in forum, give details
Mon Aug 05 2019, 04:33 PM
Ismail balghmi
Hello. Please I won't download
ExperimenterUK
Wed Jul 24 2019, 12:47 AM
@BUSTER123 Please post in the forum
Tue Jul 23 2019, 06:13 PM
BUSTER123
hello! newbie here. i am kind of a guy who hates using ready - made existing libraries, so this helped a lot as i was trying to control and write to a character lcd display. however, i can't figure out how to set the cursor position. for example, i want to set it to the 5th column in the first row, so position 5. so according to the table, i am sending 10000101 on the 8 data lines of the lcd (register select pulled low). the cursor does not move there however. and i cant move the cursor left or right too. is it something wrong that i am doing? thank you.
ExperimenterUK
Thu Jul 11 2019, 07:55 PM
@ramos https://www.theengineeringprojects.com/2017/09/l298-motor-driver-library-proteus.html
ExperimenterUK
Thu Jul 11 2019, 07:44 PM
@praveen123. Can you give a link to the project ?

Downloads

Comments

ANKITPATEL
Mon Nov 18 2019, 11:00 AM
Casmir
Wed Nov 13 2019, 06:25 AM
DeepakBGattani
Mon Nov 11 2019, 01:31 PM
Jeanbusatta
Sun Nov 10 2019, 04:42 AM
mdayaz
Sat Nov 09 2019, 03:41 PM
baoyen123
Fri Nov 08 2019, 10:06 AM
xiwang
Fri Nov 08 2019, 07:28 AM
ilylily07
Tue Oct 15 2019, 04:32 PM

Online

Guests: 41, Members: 0 ...

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

Members: 38104
Newest member: ANKITPATEL
Forum Activity
ilylily07 Avatar
Posted By ilylily07
Mon Nov 18 2019, 09:54 AM
0v7670 camera interfacing with stc 8051.using asse...
Jeanbusatta Avatar
Posted By Jeanbusatta
Sun Nov 10 2019, 04:43 AM
ty, really needed it
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Oct 22 2019, 05:18 AM
wimac Avatar
Posted By wimac
Mon Oct 21 2019, 09:18 AM
I’ve been following this thread and looking at the...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:09 PM
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:02 PM
sir, when i on display ,sometime 3rd display is no...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 02:53 PM
sir, when i on display ,sometime 3rd display is no...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Oct 20 2019, 12:21 AM
Your code seems okay on my simulationTry my code o...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sat Oct 19 2019, 07:13 PM
please find video attachment. 3rd & 4th displa...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sat Oct 19 2019, 07:05 PM
sir, 3rd and 4th dot matrix display flickering, ...