Question: how do i rework this code so it will allow you to type in a string of charaters sentance / / / / / /

how do i rework this code so it will allow you to type in a string of charaters sentance //////////////////////////////////////////////////////////////////////////////////
// This project demostrates the asynchronous serial communication capabilities
// of the PIC16F887. The TX pin is connected to a computer's COM port.
// Hyperterminal may be used to communicate on the PC. The PIC will send a
// greeting out through the serial port.
///////////////////////////////////////////////////////////////////////////////////
#include
#include
#pragma config FOSC = INTIO67// Oscillator Selection bits (Internal oscillator block, port function on RA6 and RA7)
#pragma config WDTEN = OFF // Watchdog Timer Enable bit (WDT is controlled by SWDTEN bit of the WDTCON register)
#pragma config LVP = OFF // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#define _XTAL_FREQ 16000000
// Function Prototypes
void Init(void);
void UARTTx(char[]);
void UARTRx(char[]);
void newline();
void main()
{
char sentence[]="This is a sample of how to perform serial communication.\r
"; // String to send to the hyperterminal
unsigned char response[]= "The letter you entered was
\r "; // String to sent to hyperterminal upon receiving a character
Init(); // Initialize PIC
while(1)
{
UARTTx(sentence); // Call the UART Transmit Function
UARTRx(response); // Call the UART Receive Function
}
}
//*****************************************************************************************
// This function will monitor the UART Receive line until a character is received. Once the
// character is received it will disable the receiver and enable the transmitter and send
// the character back to the computer hyperterminal to display that letter on the monitor
//*****************************************************************************************
void UARTRx(char str[])
{
unsigned char ch;
unsigned char character;
static int j;
j =0;
CREN =1; // RCSTA, continuous receive enabled
while(!RCIF); // keep looping while the receive buffer is empty
ch=RCREG; // once a character is received store it in ch
CREN =0; // RCSTA, continuous receive disabled
TXEN =1; // Enable transmitter to echo letter back
newline(); // Send a new line carriage return to hyperterm
j =0; // finished
while(str[j])// loop while the array element has data
{
while(!TXIF); // continue to loop while the TXREG still has data
TXREG = str[j]; // once TCREG has been cleared load it with new data
j++; // increment i so the next character in the array will be sent on the next iteration
}
newline(); // Send a new line carriage return to hyperterm
while(!TXIF); // continue to loop while the TXREG still has data
TXREG = ch; // once TCREG has been cleared load it with new data
newline(); // Send a new line carriage return to hyperterm
TXEN =0; // Disable transmitter
}
void UARTTx(char str[])
{
unsigned int i;
TXEN =1; // Set to 1 to enable the USART Transmitter
newline(); // Send a new line carriage return to hyperterm
// newline(); // Send a new line carriage return to hyperterm
i=0; // finished
while(str[i])// loop while the array element has data
{
while(!TXIF); // continue to loop while the TXREG still has data
TXREG = str[i]; // once TCREG has been cleared load it with new data
i++; // increment i so the next character in the array will be sent on the next iteration
}
newline(); // Send a new line carriage return to hyperterm
// newline(); // Send a new line carriage return to hyperterm
TXEN =0; //Disable the Transmitter
}
//*****************************************************************************************
// Function sends a newline carriage return to hyperterm to make the the hyperterm
// cursor move to the beginning of the next line.
//*****************************************************************************************
void newline()
{
while(!TXIF); // continue to loop while the TXREG still has data
TXREG ='
'; // once TCREG has been cleared load it with new data
__delay_ms(10);
while(!TXIF); // continue to loop while the TXREG still has data
TXREG ='\r'; // once TCREG has been cleared load it with carriage return
__delay_ms(10);
}
//*****************************************************************************************
// Initializes the USART peripheral to be ready to transmit and receive 8 bit data data
// to and from the hyperterminal. The PIC USART USART was set up for a 9600 baud rate,
//8-bit data, asynchronous mode of opertation using interrupts.
//*****************************************************************************************
void Init(void)
{
OSCTUNE =0; // Used to tune the frequency of the internal oscillator.
//3 MSB are unused. Sets the OSCTUNE as unimplemented
OSCCON=0x7E; // Set the default frequency to 8MHz,
//

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!