uart echo data
Sun Feb 25 2018, 10:06 pm
I want to see character back to terminal whatever I type on terminal. My code is not working
How to get echo character on terminal?
#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?
Mon Feb 26 2018, 06:58 am
You need to reset TIExperimenterUK
Can you give a little more information about this. How to do it ?
Wed Feb 28 2018, 04:58 am
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
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.
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
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
Wed Feb 28 2018, 07:18 am
In the rar file you just posted,
the routine "void putc (char c) "
does not contain the line "TI=0;"
Add it.
the routine "void putc (char c) "
does not contain the line "TI=0;"
Add it.
Wed Feb 28 2018, 09:02 am
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
Powered by e107 Forum System