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 PICF 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 INTIO Oscillator Selection bits Internal oscillator block, port function on RA and RA
#pragma config WDTEN OFF Watchdog Timer Enable bit WDT is controlled by SWDTEN bit of the WDTCON register
#pragma config LVP OFF SingleSupply ICSP Enable bit SingleSupply ICSP disabled
#define XTALFREQ
Function Prototypes
void Initvoid;
void UARTTxchar;
void UARTRxchar;
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
UARTTxsentence; Call the UART Transmit Function
UARTRxresponse; 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 UARTRxchar str
unsigned char ch;
unsigned char character;
static int j;
j ;
CREN ; RCSTA, continuous receive enabled
whileRCIF; keep looping while the receive buffer is empty
chRCREG; once a character is received store it in ch
CREN ; RCSTA, continuous receive disabled
TXEN ; Enable transmitter to echo letter back
newline; Send a new line carriage return to hyperterm
j ; finished
whilestrj loop while the array element has data
whileTXIF; continue to loop while the TXREG still has data
TXREG strj; 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
whileTXIF; 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 ; Disable transmitter
void UARTTxchar str
unsigned int i;
TXEN ; Set to to enable the USART Transmitter
newline; Send a new line carriage return to hyperterm
newline; Send a new line carriage return to hyperterm
i; finished
whilestri loop while the array element has data
whileTXIF; continue to loop while the TXREG still has data
TXREG stri; 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 ; 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
whileTXIF; continue to loop while the TXREG still has data
TXREG
; once TCREG has been cleared load it with new data
delayms;
whileTXIF; continue to loop while the TXREG still has data
TXREG r; once TCREG has been cleared load it with carriage return
delayms;
Initializes the USART peripheral to be ready to transmit and receive bit data data
to and from the hyperterminal. The PIC USART USART was set up for a baud rate,
bit data, asynchronous mode of opertation using interrupts.
void Initvoid
OSCTUNE ; Used to tune the frequency of the internal oscillator.
MSB are unused. Sets the OSCTUNE as unimplemented
OSCCONxE; Set the default frequency to MHz
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
