Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help with the structure of my code, its not outputting correctly and i am unsure where exactly its having issues? / * *
I need help with the structure of my code, its not outputting correctly and i am unsure where exactly its having issues?
EX: E
TASK:
Your task is to write code which handles a sequence of input characters
from the UART interface, and responds with the output specified below.
On receipt of the character sequence:
"foo" your program should print
"bar" your program should print
"foobar" your program should not print either or as specified
above, but should instead print a linefeed
character.
NOTE:
It is strongly recommended that you design a state machine to complete
this task.
Your solution should use a baud rate of and N frame format. Your
solution MUST NOT use qutyio.o or qutyserial.o
EXAMPLES:
INPUT: foo.bar.foo.barfoobarfood
OUTPUT:
START
END
INPUT: barsfoosbarforbarfoobarrforfoobarfoobarfood
OUTPUT:
START
END
#include
void uartinitvoid
PORTB.DIRSET PINbm; Enable PB as output USART TXD
USARTBAUD ; baud @ MHz
USARTCTRLB USARTRXENbm USARTTXENbm; Enable TxRx
void uartputcchar data
while USARTSTATUS & USARTDREIFbm; Wait for the Data Register to be empty
USARTTXDATAL data; Transmit the data
uintt uartgetcvoid
while USARTSTATUS & USARTRXCIFbm; Wait for received data
return USARTRXDATAL;
typedef enum
START,
F FO FOO FO FOA FOR
B BA BAR
state;
int mainvoid
uartinit;
state currentstate START;
int foobartriggered ;
while
char receivedchar uartgetc; Get input character from UART
switch currentstate
case START:
if receivedchar f currentstate F;
else if receivedchar b currentstate B;
else currentstate START;
foobartriggered ;
break;
case F:
if receivedchar o currentstate FO;
else currentstate START;
break;
case FO:
if receivedchar o currentstate FOO;
else currentstate START;
break;
case FOO:
if receivedchar b currentstate FO;
else
uartputc;
currentstate receivedchar f F : START;
break;
case FO:
if receivedchar a currentstate FOA;
else
uartputc;
currentstate receivedchar f F : START;
break;
case FOA:
if receivedchar r currentstate FOR;
else
uartputc;
currentstate receivedchar f F : START;
break;
case FOR:
uartputc
;
foobartriggered ;
currentstate START;
break;
case B:
if receivedchar a currentstate BA;
else
currentstate receivedchar f F : START;
break;
case BA:
if receivedchar r
uartputc;
if foobartriggered currentstate START;
else
currentstate receivedchar f F : START;
break;
default:
currentstate START;
break;
Ex E
FAIL.
Input: foo.bar.foobar.ffoo.bbar.ffoobar.ffoobbar.ffoob.ffooba.obarfoobafooba.abarbarbafoobfoobabarfoofobarfoobaabarofobafoobarafoobarbarfofofoobfofbarbarafoobfoobfoobafofoobfobabbafoobafoofofofoobba.
Expected:
START
END
Observed:
START
END
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started