Week2.2_hacettepe_introduction
Week2.2_hacettepe_introduction
Introductory Overview
Week2
Hacettepe University
www.msp430.ubi.pt
Embedded System
1.8
1.6
1.4
1.2
x(t)
0.8
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8
t
Copyright 2009 Texas Instruments
>> Contents All Rights Reserved
5
Analogue and Digital Signals (3/5)
1.8
1.6
1.4
1.2
x(n)
0.8
0.6
0.4
0.2
0
0 10 20 30 40 50 60 70 80
n
Digital signal:
Rounds off all values to a certain precision or a certain
number of digits.
2500
2000
x[n]
1500
1000
500
0
0 10 20 30 40 50 60 70 80
n
Copyright 2009 Texas Instruments
>> Contents All Rights Reserved
8
How to Read Datasheets (1/6)
Electrical characteristics:
• Maximum and minimum operating voltages;
• Operating temperature range e.g. 0 to 70 degrees C;
• Output drive capacity for each output pin, as well as an
overall limit for the entire chip;
• Clock frequencies;
• Pin out electrical characteristics (capacitance, inductance,
resistance);
• Noise tolerance or the noise generated by the device
itself;
• Physical tolerances…
Copyright 2009 Texas Instruments
>> Contents All Rights Reserved
10
How to Read Datasheets (3/6)
C programming language:
C is an algorithmic language;
It is based on expressions;
Programming styles:
The style used in writing the code constrains the ease with
which the program can be read, interpreted or redeployed;
Example:
a = (4 + c) * 2; // NOT: a=(4+c)*2
Example:
/* The source code should be written in such a way
that enough information is provided for the reader
to fully understand the function of the code */
Copyright 2009 Texas Instruments
>> Contents All Rights Reserved
24
Programming Issues (8/14)
Data declaration:
Data declaration:
Declaration of variables:
Identifiers names:
Rules:
• Maximum number of characters is 31;
• Only use letters, numbers, or the character '_';
• The first character must be a letter or character '_';
• Case sensitive;
• The variable name cannot be the same as a reserved
keyword in the programming language or to a routine
name.
Examples:
unsigned int weight; // unsigned integer variable
int temperature; // signed integer variable
float speed, // real variable
Identifiers names:
const:
• Used to declare a constant (content is not changed in
the course of code implementation);
• Stored in program section memory.
extern:
• Used to make reference to variables declared
elsewhere, for example in another module.
register:
• Used to store a variable in a processor’s register;
• Promotes faster access to the contents of the variable;
• Only used locally and depends on the register’s
availability.
Identifiers names:
static:
• Function declared within a function or a program block;
• Resources occupied are released, and with them their
contents;
• Preserves the variable even after a function or block has
been executed.
volatile:
• Used if an event outside the program can change the
content of a variable, for example an ADC;
• A statement using this descriptor informs the compiler
that this variable should not be optimized.
Arithmetic operators:
Operator Name Syntax
Unary Plus +a
Addition (Sum) a+b
Prefix Increment ++a
Postfix Increment a++
Assignment by Addition a += b
Unary Minus (Negation) -a
Subtraction (Difference) a-b
Prefix Decrement --a
Postfix Decrement a--
Assignment by Subtraction a -= b
Multiplication (Product) a*b
Assignment by Multiplication a *= b
Division (Dividend) a/b
Assignment by Division a /= b
Modulus (Remainder) a%b
Assignment by Modulus a %= b
Copyright 2009 Texas Instruments
>> Contents All Rights Reserved
32
Operators and Expressions (2/9)
Relational operators:
Other operators:
Operator Name Syntax
Basic Assignment a=b
Function Call a()
Array Subscript a[b]
Indirection (Dereference) *a
Address-of (Reference) &a
Member by Pointer a->b
Member a.b
Member by Pointer Indirection a->*b
Member Indirection a.*b
Cast (type) a
Comma a,b
Ternary Conditional a?b:c
Scope Resolution a::b
Size-of sizeof a
Size-of sizeof (type)
Type Identification typeid type
Allocate Storage new type
Allocate Storage (Array) new type[n]
Deallocate Storage delete a
Deallocate Storage (Array) delete[] a
Copyright 2009 Texas Instruments
>> Contents All Rights Reserved
34
Operators and Expressions (4/9)
Compact forms:
Compact form Original form
x += y x=x+y
x -= y x=x-y
x *= y x=x*y
x /= y x=x/y
x %= y x=x%y
x &= y x=x&y
x |= y x=x|y
x ^= y x=x^y
x << y x = x << y
x >> y x = x >> y
Priority of operators:
Priority Operator Description
Highest () [] -> Grouping, scope, array/member access
! ~ + - & Size of type cast (most) unary operations, …
* / % Multiplication, division, modulo
+ - Addition, subtraction
<< >> Bitwise shift left and right
< <= > >= Comparisons: less-than, ...
== != Comparisons: equal and not equal
& Bitwise AND
^ Bitwise exclusive OR
| Bitwise inclusive (normal) OR
&& Logical AND
|| Logical OR
? Conditional expression (ternary operator)
= += -= *= /= %= &= |= ^= <<= >>= Assignment operators
Lowest . Concatenation ("comma“)
Copyright 2009 Texas Instruments
>> Contents All Rights Reserved
36
Operators and Expressions (6/9)
Bitwise operators:
Bit shifts:
Bits shifted out of either end are discarded (not in
assembler - there it would placed in Carry bit);
Example: x = y << 2;
Example: x = y >> 1;
• Shift y value to the right at attributes the value to x.
C coding tips:
Use local variable as much as possible (Local variables use
CPU registers whereas global variables use RAM);
Avoid modulo;
1. An analogue signal:
(a) Varies with discontinuities;
(b) Consists of a sequence of high-level and low-level signals;
(c) Varies smoothly and continuously;
(d) None of above.
2. Digital quantities:
(a) Can be maintained with high accuracy and at high speed
rates;
(b) Can not be computed;
(c) Either have slow response or very high accuracy;
(d) None of above.
Answers:
1. (c) Vary smoothly and continuously.
2. (a) Can be maintained at high accuracy at high speed
rates.
3. (b) 255.
4. (b) Two’s complement.
5. (d) 0x75Bh , 188310.
6. (d) The One’s complement represents both +0 and -0.
7. (b) A negative number.
8. (d) -3.
9. (b) 12.375.
10. (b) 1000 0000 + 1000 0000.
11. (a) DC.
12. (c) Adding two negative numbers results in a positive
result.
Copyright 2009 Texas Instruments
>> Contents All Rights Reserved
49