Documente Academic
Documente Profesional
Documente Cultură
Microcontroller (SEL4533)
Target Hardware
Text Editor,
GNU C compiler + Assembler
+ Linker + Locator
USB cable
Machine Code
+
Bootloader
Serial Monitor
(debugging)
Microcontroller (SEL4533)
GNU C
libraries
Machine Code
Microcontroller (SEL4533)
Open
Serial Monitor
Save
Area for Writing Program
(source code editor)
Microcontroller (SEL4533)
function name
function
start
function body
function end
Microcontroller (SEL4533)
Microcontroller (SEL4533)
Microcontroller (SEL4533)
Microcontroller (SEL4533)
Preprocessor instructions
use to include the contents of other files with
#include<..> or #include ".."
use to define constants & macros with #define ...
Microcontroller (SEL4533)
Size (bytes)
Ranges
char
-128 +127
int
-32768 +32767
short
-32768 +32767
long
-2147483648 +2147483647
Microcontroller (SEL4533)
Size (bytes)
Ranges
unsigned char
0 255
unsigned int
0 65535
unsigned long
0 4294967295
Size (bytes)
Ranges
float
double
Microcontroller (SEL4533)
Microcontroller (SEL4533)
Microcontroller (SEL4533)
extern
float
for
goto
if
int
long
register
return
short
signed
ADCreading , adcreading
sizeof
static
struct
switch
typedef
union
unsigned
void
volatile
while
c 2013 Dr. Rosbi Mamat p.14/46
Microcontroller (SEL4533)
Assignment operators
Microcontroller (SEL4533)
Logical operators
Microcontroller (SEL4533)
Other operators
Microcontroller (SEL4533)
FALSE
condition?
if (condition)
statements; TRUE
statements
FALSE
condition?
if (condition)
statementT;
else
statementF; statementT
statementF
Microcontroller (SEL4533)
TRUE
condition1?
statement1
FALSE
TRUE
condition2?
statement2
FALSE
TRUE
condition3?
statement3
FALSE
statementn
FALSE
condition?
TRUE
statements
do
{
statements
statement1;
statement2;
:
statementn;
} while (condition)
condition?
TRUE
FALSE
Microcontroller (SEL4533)
Update part
condition?
FALSE
TRUE
||
expr_init;
while (condition)
{
statements
expr_update;
}
statements
update
Microcontroller (SEL4533)
parameters
name
output/
return value
Microcontroller (SEL4533)
char c;
char *cptr;
int x;
int *iptr;
/* pointer to an integer */
cptr = &c;
*cptr = 0x45;
++cptr;
/* cptr = 0x1000
/* c = 0x45
/* cptr = 0x1001
*/
*/
*/
iptr = &x;
*iptr = c;
++iptr;
/* iptr = 0x1002
/* x = 0x0045
/* iptr = 0x1004
*/
*/
*/
/* pointer to a char
*/
Address
Contents
Variables
0x1000
0x90
0x1001
0x78
0x1002
0x56
0x1003
0x34
RAM (after)
0x1000
0x45
0x1001
0x78
0x1002
0x00
0x1003
0x45
Microcontroller (SEL4533)
ptr2ram = RAM_start;
for (i=0; i< 5; i++)
{
ramcopy[i] = *ptr2ram;
++ptr2ram;
}
Microcontroller (SEL4533)
*/
*/
Microcontroller (SEL4533)
Microcontroller (SEL4533)
Process
Subroutine
Add Sugar
Calc average
START
END
Decision
Continuation
Input/Output
A
A
yes
Need sugar?
no
Microcontroller (SEL4533)
Flow Charts
step_1
step_2
.
.
condition then
true_part
else
false_part
endif
step_n
if
Microcontroller (SEL4533)
no
yes
Condition?
false_part
true_part
while condition do
repeated_part
endwhile
Flow Charts
condition?
yes
repeated_part
no
repeat
repeated_part
until condition
Repeated_part
no
condition?
yes
Microcontroller (SEL4533)
boil water
put coffee in the cup
if want sugar then add sugar
if want cream then add cream
pour hot water into the cup
Microcontroller (SEL4533)
sugar?
add sugar
No
Yes
cream?
add cream
No
Microcontroller (SEL4533)
Microcontroller (SEL4533)
Microcontroller (SEL4533)
Yes
No
cond1?
No
Yes
cond2?
stmt
Microcontroller (SEL4533)
stmt1
Yes
No
cond1?
No
stmt2
Microcontroller (SEL4533)
Yes
cond2?
stmt3
Microcontroller (SEL4533)
Microcontroller (SEL4533)
void setup() {
Serial.begin(9600);
}
void loop() {
:
if (debugMode) {
Serial.println(In Debug"); // these messg will be
Serial.print(Result = "); // printed only
Serial.println(result);
// in debug mode
}
:
}
Microcontroller (SEL4533)