You are on page 1of 45

MSP430 Teaching Materials

UBI

1

Texas Instruments Incorporated
University of Beira Interior (PT)
Pedro Dinis Gaspar, Antnio Esprito Santo, Bruno Ribeiro, Humberto Santos
University of Beira Interior, Electromechanical Engineering Department
www.msp430.ubi.pt
>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt


UBI









>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

(1/5)
UBI

,
;
: ,

:
;
;
.


.
>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

(2/5)
UBI

: :

2
1.8
1.6
1.4

x (t)

1.2
1

0.8
0.6
0.4
0.2
0

>> Contents

0.1

0.2

0.3

0.4
t

0.5

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

0.6

0.7

0.8

(3/5)
UBI

: :

() , , T:
2
1.8
1.6
1.4

x (n )

1.2
1

0.8
0.6
0.4
0.2
0

>> Contents

10

20

30

40
n

50

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

60

70

80

(4/5)
UBI

:

.

:
.

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

(5/5)
UBI

: :
, 12-bit
(Analogue-to-Digital Converter -ADC)
(full-scale) 2.5 V.
3500
3000
2500

x [n ]

2000
1500
1000
500
0

>> Contents

10

20

30

40

50

n
Copyright 2009 Texas
Instruments
All Rights Reserved
www.msp430.ubi.pt

60

70

80

(1/6)
UBI



.


(pins),
.

, :

;
;
;
,

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

(2/6)
UBI

:

.
:

.. 0 70 C
,
.


(, , )

.

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

(3/6)
UBI

MSP430:

/
;

, 2 = P6.3/A3;
6 / bit 3;
3 .

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

10

(4/6)
UBI

MSP430 :

.
:
MSP430F44x :

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

11

(5/6)
UBI

MSP430:
:
MSP430F44x: SELMx;

: (4 1 ):
SELMx = 00:
1
SELMx = 01:
2 ..
SELMx 2-bit: SELM1 (MSB), SELM0
(LSB).
,
:
SELMx FLL_CTL1 .
>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

12

Datasheets (6/6)
UBI

(Users Guide) MSP430 :


SELMx 3 4 bit FLL_CTL1
.

Bit
6

4-3

Description
SMCLKOFF

XT2OFF

SELMx

Disable the submain clock signal (SMCLK):


SMCLKOFF = 0

SMCLKOFF = 1

SMCLK active
SMCLK inactive

Disable the second crystal oscillator (XT2):


XT2OFF = 0

XT2OFF = 1

XT2 active
XT2 inactive

Select the master clock (MCLK) source:


SELM1 SELM0 = 0 0

SELM1 SELM0 = 0 1

SELM1 SELM0 = 1 0

SELM1 SELM0 = 1 1

DCO
DCO
XT2
LFXT1

SELS

Select the submain clock (SMCLK) source:


SELS = 0

DCO
SELS = 1

XT2

1-0

FLL_DIVx

Select the auxiliary clock (ACLK) signal divider:


FLL_DIV_0 = 0 0

Divider
FLL_DIV_1 = 0 1

Divider
FLL_DIV_2 = 1 0

Divider
FLL_DIV_3 = 1 1

Divider

>> Contents

factor:
factor:
factor:
factor:

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

/1
/2
/4
/8

13

(1/14)
UBI

C:
C
C


,
,
CPU

.
>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

14

(2/14)
UBI

:

,

,
, ,


. , ,


>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

15

(3/14)
UBI

: :

: :
.. Line AverageVelocity.

:
:
line, averageVelocity.

(
, )

(
)

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

16

(4/14)
UBI

: :


:
i, j, k.

: :
RED, GREEN, BLUE, WHITE.

:
:
calculateVelocity( ) or activateOutput( ).

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

17

(5/14)
UBI

:

