Imperative Programming A 5 ECTS course for for first year students http://www.control.aau.dk/~jdn/edu/courses/e10/imperativ Based on “C”
Goal Learn how to program with an imperativ language. “C” Do it in real life on your PC Install of SW like compilers Get things up and running Use it in P1 project if possible Get an programming skill platform for the next languages to come to you (java, C++,C#,Python,Php,matlab,...)
Goal II
Rough layout of course Basic C and programming Embedded programming on Arduino Ask your supervisor for an Arduino pr group And maybe buy one you self (200 DKK) http://arduino.cc
Basic C part On a tradional basis – editor,compiler, run an executable No fansy GUI etc GUI based: Eclipse,... The war of operating systems Mac, Windows XP/V/7, Linux, embedded We try to cover it all Please help your neighbour
Embedded part Arduino based AVR micro controller 1/2/4/8 kByte of RAM Up to 128 kByte of flash for program code IO Up to 14 channels 10 bit analog input Up to 7 or so analog output (by PWM) Digital in and out – a lot Serial (rs232),i2c,.. Use nearly no current (use a battery) Cheap
Arduino's
It is your choice To be here We are here to help (you)
TODAY Chapter 1 Chapter 2 Exercises
Den gang far var ung ... Var der rigtige kompjutere til
Characteristics Difficult to program Difficult to run programs on High salaries Died after the PC arrived ? 64 kByte Ram 4.77 Mhz processor (today 1000 times more) 1 or 2 640 kByte floppy drive
The return of the main frame ?!
Very simple model GUI IO NET IO OS HW
From code to executable Editor – write program in language (C,...) Compile it to binary for a specific architecture (PC,ARM,...) Link it with libraries for specific platform windows,linux,arduino,... Different platforms different facilities/possibilities Save executable In filesystem (on “disk”) In flash memory Loadable via net ...
Let's do it /* A simple Program */ #include <stdio.h> int main(void) { printf(“Hello World\n”); }
SW Development method Specify problem requirements Analyze the problem Design the algorithm to solve the problem Implement the algorithm Test and verify the completed program Maintain ... and update the program Very simplified ...
Fig 2.1 ... on the comming slides C is en general a very small language No fancy graphics, GUI, network,... All extra is by purpose on a specific platform And is supplied in libraries/part of Operating Sys
Only simple types: Integers : 16/32/64 bit wide dep of architecture Floating point: IEEE given character/byte 8 bit void (nothing) ...
/* include statements – for extending “language”*/ #include <stdio.h> /* standard input/output stuff */ /* C can only + - * / /* the rest comes as library / “extensions” */ Sin, cos, atan, printf, file I/O, GUI (!),...
double float_1; int int_1, int_2; /* upper case is not equal lower case */ int main(void) { int_1 = 3; int_2 = int_1 *3 – 44; float_1 = int_1; } /* p.. of cake */
Beware about conversions /* declaration part */ int i_1, i_2, i_3; double float_1; i_1 = 3; i_2 = 4; i_3 = i_1 / i_2; float_1 = i_1 / i_2; /* ??? */
int int1, int2; ... int2 = 12785; Int1 = int2 ; /* an assigment is a copy !!! */
stdio.h Need something one the computer screen ... Output like print “hello ...” Input like “read_an_integer_from_keyboard
stdio.h - output printf (“hello”); printf (“hello\n new line”); printf(“hello – I have %i legs “ , 2 ); printf(“ hello – I have %&i legs” , int_1) ; %i : integer %f : floating point %c : character + variants : %3i Integer written out as xxx
printf (“ %i %f %c”, 3, 3.2 , 3 ); int i,j,k; i = 3 ; j = 4; k = 4444; printf(“%i%i%i”, i,j,k); /* writes out 344444 */ printf(“%i %i %i”, i,j,k); /* writes out 3 4 4444 */
stdio.h - input read from keyboard No error handling today I ask for an integer you type dumpkopf ...
stdio.h - scanf int a_number; scanf ( “%i “, & a_number); /* read & as location or address */ /* i for int, f for float c for character – as printf*/
int i1,i2,i3; scanf(“%i %i %i”, & i1, &i2, &i3 ) ;
Operator Hierarchy See inside first page in book and page 96.. Level x + - Level x-1 * / ... 2 + 5 * 4 + 5 = ??? 27 I guess
(())(()) Use ( ) to clarify: ((2*3) +5) / (3+7) You can never use to many – only to few ...