Professional Documents
Culture Documents
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Basic Concept
What is Microcontroller?
8-bit,16-bit,32-bit
MSP430:
16 bit microcontroller
MICROCONTROLLER
The Family
Three Subfamilies
MSP430X1XX:basic unit
MSP430X2XX:Added features
MSP430X3XX:more features
MSP430X4XX:built-in LCD driver
MICROCONTROLLER
Introduction to MSP430
Features of MSP430:
Low supply-voltage Range:1.8 V to 3.6 V
3 Clock signals-MCLK,SMCLK,ACLK
16-bit RISC Architecture
51 instructions
16 bit Registers
7 addressing modes
Two 16-Bit Timer
MICROCONTROLLER
Introduction to MSP430
MSP430G2553
MSP430G2553 Variant
Asha.S.Patil
ashaspatil@pes.edu
Department of Electrical & Electronics Engineering
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
MSP430 Architecture
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Anatomy of a typical small MC
Data bus
Address bus
Central Processing
Unit (CPU) Clock
MICROCONTROLLER
Central Processing Unit(MSP430)
2. Registers
15 bits 0
R0/PC Program Counter
R1/SP Stack Pointer
R2/SR/CG1 Status Register
R3/CG2 Constant Generator
R4 General Purpose
1.Program Counter: R0
2.Stack Pointer:R1
PUSH: decrements Sp by 2
POP: increments Sp by 2
MICROCONTROLLER
Registers
3.Status Register(SR):
15 9 8 7 0
Reserved V SCG1 SCG0 OSC CPU GIE N Z C
OFF OFF
MICROCONTROLLER
Registers
4.Constant Generator(CG):
R4-R15
THANK YOU
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
Microcontroller
MSP430
MSP430 Architecture
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Registers
Status Register(SR):
15 9 8 7 0
Reserved V SCG1 SCG0 OSC CPU GIE N Z C
OFF OFF
MICROCONTROLLER
Registers
Memory:
RAM: SRAM,DRAM
MICROCONTROLLER
ORDERING OF BITS, BYTES AND WORDS IN MEMORY
MICROCONTROLLER
Ordering in Memory
1. Little-Endian Ordering
2. Big-Endian Ordering
MICROCONTROLLER
MEMORY MAP OF MSP430G2553
THANK YOU
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
The Outside View—Pin-Out MSP430G2553
MICROCONTROLLER
GENERAL PURPOSE INPUT AND OUTPUT
Floating
MICROCONTROLLER
GPIO INPUT
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Block Diagram Of Clock Module
MICROCONTROLLER
ClOCK SYSTEM
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
MSP430 –IDE
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Development Environment
Editor
Assembler 0r Compiler
Linker
Embedded emulator/debugger
In circuit emulator
Flash programmer
MICROCONTROLLER
Development Environment
- CCS
-IAR
MICROCONTROLLER
The C Programming language
Declarations:
}
MICROCONTROLLER
Shifts:
Left shift: value <<= 1
Right shift: arithmetic and logical shifts
Rotation
MICROCONTROLLER
The C Programming language
A&B=10001000
Unions:
#include “msp430.h” //
#include <stdlib.h> //
#define MAX_ITER 10
void main()
{
char choice;
int test_num,
stuff; // ...
stuff = someFunction('a',test_num);
// ...
}
THANK YOU
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Assembly Language
MOV.w #0x08,R5
AND.w #0x00,R5
BIC.W #0x03, R5
BIS.W #0X03,R4
CMP.W R5,R6
THANK YOU
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Exceptions
Classes of Exceptions:
Interrupts:
Generated by Hardware
Interrupts and
Resets
MICROCONTROLLER
Classification of interrupts
WDT Function:
to reset the MC
MICROCONTROLLER
WDT+
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Installation of IDE
CC studio V9 does not support Simulator and always needs the boards to work with.
IAR Workbench V7.12 does support Simulator and can support
the working of code without the boards.
MICROCONTROLLER
Development Environment
/**
* main.c
*/
intmain(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
P1DIR |= 0x01; // configure P1.0 as output
while(1)
{
P1OUT ^= 0x01; // toggle P1.0
for(i=10000; i>0; i--)
; // delay
}
return 0;
}
MICROCONTROLLER
Development Environment
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Development Board
MICROCONTROLLER
Features of MSP430G2553
Courtesy:www.ti.com
MICROCONTROLLER
The pin diagram of MSP430G2553
THANK YOU
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Basic code example1
#include "msp430x22x4.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to output direction
for (;;)
{
P1OUT ˆ= 0x01; // Toggle P1.0 using exclusive-OR
i = 50000; // Delay
do (i--);
while (i != 0);
}
}
MICROCONTROLLER
Basic code example2
1.LED BLINKING:
Note:for delay :_delay_cycles(2500);
#include <msp430g2553.h>
int main(void)
{
return(0);
}
MICROCONTROLLER
Basic code example2
1.LED BLINKING:.To turn on LED using assembly language programming
;;-------------------------------------------------------------------------------
.cdecls C,LIST,"msp430.h" ; Include device header file
;-------------------------------------------------------------------------------
.def RESET ; Export program entry-point to
; make it known to linker.
;-------------------------------------------------------------------------------
.text ; Assemble into program memory.
.retain ; Override ELF conditional linking
; and retain current section.
.retainrefs ; And retain any sections that have
; references to current section.
;-------------------------------------------------------------------------------
RESET mov.w #__STACK_END,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
;-------------------------------------------------------------------------------
; Main loop here
;------------------------------------------------------------------------------
-------------------------------------------------------------------------------
; Stack Pointer definition
;-------------------------------------------------------------------------------
.global __STACK_END
.sect .stack
;-------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET
THANK YOU
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Addressing MODES
7 Addressing Modes
Jumps
MICROCONTROLLER
Instruction format
Jumps
MICROCONTROLLER
Instruction format
Jump:
e.g., JC Label
JNC Label
RET
MICROCONTROLLER
Types of Addressing Mode-MSP430
destination
Before After
Execution Execution
R5 1234H R5 1234H
R6 ABCDH R6 1234H
PC 8000H PC 8002H
MICROCONTROLLER
Types of Addressing Mode-MSP430
Initially If
R5=1002H;2(R5)=1002H+0002H=1004H
R6=A0B2;6(R6)=A0B2H+0006H=A0B8H
PC Reg Content
PC Reg Content
1004H 1234h 1004H 1234h
1002H xxxxx 1002H xxxxx
FF12H xxxxx FF12H xxxxx
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Types of Addressing Mode-MSP430
destination
mov .w X ( PC ) , R6
destination
mov .w X ( PC ) , R6
destination
Mov.w 0(L1),0(L2)
source
source
Mov #10,R5
MICROCONTROLLER
Types of Addressing Mode-MSP430
destination
e.g., Mov.w 2( SP ) , R6
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
MSP430 INSTRUCTION SET
27 Core
-Double Operand Instructions(12)
-Single Operand Instructions(7)
-Jump Instructions(8)
MICROCONTROLLER
DOUBLE OPERAND INSTRUCTIONS
ƒ
MICROCONTROLLER
Double operand instruction format
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
-Assembly: rrc.w r5
-Instruction Code: 0x1005
Conditional jumps:
support program branching relative to the PC and do not
affect the status bits.
The possible jump range is from −511 to +512 words
relative to the PC value at the jump instruction.
The 10-bit program-counter offset is treated
as a signed 10-bit value that is doubled and added to the
program counter:
PC new = PC old + 2 + PC offset × 2
Unconditional jumps:
JMP Label
MICROCONTROLLER
Jump Instruction Format
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
-Assembly: JC main
-Instruction Code: 0X2fe4
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Data Movement
MOV instruction
Addressing modes
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Logic Bitwise Instructions
Effects on Flags
Flags are affected by logic operations as follows, under
otherwise indicated:
Z=1 if destination is cleared
Z=0 if at least one bit in destination is set
C= Z’ (Flag C is always equal to the inverted value of Z in
these operations)
N = most significant bit of destination
V = 0
MICROCONTROLLER
Core bitwise Instructions affecting flags
bit src, dest realizes src .and. dest but only affects flagsƒ
MICROCONTROLLER
Core bitwise Instructions affecting flags
RRA
RRC
LRA
LRC
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Programming in assembly language
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Installation of IDE
http://www.ti.com/tool/CCSTUDIO-MSP
THANK YOU
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Programming in assembly language
Blinking LED
Example 2:
bis.b #1,&P1DIR
outer
xor.b #1,&P1OUT
mov.w #0x2710,r5
mov.w #0x2710,r4
inner
dec.w r4
dec.w r5
tst.w r5
jne inner
jmp outer
THANK YOU
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
MSP430 – C Programming
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Functions and Subroutines
Functions :useful for code that is called from more than one
place but should be used much more widely, to encapsulate
every distinct function.
MICROCONTROLLER
What Happens when a Subroutine Is Called?
end of the subroutine the ret instruction pops the return address
off the stack into the PC so that execution resumes with the
instruction following the call of the subroutine.
MICROCONTROLLER
Calling Subroutine
call #DelayTenths
MICROCONTROLLER
Storage for Local Variables
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
MSP430-C Programming
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Programming Example in C
#include <msp430g2553.h>
/*
* main.c
*/
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
return(0);
THANK YOU
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Programming concept
Storage area:R0-R15
R0-------PC
R1-------SP
R2 &R3—CG
ADDRESSING MODE:
#---------IMMEDIATE AM
@---------INDIRECT ADDRESSING MODE
@+--------AUTOINCREMENT MODE
()-----------INDEXED AM
MICROCONTROLLER
Programming concept
We can add together to control multiple bits. For example, we can add a
bit in position 7 and 6 by doing an OR with 0x80 and 0x40:
P1OUT |= 0x80 + 0x40;
MICROCONTROLLER
Programming concept
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
CLOCK SYSTEM
IO
Timer System
MICROCONTROLLER
CLOCK SYSTEM
Oscillator Faults
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
MSP430 – RESETS
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
MSP430 resets
Caused by hardware.
Response of hardware to brownout (low-power)
condition.
General effects:
General effects:
Be careful with RST pin! Should never be left floating and de-
coupled from noise as best as possible. Modern uCs/uPs can
have very sensitive RST lines!
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
MSP430 – Interruppts
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
MSP430 interrupts
interrupt Acceptance
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
MSP430 – Interruppts
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
MSP430 interrupts
interrupt Acceptance
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
MSP430 – Interruppts
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
MSP430 interrupts
interrupt Acceptance
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
MSP430 – TIMER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Inside MSP430 (MSP430G2x31)
IO
k
m
Timer System
MICROCONTROLLER
Inside MSP430
MICROCONTROLLER
Inside MSP430
.Timer_A Control Register: TACTL
Typical Operations of Timer_A
Continuously
count up/down
Is time up Yes
yet?
TAIFG has to be explicitly
cleared by the CPU
TACCRx If TAIE=1, setting of TAIFG
causes an interrupt to the CPU
TACTL
• The up/down mode is used if the timer period must be different from
0FFFFh counts, and if a symmetrical pulse generation is needed.
→ The period is twice the value in TACCR0.
Timer interrupts!
(TAIFG is set)
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
MSP430 – TIMER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Inside MSP430 (MSP430G2x31)
IO
k
m
Timer System
MICROCONTROLLER
Inside MSP430
MICROCONTROLLER
Inside MSP430
.Timer_A Control Register: TACTL
Typical Operations of Timer_A
Continuously
count up/down
Is time up Yes
yet?
TAIFG has to be explicitly
cleared by the CPU
TACCRx If TAIE=1, setting of TAIFG
causes an interrupt to the CPU
TACTL
• The up/down mode is used if the timer period must be different from
0FFFFh counts, and if a symmetrical pulse generation is needed.
→ The period is twice the value in TACCR0.
Timer interrupts!
(TAIFG is set)
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
MSP430 – TIMER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Inside MSP430 (MSP430G2x31)
IO
k
m
Timer System
MICROCONTROLLER
Inside MSP430
MICROCONTROLLER
Inside MSP430
.Timer_A Control Register: TACTL
Typical Operations of Timer_A
Continuously
count up/down
Is time up Yes
yet?
TAIFG has to be explicitly
cleared by the CPU
TACCRx If TAIE=1, setting of TAIFG
causes an interrupt to the CPU
TACTL
• The up/down mode is used if the timer period must be different from
0FFFFh counts, and if a symmetrical pulse generation is needed.
→ The period is twice the value in TACCR0.
Timer interrupts!
(TAIFG is set)
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
MSP430 – TIMER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Timer_A Capture/Compare Block
Timer Block
• Compare mode:
• Compare the value of TAR with the value stored in TACCRn and update an
output when they match
• Capture mode: used to record time events
• Records the “time” (value in TAR) at which the input changes in TACCRx
• The input, usually CCIxA and CCIxB, can be either external or internal from
another peripheral or software, depending on board connections
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Watchdog Timer
7 0
Password Compare
HOLD NMIES NMI TMSEL CNTCL SSEL IS1 ISO
EQU
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
MSP430 – TIMER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Timer_A PROGRAMMING in C
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
MSP430 – TIMER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Timer_A PROGRAMMING
delay:
mov.w #32767, &TACCR0 ;seting the timer compare value
ret
jmp $
MICROCONTROLLER
Timer_A PROGRAMMING
delay:
mov.w #32767, &TACCR0 ;seting the timer compare value
mov.w #CCIE, &TACCTL0 ;compare interrupt enable
mov.w #(TASSEL_1|MC_1|TACLR), &TACTL ;setting the timer with ACLK clock
xor.b #1, &P1OUT
BIC.W #TAIFG,&TA0CTL
ret
jmp $
MICROCONTROLLER
Timer_A PROGRAMMING
MICROCONTROLLER
#include “MSP430.h”
VOID main(void)
{
WDTCTL=WDTPW|WDTHOLD;
TA0CTL=TASSWL_1+MC_1+ID_3;
TA0CCR0=4000;
P1DIR|=0X01;
P1OUT|=0X00;
P1OUT^=0X01;
}
MICROCONTROLLER
MICROCONTROLLER
MICROCONTROLLER
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Basic code example1
#include "msp430x22x4.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to output direction
for (;;)
{
P1OUT ˆ= 0x01; // Toggle P1.0 using exclusive-OR
i = 50000; // Delay
do (i--);
while (i != 0);
}
}
MICROCONTROLLER
Basic code example2
1.LED BLINKING:
Note:for delay :_delay_cycles(2500);
#include <msp430g2553.h>
int main(void)
{
return(0);
}
MICROCONTROLLER
Basic code example2
1.LED BLINKING:.To turn on LED using assembly language programming
;;-------------------------------------------------------------------------------
.cdecls C,LIST,"msp430.h" ; Include device header file
;-------------------------------------------------------------------------------
.def RESET ; Export program entry-point to
; make it known to linker.
;-------------------------------------------------------------------------------
.text ; Assemble into program memory.
.retain ; Override ELF conditional linking
; and retain current section.
.retainrefs ; And retain any sections that have
; references to current section.
;-------------------------------------------------------------------------------
RESET mov.w #__STACK_END,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
;-------------------------------------------------------------------------------
; Main loop here
;------------------------------------------------------------------------------
-------------------------------------------------------------------------------
; Stack Pointer definition
;-------------------------------------------------------------------------------
.global __STACK_END
.sect .stack
;-------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET
THANK YOU
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Block Diagram Of Clock Module
MICROCONTROLLER
ClOCK SYSTEM
Timer System
Inside Timer_A
Continuously
count up/down
Is time Yes
up yet?
TAIFG has to be
explicitly cleared by
the CPU
TACCRx If TAIE=1, setting of
TAIFG causes an
interrupt to the CPU
TACTL
Timer interrupts!
(TAIFG is set)
Timer_A Capture/Compare Block
Timer Block
Timer System
Theoretically, One Clock Is Enough
• A clock is a square wave signal whose edges
trigger hardware
• A clock may be generated by various sources
of pulses, e.g. crystal
• But, systems have conflicting requirements
– Low power, fast start/stop, accurate
Different Requirements for Clocks
• Devices often in a low-power mode until some
event occurs, then must wake up and handle
event rapidly
– Clock must be stabilized quickly
• Devices also need to keep track of real time: (1)
can wake up periodically, or (2) time-stamp
external events
• Therefore, two kinds of clocks often needed:
– A fast clock to drive CPU, which can be started and
stopped rapidly but need not be accurate
– A slow clock that runs continuously to monitor
real time that uses little power and is accurate
Different Requirements for Clocks
• Different clock sources also have different
characteristics
– Crystal: accurate and stable (w.r.t. temperature or
time); expensive, delicate, drawing large current,
external component, slow to start up or stabilize
– Resistor and capacitor (RC): cheap, quick to start,
integrated within MCU and sleep with CPU; poor
accuracy and stability
– Ceramic resonator and MEMS clocks in between
Need multiple clocks
Clocks in MSP430
• MSP430 addresses the conflicting demands
for high performance, low power, precise
frequency by using 3 internal clocks, which
can be derived from up to 4 sources
– Master clock (MCLK): for CPU & some peripherals,
normally driven by digitally controlled oscillator
(DCO) in megahertz range
– Subsystem master clock (SMCLK): distributed to
peripherals, normally driven by DCO
– Auxiliary clock (ACLK): distributed to peripherals,
normally for real-time clocking, driven by a low-
frequency crystal oscillator, typically at 32 KHz
Clock Sources in MSP430
• Low- or high-frequency crystal oscillator, LFXT1:
– External; used with a low- or high frequency crystal; an
external clock signal can also be used; connected to
MSP430 through XIN and XOUT pins
• High-frequency crystal oscillator, XT2:
– External; similar to LFXT1 but at high frequencies
• Very low-power, low-frequency oscillator, VLO:
– Internal at 12 KHz; alternative to LFXT1 when accuracy of a
crystal is not needed; may not available in all devices
• Digitally controlled oscillator, DCO:
– Internal; a highly controllable RC oscillator that starts fast
From Sources to Clocks
• Typical sources of clocks:
– MCLK, SMCLK: DCO (typically at 1.1 MHz)
– ACLK: LFXT 1 (typically at 32 KHz)
Control Registers for Clocks
Control Registers for Clock System
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
LCD codes
#include <msp430g2553.h>
void data_write(void)
{
ENABLE_HIGH;
delay(2);
ENABLE_LOW;
}
MICROCONTROLLER
LCD codes
void data_read(void)
{
ENABLE_LOW;
delay(2);
ENABLE_HIGH;
}
void data_write(void)
{
ENABLE_HIGH;
delay(2);
ENABLE_LOW;
}
MICROCONTROLLER
LCD codes
void check_busy(void)
{
P1DIR &= ~(BIT3); // make P1.3 as input
while((P1IN&BIT3)==1)
{
data_read();
}
P1DIR |= BIT3; // make P1.3 as output
}
MICROCONTROLLER
LCD codes
}
MICROCONTROLLER
LCD codes
void lcd_init(void)
{
P1DIR |= 0xFF;
P1OUT &= 0x00;
send_command(0x33);
send_command(0x32);
send_command(0x28); // 4 bit mode
send_command(0x0E); // clear the screen
send_command(0x01); // display on cursor on
send_command(0x06); // increment cursor
send_command(0x80); // row 1 column 1
}
MICROCONTROLLER
LCD codes
Main Code:
#include "lcd.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // stop watchdog
timer
lcd_init();
send_string("PESU EEE");
send_command(0xC0);
send_string("MICROCONTROLLER");
while(1){}
}
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
MSP430
MICROCONTROLLER
MSP430
MICROCONTROLLER
LCD pin description
MICROCONTROLLER
LCD interfacing diagram
MICROCONTROLLER
LCD connections
Connections:
P1.0 - D4 Pin11
P1.1 - D5 Pin12
P1.2 - D6 Pin13
P1.3 - D7 Pin14
P1.4 - RS Pin4
P1.5 - R/W Pin5
P1.6 - E Pin6
Gnd-Pin 1
5V-Pin 2
3.3V-Anode pin 15
Gnd-CATHODE pin 16
MICROCONTROLLER
LCD 4 bit mode
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
MSP430
MICROCONTROLLER
MSP430
#include "msp430g2553.h"
void main()
{
WDTCTL = WDTPW + WDTHOLD;
}
void Delay(int j)
{
int i;
for(j=0;j<10;j++)
for(i=0;i<0xFFFF;i++);
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
MSP430
control two DC brushed motors using MSP430 Launchpad
(MSP430G2553) and L293D Motor Driver IC .
L293D is a quadruple high-current half-H driver IC which can be
used for controlling DC brushed motors,solenoids,relays etc.
MICROCONTROLLER
MSP430
MICROCONTROLLER
MSP430 PWM
The IC contains 4 half H drivers which can be combined together
to create two full H bridge circuits for controlling two DC brushed
motors.
The L293D is designed to provide bidirectional drive currents of
up to 600-mA at voltages from 4.5 V to 36 V, Here we will be
running the motors at 12V.
MICROCONTROLLER
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
MSP430 – PWM
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
MSP430 PWM
Program to generate PWM signal at P1.2
#include “MSP430.h”
Void main(void)
{
WDTCTL=WDTPW|WDTHOLD;
P1DIR|=0X04; DIRECTION OF PORT PIN p1.2 AS OUTPUT
P1SEL|=0X04;INITIALIZE PORT FOR OUTPUT SIGNAL
OUT1(PWM FUNCTION)
TACCRO=0XFF; COUNT FOR PERIOD(ON+OFF)
TACCR1=0X20; COUNT FOR ON TIME
TACCTL1=OUTMOD_7; RESET/SET OUTPUT MODE
TACTL=TASSEL_1+ID_1+MC_1;ACLK/2,UPMODE,CLEAR ,NO
INTERRUPT
LOW_POWER_MODE_3();
WHILE(1);
}
MICROCONTROLLER
MSP430 PWM
Timer Frequency=32KHz/2=16KHz
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
MSP430 – PWM
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
MSP430 PWM
So, we will say the on time of PWM is 10ms and off time
is 10ms.
MICROCONTROLLER
MSP430 PWM
There are three to five capture/compare blocks inside Timer_A of MSP430 controller.
Any one of the blocks may be used to capture timer data or generate intervals.
In Timer_A ,the TACCR0 is stored for total period value of PWM and
TACCR1 is used to store on period of PWM duty cycle.
The Timer_A TAR register is in upmode and gets incremented for every clock given by selected clock source.
MICROCONTROLLER
MSP430 PWM
To use the PWM to achieve a duty cycle of 20%, we would use the following code:
CCTL1 = OUTMOD_7;
CCR1 = 200 - 1;
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Basics of ADC
what 10bit resolution is and how this maybe relevant to the accuracy of
a project.
10bit means 2 to the power of 10, which equals 1024, the 1024 is the
number of sample steps taken over a given range (in the case of
microcontrollers it’s actually 0 to 1023).
The range is defined as what voltage range the ADC accepts, to find
this we need to see the datasheet for the MSP430G2253.
MICROCONTROLLER
Basics of ADC
void ADC_capture(void)
{
/* Configure ADC Channel */
ADC10CTL0 = ADC10SHT_3 + ADC10ON + ADC10IE; //64 clk ticks, ADC on, enable interrupt
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Stepper Motor
There are actually many ways you can interface a stepper motor to
your controller, out of them the most used interfaces are:
For n=200
360/200=1.8
1.8x4=7.2(for full step)
If we want to rotate for 180 degree
180/7.2=25
#include <MSP430g2553.H>
#define stepper P1
void delay()
{
unsigned char i,j,k;
for(i=0;i<6;i++) {
for(j=0;j<255;j++)
for(k=0;k<255;k++);
}
}
MICROCONTROLLER
Stepper Motor
void main()
{
while (1) {
stepper = 0x0C;
delay();
stepper = 0x06;
delay();
stepper = 0x03;
delay();
stepper = 0x09;
delay();
}
}
MICROCONTROLLER
Stepper Motor
usually has four wires coming out of it. Unlike unipolar steppers, bipolar
steppers have no common center connection.
Working
step A B C D
1 1 0 0 0
2 0 1 0 0
3 0 0 1 0
4 0 0 0 1
MICROCONTROLLER
Stepper Motor
step A B C D
1 1 1 0 0
2 0 1 1 0
3 0 0 1 1
4 1 0 0 1
MICROCONTROLLER
Stepper Motor
Half Step Sequence
step A B C D
1 1 0 0 0
2 1 1 0 0
3 0 1 0 0
4 0 1 1 0
5 0 0 1 0
6 0 0 1 1
7 0 0 0 1
8 1 0 0 1
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Stepper Motor
The unipolar stepper motor has five or six wires and four coils (actually
two coils divided by center connections on each coil). The center
connections of the coils are tied together and used as the power
connection. They are called unipolar steppers because power always
comes in on this one pole.
MICROCONTROLLER
Stepper Motor
The unipolar stepper motor has five or six wires and four coils (actually
two coils divided by center connections on each coil).
The center connections of the coils are tied together and used as the
power connection.
They are called unipolar steppers because power always comes in on
this one pole.
MICROCONTROLLER
Stepper Motor
usually has four wires coming out of it. Unlike unipolar steppers, bipolar
steppers have no common center connection.
Working
step A B C D
1 1 0 0 0
2 0 1 0 0
3 0 0 1 0
4 0 0 0 1
MICROCONTROLLER
Stepper Motor
step A B C D
1 1 1 0 0
2 0 1 1 0
3 0 0 1 1
4 1 0 0 1
MICROCONTROLLER
Stepper Motor
Half Step Sequence
step A B C D
1 1 0 0 0
2 1 1 0 0
3 0 1 0 0
4 0 1 1 0
5 0 0 1 0
6 0 0 1 1
7 0 0 0 1
8 1 0 0 1
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
SERIAL COMMUNICATION
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
i2C
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Serial Peripheral Interface
//
void main(void)
// Description: SPI Master communicates at fast as possible, full-duplex with
{
// SPI Slave using 3-wire mode. The level on P1.4/5 is TX'ed and RX'ed to P1.0
// and P1.1. Master will pulse slave Reset on init to insure synch start.
// ACLK = n/a, MCLK = SMCLK = DCO ~ 800kHz, ULCK = external P1OUT = 0x00; // P1.0 setup for LED output
// P1DIR |= 0x03;
// fet140_slav0 fet140_mstr0
P3SEL |= 0x0E; // P3.1,2,3 SPI option select
// MSP430F169 Slave MSP430F169 Master
U0CTL = CHAR + SYNC + SWRST; // 8-bit, SPI
// ----------------- -----------------
U0TCTL = CKPL + STC; // Polarity, 3-wire
// | XIN|- /|\| XIN|-
U0BR0 = 0x02; // SPICLK = SMCLK/2
// | | | | |
U0BR1 = 0x00;
// | XOUT|- --|RST XOUT|-
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
SERIAL COMMUNICATION
MICROCONTROLLER
SERIAL COMMUNICATION
MSP430G2553
has two USCI modules names
as USCI_A0 and USCI_B0 for handling multiple
communication formats.
MICROCONTROLLER
SERIAL COMMUNICATION
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
SERIAL COMMUNICATION
UCA0TXBUF = 'A';
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
SERIAL COMMUNICATION
Now when you are interfacing with a PC RS232 serial port ,you require
atleast 3 lines RXD ,TXD andGround to communicate with the
Launchpad board.
The RS232 signals coming from the PC serial serial port is in the range
of +15 to -15V so you can't connect it directly to the microcontroller
pins.You have to build a RS232 level converter(for eg MAX232) to
convert between RS232 and TTL signal levels.
The below figure shows the connection diagram between an MSP430
Launch pad and PC DB9 serial port.
We can see that UCA0RXD (Blue Wire) the receive pin of
microcontroller is connected to the Transmit pin of PC serial port.
MICROCONTROLLER
SERIAL COMMUNICATION
MICROCONTROLLER
SERIAL COMMUNICATION
UCA0TXBUF = 'A';
Asha.S.Patil
Department of Electrical & Electronics Engineering
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
SERIAL COMMUNICATION
Data Transfer
The rate of data transfer in serial data communication is stated in bps (bits per second)
Another widely used terminology for bps is baud rate
It is modem terminology and is defined as the number of signal changes per second
In modems, there are occasions when a single change of signal transfers several bits of data
MICROCONTROLLER
SERIAL COMMUNICATION
Data Transfer
As far as the conductor wire is concerned, the baud rate and bps are the same
The data transfer rate of given computer system depends on communication ports
incorporated into that system
IBM PC/XT could transfer data at the rate of 100 to 9600 bps
Pentium-based PCs transfer data at rates as high as 56K bps
In asynchronous serial data communication, the baud rate is limited to 100K bps
MICROCONTROLLER
SERIAL COMMUNICATION
RS232 Standards
An interfacing standard RS232 was set by the Electronics Industries Association (EIA) in 1960
The standard was set long before the advent of the TTL logic family, its input and output voltage levels are n
A 1 is represented by -3 ~ -25 V
A 0 bit is +3 ~ +25 V
Making -3 to +3 undefined
MICROCONTROLLER
SERIAL COMMUNICATION
MICROCONTROLLER
SERIAL COMMUNICATION
ashaspatil@pes.edu
THANK YOU
Microcontroller
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
SERIAL COMMUNICATION
ashaspatil@pes.edu
THANK YOU