You are on page 1of 25

MICROCONTROLLER ASSIGNMENT-2

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

3 Write an 8051 C Program using interrupts to do the following:


(i) Recieve the data serially and send it to P0
(ii) Read port P1, transmit data serially and give a copy of P2.
(iii) Generate a square wave of 5KHz frequency on P0.1
(iv) Assume that XTAL=11.0592MHz, set the baud rate at 4800.

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 .

LCD panel and write an 8051 ALP display message


. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

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

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.
8051
P1.7

SWITCH

500 Hz or
750 Hz
depending
on SW

P1.2

Calculations to find count value(n)


Assuming XTAL = 11.0592MHz. Count value for f=500Hz
) = (216 n) Tc. Where Tc = 1.085 s
delay = ( timeperiod
2
1103
16
n = 2 1.085106
n = (64614)10 =(FC67)16 = FC67H
count value for f=750Hz is
delay = ( timeperiod
) = (216 n) Tc , where Tc = 1.085s
2
3
110
n = 216 1.08510
6
n=(64922)10 = (F C67)16 = FD9AH

C Program to generate frequencies at port P1.7


#include <reg51.h>
sbit mybit = P1^5;
sbit SW = P1^7;
void TOM1DELAY(unsigned char)
void main(void)
{
SW = 1;
while(1)
{
mybit = ~mybit;
if(SW==0)
TOM1DELAY(0);
else
TOM1DELAY(1);
}
}

ABHISHEK V BHAT

// make P1.7 an input

// toggle P1.5

3 of 25

1MS12EC001

Microcontroller Assignment-2

void TOM1DELAY(unsigned char c)


{
TMOD = 0x11;
if(c==0)
{
TL0 = 0x67;
TH0 = 0xFC;
}
else
{
TL0 = 0x9A;
TH0 = 0xFD;
}
TR0 = 1;
while(TF0==0);
TR0 = 0;
TF0=0;
}

8051

// Count = FC67H

// Count = FD9AH

//
//
//
//

start the timer


waits till timer overflow
stop the timer
reset TF flag

List the advantages of serial communication over parallel communication


1. Serial communication requires fewer interconnecting cables and hence occupies less space.
2. Cross talk is less of an issue, because there are fewer conductors compared to that of parallel communication cables.
3. Many IC s and peripheral devices have serial interfaces.
4. No need of (SERDES).
5. Even in shorter distance communications, serial computer buses are becoming more common because of a
tipping point where the disadvantages of parallel buses (clock skew, interconnect density) outweigh their
advantage of simplicity (no need for serializer and deserializer).
6. Serial communication requires only one line for the data, a second line for ground and possibly a third
line for the clock whereas parallel communication requires at least eight separate lines (in an 8-bit system)
and in most cases extra lines to synchronize the data transfer. Therefore serial communication requires
less physical wires, it is more suitable for transmitting data over longer distances.
7. Since serial communication uses less number of wires than that for parallel communication it is cheap.

Write an 8051 C Program using interrupts to do the following:


(i) Recieve the data serially and send it to P0
(ii) Read port P1, transmit data serially and give a copy of P2.
(iii) Generate a square wave of 5KHz frequency on P0.1
(iv) Assume that XTAL=11.0592MHz, set the baud rate at 4800.

Calculations to count value(n)


Assuming XTAL = 11.0592MHz. Count value for f=5kHz is
delay = ( timeperiod
) = (28 n)Tc , where Tc = 1.085s
2
100106
8
n = 2 1.085106 n=(164)10 =(A4)16 = A4H
ABHISHEK V BHAT

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

// put value on pins


// clear interrupt

// make P1 an input port


// select timer 1 mode 0, timer 0 mode 0
// 4800 baud rate
//
//
//
//

5 KHz has T = 200 uSec


Enable interrupt
Start the timer 1
Start the timer 0

// Read value from the pins


// put value in buffer
// write value to pins

5 of 25

1MS12EC001

Microcontroller Assignment-2

8051

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.

Assuming XTAL = 11.0592MHz.


28800
baud rate = 256T
H1
28800
TH1=256 - baud rate TH1 = 256-3 = 25310 = FDH.

C program to send above message to serial port continuously


#include < reg51.h>
void main(void)
{
unsigned char z;
unsigned char string1[]= "The Earth is Beautiful";
TMOD = 0x20;
// Use Timer 1, 8-Bit auto-reload
TH1 = 0xFD;
//9600 Baud rate
SCON = 0x50;
TR1 = 1;
//Start the Timer (Timer 1)
while(1)
{
for(z=0;z<22;z++)
//Write the name
{
SBUF = string1[z];
//Place value in buffer
while(TI==0);
//Wait for transmit
TI=0;
}
}
}

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

To stepper motor supply


ULN2003

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

8051 Connection to Stepper Motor

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

C program to rotate stepper motor clock/anticlowise.

# 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

// Stepper Motor rotates clockwise

// Stepper Motor rotates anticlockwise

void MSDelay(unsigned int value)


{
unsigned int x,y ;
for (x=0 ; x<1275; x++)
for (y=0 ;y<value;y++)
}

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.

C program for the above question


#inlcude < reg51.h>
void MSDelay(unsigned int);
void main()
{
P0=0x55;
P2=0x55;
while(1)
{
P0=~P0;
P2=~P2;
MSDelay(250);
}
}

// toggle P0
// toggle P2

void MSDelay (unsigned int itime)


{
unsigned int i,j;
for(i=0; i<itime; i++)
for(j=0; j<1275; j++)
}

Explain the resisters and pins of an LCD panel and write an 8051
ALP display message MSRIT on the LCD panel.

7.1

Pin Description for LCD


Pin
1
2
3
4
5
6
7
8
9
10
11
12
13
14

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

Register inside the LCD

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

displayed on the LCD.


3. R/W(read/write) input allows the user to write information to the LCD or read information from it. R/W
= 1 when reading; R/W = 0 when writing.
4. The enable pin (E) is used by the LCD to latch information presented to its data pins.

7.3

ALP to display message MSRIT


LABEL

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,

; Long delay for fast CPU

# 250
# 255
HERE
HERE2

300H
38H,0EH,01,06,84H,0
HELLO,0

9 of 25

COMMENT

; call command subroutine


; give LCD some time

; call data subroutine


; give LCD some time

; commands and null


; data and null

1MS12EC001

Microcontroller Assignment-2

8051

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
8051
44H
P1.0

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

C program for the above question


#include <reg51.h>
void main(void)

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

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.

+5

+5
DS89C4x0

4.7k

4.7k

4.7k

4.7k

To stepper motor supply


ULN2003

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

8051 Connection to Stepper Motor

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

ALP to rotate stepper motor clock/anticlowise

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.

Assuming XTAL = 11.0592MHz.


28800
baud rate = 256T
H1
28800
TH1=256 - baud rate TH1 = 256 - 3 = 25310 = F DH.

C program to send above message to serially


#include < reg51.h>
void main(void)
{
unsigned char z;
unsigned char string1[]= "Good Morning";
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;
for(z=0;z<12;z++)
{
SBUF = string1[z];
while(TI==0);
TI=0;
}

// Use Timer 1, 8-Bit auto-reload


//9600 Baud rate
//Start the Timer (Timer 1)
//Write the name
//Place value in buffer
//Wait for transmit

12
12.1

Explain the importance of TI and RI flag


Importance of TI flag

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

5 Draw the Simplified block diagram of the clock module of


MSP430F2xx family and explain the 4 clock sources available
5.1 Simplified diagram block diagram of the clock modeule . . . . . .
5.2 Clock sources available in MSP430F2xx . . . . . . . . . . . . . .
5.2.1 Low- or high-frequency crystal oscillator, LFXT1: . . . .
5.2.2 High-frequency crystal oscillator, XT2: . . . . . . . . . . .
5.2.3 Internal very low-power, low-frequency oscillator, VLO: .
5.2.4 Digitally controlled oscillator, DCO: . . . . . . . . . . . .

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

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

10 Draw the simplified block diagrams of ADC10 and SD16 A.

24

Draw the pin-out of MSP4300F2013 and describe the function of


each of the 14 pins.

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

Functions of each pins of MSP4300F2013

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

Functional block diagram of the MSP430F2013

2.2

Main features of MSP430F2013

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

Draw the Memory map of MSP430F2013 and briefly describe each


region
Memory Map of MSP430F2013

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

Description of each region

1. Special function registers:


It is concerned with enabling functions of some modules and enabling and signalling interrupts from
peripherals.
2. Peripheral registers with byte access and peripheral registers with word access:
(a) It Provides the main communication between the CPU and peripherals.
(b) Sometimes it must be accessed as words and others as bytes. They are grouped in this way to avoid
wasting addresses.
(c) If the bytes and words were mixed, numerous unused bytes would be needed to ensure that the words
were correctly aligned on even addresses.
3. Random access memory:
It is used for variables. This always starts at address 0x0200 and the upper limit depends on the size of
the RAM. The MSP430F2013 has 128 B.
4. Bootstrap loader:
(a) Contains a program to communicate using a standard serial protocol, often with the COM port of a
PC.
(b) This can be used to program the chip. But because of other improved communication, it was omitted
to improve security.
5. Information memory:
(a) A 256B block of flash memory that is intended for storage of nonvolatile data.
(b) It might include serial numbers to identify equipment an address for a network, for instance - or
variables that should be retained even when power is removed.
(c) For example, a printer might remember the settings from when it was last used and keep a count of
the total number of pages printed.
6. Code memory:
Holds the program, including the executable code itself and any constant data. The F2013 has 2KB but
the F2003 only 1KB.
7. Interrupt and reset vectors:
Used to handle exceptions, when normal operation of the processor is interrupted or when the device is
reset. This table was smaller and started at 0xFFE0 in earlier devices.

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

1. This uses one or two of the registers in the CPU.


2. It is the most straightforward addressing mode and is available for both source and destination.

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

1. It looks similar to an element of an array in C.


2. The address is formed by adding a constant base address to the contents of a CPU register; the value in
the register is not changed.
3. Indexed addressing can be used for both source and destination. EX: If R5=4 then the instruction
mov.b 3(R5), R6 ; load byte from address 3+(R5)=7 into R6
Here the address of the source is computed as 3+(R5) = 3+4 = 7. Thus a byte is loaded from address 7
into R6. The value in R5 is unchanged.
4. The base is the address of the first element of an array or table and the register holds the index. Thus
the indexed address Message(R5) is equivalent to the element Message[i] of an array of characters in C,
assuming that R5 is used for the index and R5=i.

4.3

Indirect Register Mode

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

Indirect autoincrement register mode

1. It(autoincrement addressing mode) uses the program counter PC.


For EX: mov.w @PC+,R6 ; load immediate word into R6.
2. The PC is automatically incremented after the instruction is fetched and therefore points to the following
word. The instruction loads this word into R6 and increments PC to point to the next word, which in
this case is the next instruction.
3. The word that followed the original instruction has been loaded into R6.
4. It is applicable only for the source of an instruction because it is a type of autoincrement addressing.

Draw the Simplified block diagram of the clock module of


MSP430F2xx family and explain the 4 clock sources available

5.1

Simplified diagram block diagram of the clock modeule

5.2

Clock sources available in MSP430F2xx

5.2.1

Low- or high-frequency crystal oscillator, LFXT1:

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

High-frequency crystal oscillator, XT2:

1. It is similar to LFXT1 except that it is restricted to high frequencies.


2. It is available in only a few devices and LFXT1 (or VLO) is used instead if XT2 is missing.

5.2.3

Internal very low-power, low-frequency oscillator, VLO:

1. Available in only the more recent MSP430F2xx devices.


2. It provides an alternative to LFXT1 when the accuracy of a crystal is not needed.

5.2.4

Digitally controlled oscillator, DCO:

1. Available in all devices and one of the highlights of the MSP430.


2. It is basically a highly controllable RC oscillator that starts in less than 1 s in newer devices.

Write the delay subroutine with R4 and R12 as inner and outer
loop counters respectively

// Subroutine to give delay of R12 *0.1s


// Parameter is passed in R12 and destroyed
//R4 used for loop counter , stacked and restored
LABEL
DelayTenths:
OuterLoop:
DelayLoop:

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

Explain the following modes of MSP430:


(i) Active Mode
(ii) LPM0
(iii) LPM3
(iv) LPM4

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

1. CPU and all clocks are disabled, I 0.1A.


2. The device can be wakened only by an external signal. This is also called RAM retention mode.

Many times it is better to return from a low power mode to the


main function. Explain with examples.
1. It is not appropriate to carry out all actions in an ISR and it is better to return to the main function in
active mode. i.e returning to the function that put the device into the low-power mode. Hence must clear
all the low-power bits in the saved value of SR on the stack before it is restored at the end of the interrupt
service routine.
2. EX: Part of program timainC1.c to toggle LEDs using interrupts from Timer A. The device enters lowpower mode 0, is awakened by an interrupt and returns to the main function to toggle the LED.
for (;;)
{
__low_power_mode_3 ();

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

// Interrupt service routine for Timer A channel 0


// Processor remains in Active Mode after ISR
#pragma vector = TIMERA0_VECTOR
__interrupt void TA0_ISR (void)
{
__low_power_mode_off_on_exit(); // Restore Active Mode on return
}

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

Need for watchdog

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)

Lower Byte of WDTCTL register

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

functions of Lower byte of WDTCTL register

(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

Draw the simplified block diagrams of ADC10 and SD16 A.

ABHISHEK V BHAT

24 of 25

1MS12EC001

Microcontroller Assignment-2

MSP430

INCHx

A0
A1

VeREF+

analog
inputs

external references

VeREFVSS

Simplified block diagrams of ADC10

ADC10SHTx

A6
A7

VREF+

VR-

VR+

10-bit SAR core

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

Simplified block diagram of SD16A

ABHISHEK V BHAT

25 of 25

1MS12EC001

You might also like