:
:
P3OUT |= 0x04;
while(1){
if(!CMBufIsEmpty()){//polling the command receiver buffer
cmd = CMGetCommand();
//get the new command
ACStop();
//stops the action being executed
switch (cmd){
case DEMO1:
//demo1 procedure
...

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

18

(6/14)
UBI


, , .

Example:
a = (4 + c) * 2;

>> Contents

// : a=(4+c)*2

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

19

(7/14)
UBI

: ( // )

: ( /* ) ( */ )

:
/* 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 */

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

20

(8/14)
UBI

(integer)
(real)

null (void)

Integer
(int), (signed) (unsigned)

( twos
complement) ( unsigned-
)

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

21

(9/14)
UBI


(float),
.


:
short:

long:

signed:
;
unsigned:
.

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

22

(10/14)
UBI

C (
C : CCE IAR
MSP430):

[bits]

signed char

char, unsigned char

ASCII

-128

127

ASCII

255

short, signed short

16

2s complement

-32768

32767

unsigned short

16

Binary

65535

int, signed int

16

2s complement

-32768

32767

unsigned int

16

Binary

65535

long, signed long

32

2s complement

-2147483648

2147483647

unsigned long

32

Binary

4294967295

float

32

IEEE 32-bit

1.175495e-38

3.40282346e+38

double

32

IEEE 32-bit

1.175495e-38

3.40282346e+38

long double

32

IEEE 32-bit

1.175495e-38

3.40282346e+38

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

23

(11/14)
UBI

(Global) :

(Local) :


,

.

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

24

(12/14)
UBI

:
31
, , '_'

'_'
-case sensitive


.

:
unsigned int weight;
int temperature;
float speed,

>> Contents

// unsigned integer variable


// signed integer variable
// real variable

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

25

(13/14)
UBI

const:
(
)
.

extern:
,
.

register:


>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

26

(14/14)
UBI

static:

;
,
;

.

volatile:

,
ADC;

.

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

27

(1/9)
UBI

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

28

(2/9)
UBI

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

29

(3/9)
UBI

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

30

(4/9)
UBI

>> Contents

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

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

31

(5/9)
UBI

() [] ->

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

?
= += -= *= /= %= &= |= ^= <<=
>>=

>> Contents

Conditional expression (ternary operator)


Assignment operators
Concatenation ("comma)

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

32

(6/9)
UBI

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

33

(7/9)
UBI

:

( assembler
);

>> Contents

( -carry):
,
;

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

34

(8/9)
UBI

: ( << )

: x = y << 2

: x = y << 1

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

35

(9/9)
UBI

: ( carry)

,
;

: ( >> )

: x = y >> 1;
y x.

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

36


(1/2)

UBI

C:

(
CPU
RAM)

>> Contents

unsigned

static const

, ,

for
.
Copyright 2009 Texas Instruments
All Rights Reserved
www.msp430.ubi.pt

37


(2/2)

UBI

interrupts ;

.

.

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

38

(1/7)
UBI

1. :
(a) ;
(b) - ;
(c) ;
(d) .

2. :
(a)
;
(b)
(c) ;
(d) .
>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

39

(2/7)
UBI

3.
(unsigned)
8- :
(a) 256;
(b) 255;
(c) 16;
(d) 128.
4.
:
(a) Unsigned binary;
(b) Twos complement;
(c) ;
(d) .
>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

40

(3/7)
UBI

5. :
0111 0101 1011 :
(a) 0x75B , -188310;
(b) 0x8A4 , -188310;
(c) 0x8A4 , 188310;
(d) 0x75B , 188310.
6. Ones
Twos complement :
(a) Ones complement +0 -0;
(b) MSB ;
(c) LSB ;
(d) Twos complement
.
>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

41

(4/7)
UBI

7. Twos complement , 1 MSB


:
(a) ;
(b) ;
(c) ;
(d) Carry.

8. 11012 Twos complement :


(a) -5;
(b) -13;
(c) 3;
(d) -3.

>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

42

(5/7)
UBI

9. 1100.0112 unsigned binary


:
(a) -4.375;
(b) 12.375;
(c) 4.375;
(d) -12.375.
10.
-
:
(a) 0111 11112 + 0000 00102;
(b) 1000 00002 + 1000 00002;
(c) 0111 11112 + 1000 00002;
(d) .
>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

43

(6/7)
UBI

11.
36 :
(a) 0xDC;
(b) 0x24;
(c) 0xDB;
(d) 0x23.
12. -signed
:
(a) LSB;
(b) MSB;
(c)

(d)
.
>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

44

(7/7)
UBI

:
1. (c) .
2. (a)

3. (b) 255.
4. (b) Twos complement.
5. (d) 0x75Bh , 188310.
6. (d) Ones complement +0
-0.
7. (b) .
8. (d) -3.
9. (b) 12.375.
10. (b) 1000 0000 + 1000 0000.
11. (a) 0xDC.
12. (c)
.
>> Contents

Copyright 2009 Texas Instruments


All Rights Reserved
www.msp430.ubi.pt

45

You might also like