Académique Documents
Professionnel Documents
Culture Documents
Computer
What are the main parts of the computer?
1) Central Processing Unit (CPU)
The CPU will does the computations
Arithmetic (addition, subtraction, multiplication, division)
Decision making (if- else)
2) Memory
The memory stores the program and the data (eg: variables and arrays)
The memory is supplemented by the hard disk (in small computers, theres no hard
disk, only the memory)
3/2/2015
Computer
If you open the computer box, you can identify these three parts
In a desktop computer, these parts are distinct components
This means you can replace the CPU only, or replace the memory only, or replace
the motherboard only to get better I/O performance
The motherboard is the large board of the desktop computer that connects
everything together
Microcontroller
What is a microcontroller?
The microcontroller is a small computer chip that contains all
of these in one package:
A CPU (Central Processing Unit)
Memory
I/O interfaces
3/2/2015
Microcontroller
Microcontrollers are used in a multitude of products that have computing
power
A simple calculator uses a basic microcontroller
Such a microcontroller could cost a few cents
Microcontroller
What are the available microcontrollers?
They are made by these companies:
Texas Instruments (TI)
Atmel
Microchip (they produce the PIC microcontrollers)
Renesas (owned by Hitachi, NEC, Mitsubishi)
Freescale (spun off Motorola)
STMicroelectronics
NXP Semiconductors
Silicon Labs
Zilog
3/2/2015
3/2/2015
10
3/2/2015
11
12
3/2/2015
13
14
3/2/2015
15
16
3/2/2015
P1DIR |= 0x41;
P1DIR &= 0xBE;
P1OUT ^= 0x01;
17
Decimal Numbers
Lets look at a number below thats in base 10
Each digit position has a weight
3,427
103
102
101
100
18
3/2/2015
Binary Numbers
Lets look at a number below thats in binary
In binary, the bits can be only 0 or 1
Each bit position has a weight
1101
23
22
21
20
19
Binary Numbers
In general, these are the weights of a binary number:
1011 1101
128
64
32
16
20
10
3/2/2015
Hexadecimal Numbers
Hexadecimal numbers are in base 16
11
12
13
14
15
Hexadecimal Numbers
These are the weights of each digit position
C2A7
163
162
161
160
22
11
3/2/2015
Converting to Binary
To convert a decimal number to binary, keep dividing it by 2 until the
quotient becomes 0
The binary number will be all the remainders taken from the last to the
first
Example: Convert 26 to binary
26 / 2 = 13
remainder: 0
13 / 2 = 6
remainder: 1
6/2=3
remainder: 0
3/2=1
remainder: 1
1/2=0
remainder: 1
Taking the remainders from last to first, the binary number is: 11010
Therefore, we can write: 2610 = 110102
Base 10
Base 2
23
Converting to Binary
Another way to convert a decimal number to binary is to write down a
few binary positions and their weights
32
16
32
16
1
24
12
3/2/2015
Converting to Binary
0
32
16
32
16
1
2
0
1
25
Converting to Hexadecimal
To convert a decimal number to hexadecimal, we keep dividing it by 16
until the quotient becomes 0
The hexadecimal number will be all the remainders taken from the last
to the first (the remainder range from 0 to 15, represented by 0 to F)
Example: Convert 49,831 to hexadecimal
49,831 / 16 = 3114
remainder: 7
3114 / 16 = 194
remainder: 10
194 / 16 = 12
remainder: 2
12 / 16 = 0
remainder: 12
A
C
Taking the remainders from last to first, the hex number is: C2A7
Therefore, we can write: 49,83110 = C2A716 = C2A7 (hex)
26
13
3/2/2015
27
26D9
We should start grouping the bits in four from the right side; this way, the
leftmost two bits are taken together
28
14
3/2/2015
AND Function
Lets start with the AND function
This symbol is called the AND gate
It takes two inputs (A, B) and gives one output (Y)
A, B and Y are binary; it means each of them can be 0 or 1
B
0
1
0
1
AND
0
0
0
1
From the truth table, we can say that the output of AND is 1 only when
its two inputs are 1
29
AND Function
This is an example of the AND operation
Here, the numbers are binary:
AND
0011 1010
0101 1110
0001 1010
The result:
0001 1010
3A (in hex)
5E (in hex)
1A (in hex)
15
3/2/2015
AND Function
How can we do this operation in a C code?
AND
0011 1010
0101 1110
0001 1010
(3A)
(5E)
(1A)
AND Function
Lets see the output of this code:
int num1, num2, result;
num1 = 0x3A;
num2 = 0x5E;
result = num1 & num2;
printf("This is the operation in hexadecimal...\n");
printf("%X & %X = %X\n\n", num1, num2, result);
printf("This is the operation in decimal...\n");
printf("%d & %d = %d\n", num1, num2, result);
This is the operation in hexadecimal...
3A & 5E = 1A
This is the operation in decimal...
58 & 94 = 26
32
16
3/2/2015
AND Function
Lets look at the truth table of the AND gate one more time
What does the AND gate do?
A
0
If we AND something with 1, we get the same thing
0
If we AND something with 0, we get 0
1
1
B
0
1
0
1
AND
0
0
0
1
Lets consider the 8-bit word abcd efgh (each letter is 1 bit)
How can we make the leftmost and rightmost bits 0 and keep the other
bits unchanged? We can use the AND operation
AND
abcd efgh
0111 1110
0bcd efg0
This number is
called the mask
Therefore, the AND operation can be used to zero some bits in a word
33
OR Function
Another function is the OR function thats implemented by the OR gate
This is the symbol of the OR gate
It takes two inputs (A, B) and gives one output (Y)
This is the truth table of the OR gate
The truth table defines the output for all the cases of the inputs
A
0
0
1
1
B
0
1
0
1
OR
0
1
1
1
From the truth table, we can say that the output of OR is 1 if any of
the inputs is 1
34
17
3/2/2015
OR Function
This is an example of the OR operation
Here, the numbers are binary:
OR
0011 1010
0101 1110
0111 1110
(3A)
(5E)
(7E)
35
OR Function
How can we do this operation in a C code?
OR
0011 1010
0101 1110
0111 1110
(3A)
(5E)
(7E)
36
18
3/2/2015
OR Function
Lets look at the truth table of the OR gate one more time
What does the OR gate do?
If we OR something with 0, we get the same thing
If we OR something with 1, we get 1
A
0
0
1
1
B
0
1
0
1
OR
0
1
1
1
Lets consider the 8-bit word abcd efgh (each letter is 1 bit)
How can we make the leftmost 4 bits equal to 1 and leave the remaining
bits unchanged? We can use the OR operation
abcd efgh
1111 0000
1111 efgh
OR
This number is
called the mask
XOR Function
Lets look now at the exclusive OR operation, called XOR in short
This is the symbol of the XOR gate
It takes two inputs (A, B) and gives one output (Y)
This is the truth table of the XOR gate
The truth table defines the output for all the cases of the inputs
A
0
0
1
1
B
0
1
0
1
XOR
0
1
1
0
19
3/2/2015
XOR Function
This is an example of the XOR operation
Here, the numbers are binary:
XOR
0011 1010
0101 1110
0110 0100
(3A)
(5E)
(64)
39
XOR Function
How can we do this operation in a C code?
OR
0011 1010
0101 1110
0110 0100
(3A)
(5E)
(64)
40
20
3/2/2015
XOR Function
Lets look at the truth table of the XOR gate one more time
If we XOR something with 0, we get the same thing
If we XOR something with 1, its inverted
A
0
0
1
1
B
0
1
0
1
XOR
0
1
1
0
XOR
0110 0101
0000 1111
0110 1010
This number is
called the mask
Therefore, the XOR operation can be used to invert some bits in a word
41
42
21
3/2/2015
43
44
22
3/2/2015
P1DIR |= 0x41; // set the direction register for LED1 and LED2
46
23
3/2/2015
47
P1DIR = 0xFF;
Otherwise, we can write 00000000 to P1DIR to set all the pins as input
This can be done with:
P1DIR = 0x00;
P1DIR |= 0x41; // set the direction register for LED1 and LED2
48
24
3/2/2015
25
3/2/2015
51
52
26
3/2/2015
53
54
27
3/2/2015
for (;;) {
//empty for loop is an infinite loop
P1OUT ^= 0x01; // invert the state of LED1
for(i=0; i< 20000; i++) // create a delay between toggles
;
// empty statement, do nothing
}
55
56
28
3/2/2015
Resources
New to MSP430 webpage on TIs website
http://www.ti.com/lsds/ti/microcontroller/16-bit_msp430/newtomsp430.page
MSP430 Launchpad
http://processors.wiki.ti.com/index.php/MSP430_LaunchPad_%28MSPEXP430G2%29?DCMP=launchpad&HQS=Other+OT+launchpadwiki
Resources
Additional boards that can be connected to the MSP430 board that were
using
http://processors.wiki.ti.com/index.php/BoosterPacks
58
29