Lab2 C Programming
Lab2 C Programming
PROGRAMMING
EMBEDDED AND REAL-TIME SYSTEMS
(INT3108, LẬP TRÌNH NHÚNG VÀ THỜI GIAN THỰC)
CPU: Week
ARM Cortex-M 4
Curriculum Memory
and Interfaces
Week
5-6
Real-time Week
Operating systems 10-12
Project Week
Laboratory for Smart Integrated Systems 15
Objectives
3
Outline
• Hello World.
• Development Tool chain Overview
(KEIL).
4
First Program: Hello World
- In Pack Installer, select a device on the Devices tab. Click on the
Examples tab and select “Hello World (FRDM-KL46Z)”
-Press Copy to install the selected example project on your machine.
µVision opens up and you can start working with the project.
5
First Program: Hello World
- On PC, Open “Device manager” find COM NUMBER of “OpenSDA – CDC
Serial port
6
First Program: Hello World
- In Putty Configuration, select Session on the Category tab. Check on the
Serial and enter COM NUMBER on Serial line and 115200 on Speed
-Press Open
7
Program #2: Static variables
int a(void)
{
static int i = 10;
i++;
return(i);
}
int main()
{
int p, n;
for (n=1; n < 10; n++) {
p = a();
PRINTF("Invocation %i, return value %i\n", n, p );
}
} 8
Program #3: Array
9
Program #4: Struct
int main() {
typedef struct {
int hours;
int mins;
int secs;
} time;
time clock;
time *ptime; /* pointer to time struct */
10
Program #5: Add Two integers
11
Program #6: pass-by-value vs pass-by-reference
swap(&x,&y);
temp = *a; printf("x = %i, y = %i\n", x, y);
*a = *b; }
*b = temp;
}
12
Summary
13