Question: / * * CODE: Include any header files and macro definitions here. * / #include #include #include / * * EX: E 3 . 0
CODE: Include any header files and macro definitions here.
#include
#include
#include
EX: E
In this week's tutorial, we used some functions from the libraries
qutyio.h and stdio.h to output data via the serial interface. This can
be a useful tool for debugging your program.
To use the serial interface you first need to initialise the required
hardware on the ATtiny and, if you wish to use certain functions
from the stdio.h library, also redirect the standard input stdin and
standard output stdout streams to the serial interface.
This has been done for you in the qutyio.h library, through the function
serialinit
In this exercise, we will use the printf function to output formatted
strings to stdout. The syntax for printf is:
printf arguments;
where is a string that may contain format specifiers
that are replaced by the values of one or more arguments If no format
specifiers are present in this string, no additional arguments are
required in this function call. Some examples are provided below:
printfCAB prints the string "CAB to stdout.
printf prints a space to stdout.
printfX x prints the bit integer x to stdout,
formatted as two uppercase hexadecimal digits,
with padding.
printfu x prints the bit integer x to stdout, encoded
as an unsigned decimal number. Prefix u with
l to print an unsigned bit integer.
printf
prints a newline character to stdout.
Note that the format string can consist of multiple parts, for example:
uintt x xAB;
printfx: xX lu
x x;
prints:
STARTx: xAB
END
TASK: Write C code that performs the following steps:
Include qutyio.h and stdio.h and initialise the serial interface
using serialinit
Create a variable "state" to store your student number in decimal.
You should use the smallest fixedwidth integer type from the
stdint.h header file that can hold this value.
Iterate through all the numbers from to in sequence, and for
each number, perform the following steps:
a Take the bitwise XOR of the number with the variable "state",
storing the result back into "state".
b Rotate right the bits in "state" at least one time, and until the
LSB of "state" is a zero. If there are no cleared bits in "state",
do nothing.
c Print the least significant two bytes of "state" to the stdout
as four uppercase hexadecimal digits, followed by a space.
The prefix x is not required.
d Inspect bits of "state" where bit is the LSB and:
if the most significant nibble of this byte is equal to the
second last digit of your student number, print the word "foo"
to stdout.
if the least significant nibble of this byte is equal to the
final digit of your student number print the word "bar" to
stdout.
if both of the above conditions are satisfied, print "foobar".
e Print a newline character to stdout.
After step your program should have printed lines to stdout.
EXAMPLES:
Assuming the student number n if after step b "state" holds:
xEBC the program should print: C
xDFF the program should print: F foo
xF the program should print: F bar
xAFBF the program should print: F foobar
after step e
int mainvoid
CODE: Write your code for Ex E below this line.
CODE: Write your code for Ex E above this line.
END OF EXTENSION EXERCISES
DO NOT EDIT BELOW THIS LINE
while
; Loop indefinitely
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
