---+ <p align="center"><font face="Liberation Sans, sans-serif"><font size="6"> *Exercises 2: C programming* </font></font></p> ---++ Goal: We will program most of our sensor readout programs in the C programming language and programming a few simple C programs will help us with future exercises. As soon as programs become a bit more complex it becomes important to describe how the program must be built. This description is usually done in <i>Makefiles </i>in such a way that the simple command <i>make </i>will reconstruct the entire program compiling just the code that has been modified and linking the right files and libraries needed be the program. ---++ Exercise 1: Hello World! The first program to be written in C is traditionally the “Hello World!” program. We don’t want to change this tradition and you are therefore asked to write the program that prints “Hello World!”.<br /> First compile it with the gcc command, then write a Makefile to build the program using the make command. ---++ Exercise 2: A calculator We want to produce a calculator program capable of calculating the 4 basic calculations: * <p>addition</p> * <p>subtraction</p> * <p>multiplication</p> * <p>division</p> The program takes 3 arguments: the first operand followed by the operator followed by the second operand. The user should type calculate 3.4 + 5.8 and the program should print: 3.4 + 5.8 = 9.2 Addition, subtraction, multiplication and division should be performed by functions implemented in separate files, compiled separately and linked to the main calculator program. Write the 5 C files: * <p>calculator.c</p> * <p>add.c</p> * <p>subtr.c</p> * <p>mult.c</p> * <p>divide.c</p> and the Makefile to build the complete program. ---++ Exercise 3: Calculate a sine function One of the devices we will use during the sensor exercises is a digital to analogue converter (DAC), allowing us to generate an arbitrary wave form. This is a 12 bit device and we want to generate a sine wave for it. In order to do this, calculate the values to be sent to the DAC in such a way, that the min/max values of the sine wave are adapted to the 12 bits of the DAC. Generate 100 values for the sin(x) argument x running from 0 to 2<font face="Liberation Serif, serif">π and write them to a file called sine.dat.</font> <font face="Liberation Serif, serif">Read sine.dat with <nop>LibreOffice and generate a plot. </font> <font face="Liberation Serif, serif">Generate a plot with gnuplot.</font> -- %USERSIG{UliRaich - 2017-01-03}% ---++ Comments %COMMENT%
This topic: Embedded_Systems
>
WebHome
>
CourseExercises
>
ProgrammingExercise
Topic revision: r2 - 2017-01-15 - uli
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback