Microcontroller
Microcontroller
Microcontroller
USING LATEX
ABHISHEK V BHAT
1MS12EC001
SECTION A
QUESTIONS RELATED TO 8051
November 6, 2014
Microcontroller Assignment-2
8051
Contents
1 A Switch is connected to the pin P1.2. Write an 8051 C program to monitor the switch
and create the following frequencies on the pin P1.7.
(i) When SW = 0, 500Hz
(ii) When SW = 1, 750Hz. Use timer 0, mode 1 for both of them.
3
2 List the advantages of serial communication over parallel communication
4 Write a C program to send the message The Earth is Beautiful, to the serial port continuously. Assume XTAL=11.0592MHz, 9600 baud rate, 8-bit data and one stop bit.
6
5 Describe the 8051 connection to stepper motor. A switch is connected to pin P2.7. Write
an C program to monitor the status of SW and perform the following:
(i) If SW=0, the stepper motor moves clockwise.
(ii) If SW=0, the stepper motor moves clockwise.
6
5.1 8051 Connection to Stepper Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
5.2 C program to rotate stepper motor clock/anticlowise. . . . . . . . . . . . . . . . . . . . . . . . . .
7
6 Write the C program to toggle all the bits of P0 and P2 continuously with 250mSec delay.
Use the inverting operator.
8
7 Explain the resisters and pins of an
MSRIT on the LCD panel.
7.1 Pin Description for LCD . . . . . .
7.2 Register inside the LCD . . . . . . .
7.3 ALP to display message MSRIT .
8
8
8
9
8 A switch (SW) is connected to P2.0 port pin. Write a C program to send out the value
44H serially one bit at a time via P1.0, depending upon switch condition:
(i) When SW=0 LSB should go out first
(ii) When SW=1 MSB should go out first
10
9 Write a C program to convert a given hex-data FDH into its equivalent decimal dara and
display the result digits on the P0,P1,P2
10
10 Describe the 8051 connection to stepper motor. A switch is connected to pin P2.7. Write
an ALP to monitor the status of SW and perform the following:
(i) If SW=0, the stepper motor moves clockwise.
(i) If SW=0, the stepper motor moves clockwise.
11
10.1 8051 Connection to Stepper Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
10.2 ALP to rotate stepper motor clock/anticlowise . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
11 Write a C program to send the message Good Morning, serially at 9600 baud rate, 8-bit,
1 stop bit.
12
12 Explain the importance of TI and RI flag
12
12.1 Importance of TI flag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
12.2 Importance of RI flag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
ABHISHEK V BHAT
2 of 25
1MS12EC001
Microcontroller Assignment-2
8051
SWITCH
500 Hz or
750 Hz
depending
on SW
P1.2
ABHISHEK V BHAT
// toggle P1.5
3 of 25
1MS12EC001
Microcontroller Assignment-2
8051
// Count = FC67H
// Count = FD9AH
//
//
//
//
4 of 25
1MS12EC001
Microcontroller Assignment-2
8051
8051
A9
5kHz
RXD
P3.0
P3.0
P1.2
P1.7
P0.1
P3.1
TXD
8
P1
P2
C program
#include < reg51.h>
sbit WAVE = P0^1;
void timer0() interrupt 1
{
WAVE = ~WAVE;
}
void serial0() interrupt 4
{
if (TI == 1)
{
TI = 0;
}
else
{
P0 = SBUF;
RI = 0;
}
}
void main()
{
unsigned char x;
P1 = 0xFF;
TMOD = 0x22;
TH1 = 0xF6;
SCON = 0x50;
TH0 = 0xA4;
IE = 0x92;
TR1 = 1;
TR0 = 1;
while(1)
{
x = P1;
SBUF = x;
P2 = x;
}
}
ABHISHEK V BHAT
// Clear Interrupt
5 of 25
1MS12EC001
Microcontroller Assignment-2
8051
Describe the 8051 connection to stepper motor. A switch is connected to pin P2.7. Write an C program to monitor the status of
SW and perform the following:
(i) If SW=0, the stepper motor moves clockwise.
(ii) If SW=0, the stepper motor moves clockwise.
+5
+5
DS89C4x0
4.7k
4.7k
4.7k
4.7k
Unipolar Stepper
motor
P1.0
P1.1
P1.2
P1.3
One power supply is used for the
motor and the ULN2003 and the
other for the 8051
ABHISHEK V BHAT
6 of 25
8
+5
1MS12EC001
Microcontroller Assignment-2
5.1
8051
1. An ohmmeter is used to measure the resistance of the leads. This should identify which COM leads are
connected to which winding leads.
2. The common wire(s) are connected to the positive side of the motors power supply.
3. The four leads of the stator winding are controlled by four bits of the 8051 port (Pl.0 - P1.3).But 8051
lacks sufficient current to drive the stepper motor windings, driver such as the ULN2003 is used to energize
the stator. Reason for using the ULN2003 is it has an internal diode to take care of back EMF.
5.2
# include <reg.h>
sbit SW = P2^7;
void main ( )
{
SW =1;
while (1)
{
if( SW==0)
{
P1 = 0x66;
MSDelay(100);
P1 = 0xCC;
MSDelay(100);
P1 = 0x99 ;
MSDelay(100);
P1 = 0X33;
MSDelay(100);
}
else
{
P1 = 0x66;
MSDelay(100);
P1 = 0X33;
MSDelay(100);
P1 = 0x99;
MSDelay(100);
P1 = 0xCC;
MSDelay(100);
}
}
}
// SW = Switch
ABHISHEK V BHAT
7 of 25
1MS12EC001
Microcontroller Assignment-2
8051
Write the C program to toggle all the bits of P0 and P2 continuously with 250mSec delay. Use the inverting operator.
// toggle P0
// toggle P2
Explain the resisters and pins of an LCD panel and write an 8051
ALP display message MSRIT on the LCD panel.
7.1
7.2
Symbol
V
V
V
RS
R/W
E
DB0
DB1
DB2
DB3
DB4
DB5
DB6
DB7
I/O
I
I
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
Description
Ground
+5V Power supply
Power supply to control contrast
RS=0 to select command register,RS =1 to select data register
R/W = 0 for write, R/W = 1 for read
Enable
The 8-bit data bus
The 8-bit data bus
The 8-bit data bus
The 8-bit data bus
The 8-bit data bus
The 8-bit data bus
The 8-bit data bus
The 8-bit data bus
1. There are two very important register present in LCD. The RS pin in used for their selection.
2. If RS = 0, the instruction command code register is selected, then user can send a command such as clear
display, cursor at home etc.If RS = 1 the data register is selected, it allows the user to send data to be
ABHISHEK V BHAT
8 of 25
1MS12EC001
Microcontroller Assignment-2
8051
7.3
LOC1:
SENDDAT:
LOC2:
AGAIN:
COMNWRT:
DATAWRT:
DELAY:
HERE2:
HERE:
MYCOM:
MYDATA:
MNEMONIC
ORG
MOV
CLR
MOVC
ACALL
ACALL
JZ
INC
SJMP
MOV
CLR
MOVC
ACALL
ACALL
INC
JZ
SJMP
SJMP
MOV
CLR
CLR
SETB
ACALL
CLR
RET
MOV
SETB
CLR
SETB
ACALL
CLR
RET
MOV
MOV
DJNZ
DJNZ
RET
ORG
DB
DB
END
ABHISHEK V BHAT
OPERAND
0
DPTR, # MYCOM
A
A, @A+DPTR
COMNWRT
DELAY
SENDDAT
DPTR
LOC1
DPTE, # MYDATA
A
A, @A+DPTR
DATAWRT
DELAY
DELAY
AGAIN
LOC2
AGAIN
P1, A
P2.0
P2.1
P2.2
DELAY
P2.2
;
;
;
;
;
;
;
stay here
send command to P1
RS = 0 for command
R/W = 0 for command
E = 1 for high pulse
give LCD some time
E = 0 for H-to-L
P1,A
P2.0
P2.1
P2.2
DELAY
P2.2
;
;
;
;
;
;
send data to P1
RS = 1 for data
R/W = 0 for write
E = 1 for high pulse
give LCD some time
E = 0 for H-to-L pulse
R3,
R4,
R4,
R3,
# 250
# 255
HERE
HERE2
300H
38H,0EH,01,06,84H,0
HELLO,0
9 of 25
COMMENT
1MS12EC001
Microcontroller Assignment-2
8051
SWITCH
P2.0
#include <reg51.h>
sbit P1b0 = P1^0;
sbit regALSB = ACC^0;
sbit regAMSB = ACC^7;
sbit SW = P2^0;
void main(void)
{
unsigned char conbyte = 0x44;
unsigned char x;
ACC = conbyte;
for(x=0;x<8;x++)
{
if(SW==0) /*sending 44H serially out one bit at time. LSB is going out first*/
{
P1b0 = regALSB;
ACC = ACC << 1;
}
else
/*sending 44H serially out one bit at time. MSB is going out first*/
{
P1b0 = regAMSB;
ACC = ACC << 1;
}
}
}
Write a C program to convert a given hex-data FDH into its equivalent decimal dara and display the result digits on the P0,P1,P2
ABHISHEK V BHAT
10 of 25
1MS12EC001
Microcontroller Assignment-2
8051
{
unsigned char x, binbyte, d1,d2,d3;
binnyte = 0xFD;
// binary (hex) byte
x = binbyte / 10;
// divide by 10
d1 = binbyte % 10;
// remainder is Least Significant digit(LSD)
d2 = x % 10;
// middle digit
d3 = x / 10;
// Most Significant digit (MSD)
P0 = d1;
// send d1 through port P0
P1 = d2;
// send d2 through port P1
P2 = d3;
// send d3 through port P2
}
10
+5
+5
DS89C4x0
4.7k
4.7k
4.7k
4.7k
Unipolar Stepper
motor
P1.0
P1.1
P1.2
P1.3
One power supply is used for the
motor and the ULN2003 and the
other for the 8051
10.1
8
+5
1. An ohmmeter is used to measure the resistance of the leads. This should identify which COM leads are
connected to which winding leads.
2. The common wire(s) are connected to the positive side of the motors power supply.
3. The four leads of the stator winding are controlled by four bits of the 8051 port (Pl.0 - P1.3).But 8051
lacks sufficient current to drive the stepper motor windings, driver such as the ULN2003 is used to energize
the stator. Reason for using the ULN2003 is it has an internal diode to take care of back EMF.
ABHISHEK V BHAT
11 of 25
1MS12EC001
Microcontroller Assignment-2
10.2
LABEL
MAIN :
TURN :
CW :
DELAY :
H1 :
H2 :
11
8051
MNEMONIC
ORG
SETB
MOV
MOV
JNB
RR
ACALL
MOV
SJMP
RL
ACALL
MOV
SJMP
MOV
MOV
DJNZ
DJNZ
RET
END
OPERAND
0
P2.7
A, #66H
P1, A
P2.7, CW
A
DELAY
P1, A
TURN
A
DELAY
P1, A
TURN
R2, #100
R3, #225
R3, H2
R2, H1
COMMENTS
; Starting address
; Make an input
; Starting phase value
; Send value to port
; Check switch result
; Rotare right
; Call delay
; Write value to port
; Repeat
; Rotate left
;Call dealy
; Write value to port
;Repeat
Write a C program to send the message Good Morning, serially at 9600 baud rate, 8-bit, 1 stop bit.
12
12.1
1. Once the timer is on, TI is reset(=0). When the stop bit is transferred, 8051 rises the TI flag is set,
indicating that the last character was transmitted and ready to transfer next character.
ABHISHEK V BHAT
12 of 25
1MS12EC001
Microcontroller Assignment-2
8051
2. By monitoring the TI flag, we make sure that we are not overloading the SBUF register. If we write
another byte into the SBUF register before TI is raised, the untransmitted portion of the previous byte
will be lost.
3. When 8051 finishes transferring a byte, it raises the TI flag to indicate it is ready for the next character.
After SBUF is loaded with a new byte ,TI flag is forced to zero by CLR TI to transmit the new byte.
4. By checking the TI flag bit, we know whether or not the 8051 is ready to transfer another byte.
5. TI flag is raised by 8051 when it finishes the transfer of data, whereas it must be cleared by programmer.
6. The TI flag bit can be checked by the instruction JNB TI, . . . or by using an interrupt.
12.2
Importance of RI flag
1. The 8-bit character is received one bit at time. When the last bit is received, a byte is formed and placed
in SBUF.
2. When receiving the stop bit the 8051 makes RI = 1,indicating that an entire character byte has been
received and must be picked up before it gets overwritten by an incoming character.
3. By checking the RI flag bit when it is raised, we know that a character has been received and is sitting in
the SBUF register
4. RI flag bit is raised by 8051 when it finish receive data. It must be cleared by the programmer with
instruction CLR RI.
5. The RI flag bit can be checked by the instruction JNB RI, xx or by using an interrupt.
ABHISHEK V BHAT
13 of 25
1MS12EC001
Microcontroller Assignment-2
MSP430
MSP430
Contents
1 Draw the pin-out of MSP4300F2013 and describe the function of each of the 14 pins.
15
1.1 pin-out of MSP4300F2013 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.2 Functions of each pins of MSP4300F2013 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2 Draw the functional block diagram of the MSP430F2013 and explain its main feature.
16
2.1 Functional block diagram of the MSP430F2013 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.2 Main features of MSP430F2013 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3 Draw the Memory map of MSP430F2013 and briefly describe each region
17
3.1 Memory Map of MSP430F2013 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2 Description of each region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4 Explain with examples the following 4 addressing modes of MSP430:
(i) Register mode
(ii) Indexed mode
(iii) Indirect register mode
(iv) Indirect autoincrement register mode
4.1 Register mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.2 Indexed Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.3 Indirect Register Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4 Indirect autoincrement register mode . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
18
18
19
19
20
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
20
20
20
20
21
21
21
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
6 Write the delay subroutine with R4 and R12 as inner and outer loop counters respectively 21
7 Explain the following
(i) Active Mode
(ii) LPM0
(iii) LPM3
(iv) LPM4
7.1 Active Mode . . .
7.2 LPM0 . . . . . . .
7.3 LPM3 . . . . . . .
7.4 LPM4 . . . . . . .
modes of MSP430:
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
21
22
22
22
22
8 Many times it is better to return from a low power mode to the main function. Explain
with examples.
22
9 Explain the need for a watchdog timer. Explain the lower byte
9.1 Need for watchdog . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.2 Lower Byte of WDTCTL register . . . . . . . . . . . . . . . . . . .
9.2.1 functions of Lower byte of WDTCTL register . . . . . . . .
ABHISHEK V BHAT
14 of 25
of WDTCTL
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
register.
23
. . . . . . . . 23
. . . . . . . . 23
. . . . . . . . 24
1MS12EC001
Microcontroller Assignment-2
MSP430
24
1.1
pin-out of MSP4300F2013
V
P1.0/TACLK/ACLK/A01
P1.1/TA0/A02/A41
P1.2/TA1/A11/A42
P1.3/VREF/A12
P1.4/SMCLK/A21/TCK
P1.5/TA0/A22/SCLK/TMS
1.2
14
13
12
11
10
9
8
1
2
3
4
5
6
7
V
XIN/P2.6/TA1
XOUT/P2.7
TEST/SBWTCK
RST/NMI/SBWTDIO
P1.7/A32/SDI/SDA/TDO/TDI
P1.6/TA1/A31/SDO
/SCL/TDI/TCLK
1. VCC and VSS are the supply voltage and ground for the whole device (the analog and digital supplies are
separate in the 16-pin package).
2. P1.0 to P1.7, P2.6, and P2.7 are for digital input and output, grouped into ports P1 and P2.
3. TACLK, TA0, and TA1 are associated with Timer A ; TACLK can be used as the clock input to the
timer, while TA0 and TA1 can be either inputs or outputs. These can be used on several pins because of
the importance of the timer.
4. A0, A0+, and so on, up to A4, are inputs to the analog-to-digital converter. It has four differential
channels, each of which has negative and positive inputs. VREF is the reference voltage for the converter.
5. ACLK and SMCLK are outputs for the microcontrollers clock signals. These can be used to supply a
clock to external components or for diagnostic purposes.
6. SCLK, SD0, and SCL are used for the universal serial interface, which communicates with external devices
using the serial peripheral interface (SPI) or inter-integrated circuit (I2 C) bus.
7. XIN and XOUT are the connections for a crystal, which can be used to provide an accurate, stable clock
frequency.
8. RST is an active low reset signal. Active low means that it remains high near VCC for normal operation
and is brought low near VSS to reset the chip. Alternative notations to show the active low nature are
RST and /RST.
ABHISHEK V BHAT
15 of 25
1MS12EC001
Microcontroller Assignment-2
MSP430
9. NMI is the non-maskable interrupt input, which allows an external signal to interrupt the normal operation
of the program.
10. TCK, TMS, TCLK, TDI, TDO, and TEST form the full JTAG interface, used to program and debug the
device.
11. SBWTDIO and SBWTCK provide the Spy-Bi-Wire interface, an alternative to the usual JTAG connection
that saves pins.
Draw the functional block diagram of the MSP430F2013 and explain its main feature.
2.1
2.2
1. On the left it has CPU and its supporting hardware, including the clock generator. The emulation, JTAG
interface and Spy-Bi-Wire are used to communicate with a desktop computer when downloading a program
and for debugging.
2. The main blocks are linked by the memory address bus (MAB) and memory data bus (MDB).
ABHISHEK V BHAT
16 of 25
1MS12EC001
Microcontroller Assignment-2
MSP430
3. These devices have flash memory, 1KB in the F2003 or 2KB in the F2013, and 128 bytes of RAM.
4. Six blocks are shown for peripheral functions. All MSP430s include input/output ports, Timer A, and a
watchdog timer. The universal serial interface (USI) and sigmadelta analog-to-digital converter (SD16 A)
are particular features of this device.
5. The brownout protection comes into action if the supply voltage drops to a dangerous level. Most devices
include this.
6. There are ground and power supply connections. Ground is labeled VSS and is taken to define 0V. The
supply connection is VCC . The standard for logic was VCC =+5V but most devices now work from lower
voltages and a range of 1.83.6V is specified for the F2013. The performance of the device depends on VCC .
For example, it is unable to program the flash memory if VCC < 2.2V and the maximum clock frequency
of 16MHz is available only if VCC 3.3V.
3.1
Address
0xFFFF
0xFFC0
0xFFBF
0xF800
0xF7FF
0x1100
0x10FF
0x1000
0x0FFF
0x0C00
0x0BFF
0x0280
0x027F
0x0200
0x01FF
0x0100
0x00FF
0x0100
0x000F
0x0000
ABHISHEK V BHAT
Type of memory
interrupt and reset
vector table
ash code memory
(lower boundary varies)
ash
informa on memory
bootstrap loader
(not in F20xx)
RAM
(upper boundary varies)
peripheral registers
with word access
peripheral registers
with byte access
special func on registers
(byte access)
17 of 25
1MS12EC001
Microcontroller Assignment-2
3.2
MSP430
4.1
Register mode
ABHISHEK V BHAT
18 of 25
1MS12EC001
Microcontroller Assignment-2
MSP430
3. It is also the fastest mode and this instruction takes only 1 cycle.
EX: mov.w R5, R6 ; move (copy) word from R5 to R6
4. Any of the 16 registers can be used for either source or destination but there are some special cases:
(a) The PC is incremented by 2 while the instruction is being fetched, before it is used as a source.
(b) The constant generator CG2 reads 0 as a source.
(c) Both PC and SP must be even because they address only words, so the lsb is discarded if they are
used as the destination.
(d) SR can be used as a source and destination in almost the usual way although there are some details
about the behaviour of individual bits.
5. For byte instructions,
(a) Operands are taken from the lower byte; the upper byte is not affected.
(b) The result is written to the lower byte of the register and the upper byte is cleared. The upper byte
of a register in the CPU cannot be used as a source.
4.2
Indexed Mode
4.3
1. It is available only for the source and is representd by the symbol @ in front of a register with a + sign
after it, such as @R5+.
2. It uses the value in R5 as a pointer and automatically increments it afterward by 1 if a byte has been
fetched or by 2 for a word. If R5 = 4 then the instruction:
mov.w @R5+,R6 ; A word is loaded from address 4 into R6 and the value in R5 is incremented to 6
because a word (2 bytes) was fetched.
3. This mode cannot be used for the destination.An important feature of the addressing modes is that all
operations on the first address are fully completed before the second address is evaluated.
ABHISHEK V BHAT
19 of 25
1MS12EC001
Microcontroller Assignment-2
4.4
MSP430
5.1
5.2
5.2.1
ABHISHEK V BHAT
20 of 25
1MS12EC001
Microcontroller Assignment-2
MSP430
1. Available in all devices. It is usually used with a low-frequency watch crystal (32 KHz) but can also run
with a high-frequency crystal (typically a few MHz) in most devices.
2. An external clock signal can be used instead of a crystal if it is important to synchronize the MSP430
with other devices in the system.
5.2.2
5.2.3
5.2.4
Write the delay subroutine with R4 and R12 as inner and outer
loop counters respectively
LoopTest:
MNEMONICS
push.w
jmp
mov.w
dec.w
OPERAND
R4
LoopTest
#DELAYLOOPS, R4
R4
jnz
dec.w
cmp.w
jnz
pop.w
ret
DelayLoop
R12
#0, R12
OuterLoop
R4
COMMENTS
; Stack R4: will be overwritten
; Start with test in case R12 = 0
; Initialize loop counter
; [clock cycles in brackets].Decrement loop
counter [1]
; Repeat loop if not zero [2]
; Decrement number of 0.1s delays
; Finished number of 0.1s delays?
; No: go around delay loop again
; Yes: restore R4 before returning
ABHISHEK V BHAT
21 of 25
1MS12EC001
Microcontroller Assignment-2
7.1
MSP430
Active Mode
1. CPU, all clocks, and enabled modules are active, I300A. The MSP430 starts up in this mode, which
must be used when the CPU is required.
2. Interrupt automatically switches the device to active mode. The current can be reduced by running the
MSP430 at the lowest supply voltage consistent with the frequency of MCLK; VCC can be lowered to 1.8V
for fDCO = 1MHz, giving I200A.
7.2
LPM0
1. CPU and MCLK are disabled, SMCLK and ACLK remain active, I85A.
2. This is used when the CPU is not required but some modules require a fast clock from SMCLK and the
DCO.
7.3
LPM3
1. CPU, MCLK, SMCLK, and DCO are disabled; only ACLK remains active; I 1A.
2. This is the standard low-power mode when the device must wake itself at regular intervals and therefore
needs a (slow) clock.
3. It is required if the MSP430 must maintain a real-time clock. The current can be reduced to about 0.5A
by using the VLO instead of an external crystal in a MSP430F2xx if fACLK need not be accurate.
7.4
LPM4
P2OUT^= LED1|LED2;
// Loop forever
// Enter low power mode LPM3
// Wait here , pace loop until timer expire
//and ISR restores Active Mode
// Toggle LEDs
ABHISHEK V BHAT
22 of 25
1MS12EC001
Microcontroller Assignment-2
MSP430
3. The main function is now like the paced loop of Program butasm1.s43 with single loop in assembly
language to light LED1 when button B1 is pressed, except that the processor goes to sleep and waits to be
awakened by an interrupt from the timer instead of polling the overflow flag. In fact low power mode 3()
behaves just like a simple delay function.
4. The ISR is trivial and contains only one line for the intrinsic function to clear the stacked low-power mode.
5. The more general function bic SR register on exit() can be used to clear selected bits in SR if finer
control is required. It is also called BIC SR IRQ().
6. Assembly language requires a mildly tricky line of assembly language to clear the bits set for the low-power
mode. SP(stack pointer) points to the most recently added word, which is the pushed value of SR. The
simplest way to address this would be @SP but this is not permitted for a destination so the indexed
mode is used with an offset of 0.
Explain the need for a watchdog timer. Explain the lower byte of
WDTCTL register.
9.1
1. The main purpose of the watchdog timer is to protect the system against failure of the software(malfunction),
such as the program becoming trapped in an unintended, infinite loop.
2. The watchdog counts up and resets the MSP430 when it reaches its limit. The code must therefore keep
clearing the counter before the limit is reached to prevent a reset.
3. It can instead be used as an interval timer if this protection is not needed.
777
WDTHOLD
rw(0)
9.2
WDTNMIES
WDTNMI
WDTTMSEL
rw(0)
rw(0)
rw(0)
WDTCNTCL
WDTSSEL
r0(w)
rw(0)
WDTISx
rw(0)
rw(0)
1. The operation of the watchdog is controlled by the 16-bit register WDTCTL. It is guarded against accidental writes by requiring the password WDTPW = 0x5A in the upper byte.
ABHISHEK V BHAT
23 of 25
1MS12EC001
Microcontroller Assignment-2
MSP430
2. A reset will occur if a value with an incorrect password is written to WDTCTL. This can be done
deliberately if you need to reset the chip from software. Reading WDTCTL returns 0x69 in the upper
byte, so reading WDTCTL and writing the value back violates the password and causes a reset.
3. The lower byte of WDTCTL contains the bits that control the operation of the watchdog timer.
4. The RST/NMI pin is also configured using this register. Most bits are reset to 0 after a power-on reset
(POR) but are unaffected by a power-up clear (PUC). This distinction is important in handling resets
caused by the watchdog.
5. The exception is the WDTCNTCL bit, labeled r0(w). This means that the bit always reads as 0 but a 1
can be written to stimulate some action, clearing the counter.
9.2.1
(a) The watchdog counter is a 16-bit register WDTCNT. It is clocked from either SMCLK (default) or
ACLK, according to the WDTSSEL bit.
(b) The reset output can be selected from bits 6, 9, 13, or 15 of the counter. Thus the period is 26 = 64,
512, 8192, or 32,768 (default) times the period of the clock. This is controlled by the WDTISx bits
in WDTCTL. The intervals are roughly 2, 16, 250, and 1000 ms if the watchdog runs from ACLK at
32 KHz.
(c) The watchdog is always active after the MSP430 has been reset. By default the clock is SMCLK,
which is in turn derived from the DCO at about 1 MHz. The default period of the watchdog is
the maximum value of 32,768 counts, which is therefore around 32 ms. Watchdog must be cleared,
stoped, or reconfigured before this time has elapsed.
(d) If the watchdog is left running, the counter must be repeatedly cleared to prevent it counting up as
far as its limit. This is done by setting the WDTCNTCL bit in WDTCTL. The task is often called
petting, feeding, or kicking the dog. The bit automatically clears again after WDTCNT has been
reset.
10
ABHISHEK V BHAT
24 of 25
1MS12EC001
Microcontroller Assignment-2
MSP430
INCHx
A0
A1
VeREF+
analog
inputs
external references
VeREFVSS
ADC10SHTx
A6
A7
VREF+
VR-
VR+
REF2_5V
voltage
reference
VCC
SREF,1
SREF2
Sample
and hold
ADC10SR
buffer
REFON
ADC10DIVx
ADC10OSC
ACLK
divider
/1../8
MCLK
SMCLK
ADC10CLK
VCC
A10
A11
Vmid
VREF+
ADC10MEM
Start conversion
Vtemp
ADC10IFG
ENC
Temperature
ADC10SC
OUT0
OUT1
OUT2
ABHISHEK V BHAT
25 of 25
1MS12EC001