microcontroller
DESCRIPTION
General questions related to microcontrollerTRANSCRIPT
MICROCONTROLLER ASSIGNMENT-2
USING LATEX
ABHISHEK V BHAT
1MS12EC001
SECTION A
QUESTIONS RELATED TO 8051
November 6, 2014
1
Microcontroller Assignment-2 8051
Contents
1 A Switch is connected to the pin P1.2. Write an 8051 C program to monitor the switchand 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
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
4 Write a C program to send the message ”The Earth is Beautiful”, to the serial port con-tinuously. 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. Writean 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. 65.1 8051 Connection to Stepper Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75.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 LCD panel and write an 8051 ALP display message”MSRIT” on the LCD panel. 87.1 Pin Description for LCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87.2 Register inside the LCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87.3 ALP to display message ”MSRIT” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
8 A switch (SW) is connected to P2.0 port pin. Write a C program to send out the value44H 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 anddisplay 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. Writean 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. 1110.1 8051 Connection to Stepper Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1110.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 1212.1 Importance of TI flag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1212.2 Importance of RI flag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
ABHISHEK V BHAT 2 of 25 1MS12EC001
Microcontroller Assignment-2 8051
1 A Switch is connected to the pin P1.2. Write an 8051 C programto monitor the switch and create the following frequencies on thepin P1.7.(i) When SW = 0, 500Hz(ii) When SW = 1, 750Hz. Use timer 0, mode 1 for both of them.
SWITCH
8051
500 Hz or 750 Hz depending on SW
P1.7
P1.2
Calculations to find count value(n)
Assuming XTAL = 11.0592MHz. Count value for f=500Hzdelay = ( timeperiod
2 ) = (216 − n)× Tc. Where Tc = 1.085µ s
n = 216 − 1×10−3
1.085×10−6
n = (64614)10 =(FC67)16 = FC67H
count value for f=750Hz isdelay = ( timeperiod
2 ) = (216 − n)× Tc , where Tc = 1.085µs
n = 216 − 1×10−3
1.085×10−6
n=(64922)10 = (FC67)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; // make P1.7 an input
while(1)
{
mybit = ~mybit; // toggle P1.5
if(SW==0)
TOM1DELAY(0);
else
TOM1DELAY(1);
}
}
ABHISHEK V BHAT 3 of 25 1MS12EC001
Microcontroller Assignment-2 8051
void TOM1DELAY(unsigned char c)
{
TMOD = 0x11;
if(c==0)
{
TL0 = 0x67; // Count = FC67H
TH0 = 0xFC;
}
else
{
TL0 = 0x9A; // Count = FD9AH
TH0 = 0xFD;
}
TR0 = 1; // start the timer
while(TF0==0); // waits till timer overflow
TR0 = 0; // stop the timer
TF0=0; // reset TF flag
}
2 List the advantages of serial communication over parallel commu-nication
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 commu-nication 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 atipping point where the disadvantages of parallel buses (clock skew, interconnect density) outweigh theiradvantage 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 thirdline 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 requiresless 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.
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.
Calculations to count value(n)
Assuming XTAL = 11.0592MHz. Count value for f=5kHz isdelay = ( timeperiod
2 ) = (28 − n)×Tc , where Tc = 1.085µs
n = 28 − 100×10−6
1.085×10−6⇒ n=(164)10 =(A4)16 = A4H
ABHISHEK V BHAT 4 of 25 1MS12EC001
Microcontroller Assignment-2 8051
A9
P1.2
P1.7 P3.0
TXD
RXD
8051
P1
5kHz
P0.1 P3.0
P3.1
P2
88
C program
#include < reg51.h>
sbit WAVE = P0^1;
void timer0() interrupt 1
{
WAVE = ~WAVE;
}
void serial0() interrupt 4
{
if (TI == 1)
{
TI = 0; // Clear Interrupt
}
else
{
P0 = SBUF; // put value on pins
RI = 0; // clear interrupt
}
}
void main()
{
unsigned char x;
P1 = 0xFF; // make P1 an input port
TMOD = 0x22; // select timer 1 mode 0, timer 0 mode 0
TH1 = 0xF6; // 4800 baud rate
SCON = 0x50;
TH0 = 0xA4; // 5 KHz has T = 200 uSec
IE = 0x92; // Enable interrupt
TR1 = 1; // Start the timer 1
TR0 = 1; // Start the timer 0
while(1)
{
x = P1; // Read value from the pins
SBUF = x; // put value in buffer
P2 = x; // write value to pins
}
}
ABHISHEK V BHAT 5 of 25 1MS12EC001
Microcontroller Assignment-2 8051
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.
Assuming XTAL = 11.0592MHz.baud rate = 28800
256−TH1
TH1=256 - 28800baud 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;
}
}
}
5 Describe the 8051 connection to stepper motor. A switch is con-nected to pin P2.7. Write an C program to monitor the status ofSW and perform the following:(i) If SW=0, the stepper motor moves clockwise.(ii) If SW=0, the stepper motor moves clockwise.
+5
4.7k ULN2003
4.7k
P1.0
P1.1
P1.2
P1.3
DS89C4x0
+5
4.7k 4.7k
+5
9
8
To stepper motor supply
Unipolar Stepper motor
One power supply is used for the motor and the ULN2003 and the other for the 8051
ABHISHEK V BHAT 6 of 25 1MS12EC001
Microcontroller Assignment-2 8051
5.1 8051 Connection to Stepper Motor
1. An ohmmeter is used to measure the resistance of the leads. This should identify which COM leads areconnected 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 8051lacks sufficient current to drive the stepper motor windings, driver such as the ULN2003 is used to energizethe 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; // SW = Switch
void main ( )
{
SW =1;
while (1)
{
if( SW==0) // Stepper Motor rotates clockwise
{
P1 = 0x66;
MSDelay(100);
P1 = 0xCC;
MSDelay(100);
P1 = 0x99 ;
MSDelay(100);
P1 = 0X33;
MSDelay(100);
}
else // Stepper Motor rotates anticlockwise
{
P1 = 0x66;
MSDelay(100);
P1 = 0X33;
MSDelay(100);
P1 = 0x99;
MSDelay(100);
P1 = 0xCC;
MSDelay(100);
}
}
}
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
6 Write the C program to toggle all the bits of P0 and P2 continu-ously 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; // toggle P0
P2=~P2; // toggle P2
MSDelay(250);
}
}
void MSDelay (unsigned int itime)
{
unsigned int i,j;
for(i=0; i<itime; i++)
for(j=0; j<1275; j++)
}
7 Explain the resisters and pins of an LCD panel and write an 8051ALP display message “MSRIT” on the LCD panel.
7.1 Pin Description for LCD
Pin Symbol I/O Description
1 V - Ground
2 V - +5V Power supply
3 V - Power supply to control contrast
4 RS I RS=0 to select command register,RS =1 to select data register
5 R/W I R/W = 0 for write, R/W = 1 for read
6 E I/O Enable
7 DB0 I/O The 8-bit data bus
8 DB1 I/O The 8-bit data bus
9 DB2 I/O The 8-bit data bus
10 DB3 I/O The 8-bit data bus
11 DB4 I/O The 8-bit data bus
12 DB5 I/O The 8-bit data bus
13 DB6 I/O The 8-bit data bus
14 DB7 I/O The 8-bit data bus
7.2 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 cleardisplay, 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 MNEMONIC OPERAND COMMENTORG 0MOV DPTR, # MYCOM
LOC1: CLR AMOVC A, @A+DPTRACALL COMNWRT ; call command subroutineACALL DELAY ; give LCD some timeJZ SENDDATINC DPTRSJMP LOC1
SENDDAT: MOV DPTE, # MYDATALOC2: CLR A
MOVC A, @A+DPTRACALL DATAWRT ; call data subroutineACALL DELAY ; give LCD some timeINC DELAYJZ AGAINSJMP LOC2
AGAIN: SJMP AGAIN ; stay hereCOMNWRT: MOV P1, A ; send command to P1
CLR P2.0 ; RS = 0 for commandCLR P2.1 ; R/W = 0 for commandSETB P2.2 ; E = 1 for high pulseACALL DELAY ; give LCD some timeCLR P2.2 ; E = 0 for H-to-LRET
DATAWRT: MOV P1,A ; send data to P1SETB P2.0 ; RS = 1 for dataCLR P2.1 ; R/W = 0 for writeSETB P2.2 ; E = 1 for high pulseACALL DELAY ; give LCD some timeCLR P2.2 ; E = 0 for H-to-L pulseRET
DELAY: MOV R3, # 250 ; Long delay for fast CPUHERE2: MOV R4, # 255HERE: DJNZ R4, HERE
DJNZ R3, HERE2RETORG 300H
MYCOM: DB 38H,0EH,01,06,84H,0 ; commands and nullMYDATA: DB ”HELLO”,0 ; data and null
END
ABHISHEK V BHAT 9 of 25 1MS12EC001
Microcontroller Assignment-2 8051
8 A switch (SW) is connected to P2.0 port pin. Write a C programto 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
SWITCH
8051 44H
P1.0
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;
}
}
}
9 Write a C program to convert a given hex-data FDH into its equiv-alent 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 isconnected to pin P2.7. Write an ALP to monitor the status ofSW and perform the following:(i) If SW=0, the stepper motor moves clockwise.(i) If SW=0, the stepper motor moves clockwise.
+5
4.7k ULN2003
4.7k
P1.0
P1.1
P1.2
P1.3
DS89C4x0
+5
4.7k 4.7k
+5
9
8
To stepper motor supply
Unipolar Stepper motor
One power supply is used for the motor and the ULN2003 and the other for the 8051
10.1 8051 Connection to Stepper Motor
1. An ohmmeter is used to measure the resistance of the leads. This should identify which COM leads areconnected 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 8051lacks sufficient current to drive the stepper motor windings, driver such as the ULN2003 is used to energizethe 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 8051
10.2 ALP to rotate stepper motor clock/anticlowise
LABEL MNEMONIC OPERAND COMMENTSORG 0 ; Starting address
MAIN : SETB P2.7 ; Make an inputMOV A, #66H ; Starting phase valueMOV P1, A ; Send value to port
TURN : JNB P2.7, CW ; Check switch resultRR A ; Rotare rightACALL DELAY ; Call delayMOV P1, A ; Write value to portSJMP TURN ; Repeat
CW : RL A ; Rotate leftACALL DELAY ;Call dealyMOV P1, A ; Write value to portSJMP TURN ;Repeat
DELAY : MOV R2, #100H1 : MOV R3, #225H2 : DJNZ R3, H2
DJNZ R2, H1RETEND
11 Write a C program to send the message “Good Morning”, seri-ally at 9600 baud rate, 8-bit, 1 stop bit.
Assuming XTAL = 11.0592MHz.baud rate = 28800
256−TH1
TH1=256 - 28800baud rate ⇒ TH1 = 256 - 3 = 25310 = FDH.
C program to send above message to serially
#include < reg51.h>
void main(void)
{
unsigned char z;
unsigned char string1[]= "Good Morning";
TMOD = 0x20; // Use Timer 1, 8-Bit auto-reload
TH1 = 0xFD; //9600 Baud rate
SCON = 0x50;
TR1 = 1; //Start the Timer (Timer 1)
for(z=0;z<12;z++) //Write the name
{
SBUF = string1[z]; //Place value in buffer
while(TI==0); //Wait for transmit
TI=0;
}
}
12 Explain the importance of TI and RI flag
12.1 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 writeanother byte into the SBUF register before TI is raised, the untransmitted portion of the previous bytewill 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 placedin SBUF.
2. When receiving the stop bit the 8051 makes RI = 1,indicating that an entire character byte has beenreceived 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 inthe SBUF register
4. RI flag bit is raised by 8051 when it finish receive data. It must be cleared by the programmer withinstruction “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. 151.1 pin-out of MSP4300F2013 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151.2 Functions of each pins of MSP4300F2013 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2 Draw the functional block diagram of the MSP430F2013 and explain its main feature. 162.1 Functional block diagram of the MSP430F2013 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162.2 Main features of MSP430F2013 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3 Draw the Memory map of MSP430F2013 and briefly describe each region 173.1 Memory Map of MSP430F2013 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.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 184.1 Register mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184.2 Indexed Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194.3 Indirect Register Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194.4 Indirect autoincrement register mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5 Draw the Simplified block diagram of the clock module ofMSP430F2xx family and explain the 4 clock sources available 205.1 Simplified diagram block diagram of the clock modeule . . . . . . . . . . . . . . . . . . . . . . . . 205.2 Clock sources available in MSP430F2xx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5.2.1 Low- or high-frequency crystal oscillator, LFXT1: . . . . . . . . . . . . . . . . . . . . . . 205.2.2 High-frequency crystal oscillator, XT2: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215.2.3 Internal very low-power, low-frequency oscillator, VLO: . . . . . . . . . . . . . . . . . . . 215.2.4 Digitally controlled oscillator, DCO: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
6 Write the delay subroutine with R4 and R12 as inner and outer loop counters respectively 21
7 Explain the following modes of MSP430:(i) Active Mode(ii) LPM0(iii) LPM3(iv) LPM4 217.1 Active Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227.2 LPM0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227.3 LPM3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227.4 LPM4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
8 Many times it is better to return from a low power mode to the main function. Explainwith examples. 22
9 Explain the need for a watchdog timer. Explain the lower byte of WDTCTL register. 239.1 Need for watchdog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239.2 Lower Byte of WDTCTL register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
9.2.1 functions of Lower byte of WDTCTL register . . . . . . . . . . . . . . . . . . . . . . . . . 24
ABHISHEK V BHAT 14 of 25 1MS12EC001
Microcontroller Assignment-2 MSP430
10 Draw the simplified block diagrams of ADC10 and SD16 A. 24
1 Draw the pin-out of MSP4300F2013 and describe the function ofeach 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
123456
7
141312
111098
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.2 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 areseparate 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 thetimer, while TA0 and TA1 can be either inputs or outputs. These can be used on several pins because ofthe importance of the timer.
4. A0, A0+, and so on, up to A4±, are inputs to the analog-to-digital converter. It has four differentialchannels, 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 aclock to external components or for diagnostic purposes.
6. SCLK, SD0, and SCL are used for the universal serial interface, which communicates with external devicesusing the serial peripheral interface (SPI) or inter-integrated circuit (I2C) bus.
7. XIN and XOUT are the connections for a crystal, which can be used to provide an accurate, stable clockfrequency.
8. RST is an active low reset signal. Active low means that it remains high near VCC for normal operationand is brought low near VSS to reset the chip. Alternative notations to show the active low nature areRST 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 operationof the program.
10. TCK, TMS, TCLK, TDI, TDO, and TEST form the full JTAG interface, used to program and debug thedevice.
11. SBWTDIO and SBWTCK provide the Spy-Bi-Wire interface, an alternative to the usual JTAG connectionthat saves pins.
2 Draw the functional block diagram of the MSP430F2013 and ex-plain 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, JTAGinterface and Spy-Bi-Wire are used to communicate with a desktop computer when downloading a programand 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 awatchdog 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 devicesinclude this.
6. There are ground and power supply connections. Ground is labeled VSS and is taken to define 0V. Thesupply connection is VCC . The standard for logic was VCC =+5V but most devices now work from lowervoltages 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 frequencyof 16MHz is available only if VCC ≥ 3.3V.
3 Draw the Memory map of MSP430F2013 and briefly describe eachregion
3.1 Memory Map of MSP430F2013
interrupt and resetvector table
flash code memory(lower boundary varies)
flashinforma�on memory
bootstrap loader(not in F20xx)
RAM(upper boundary varies)
peripheral registerswith word access
peripheral registerswith byte access
special func�on registers(byte access)
0xFFFF0xFFC00xFFBF0xF8000xF7FF0x1100
0x10FF0x10000x0FFF0x0C000x0BFF0x02800x027F0x02000x01FF0x0100
0x00FF
0x000F0x0000
0x0100
Address Type of memory
ABHISHEK V BHAT 17 of 25 1MS12EC001
Microcontroller Assignment-2 MSP430
3.2 Description of each region
1. Special function registers:It is concerned with enabling functions of some modules and enabling and signalling interrupts fromperipherals.
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 avoidwasting addresses.
(c) If the bytes and words were mixed, numerous unused bytes would be needed to ensure that the wordswere 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 ofthe 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 aPC.
(b) This can be used to program the chip. But because of other improved communication, it was omittedto 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 - orvariables 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 ofthe total number of pages printed.
6. Code memory:Holds the program, including the executable code itself and any constant data. The F2013 has 2KB butthe F2003 only 1KB.
7. Interrupt and reset vectors:Used to handle exceptions, when normal operation of the processor is interrupted or when the device isreset. This table was smaller and started at 0xFFE0 in earlier devices.
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
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 areused as the destination.
(d) SR can be used as a source and destination in almost the usual way although there are some detailsabout 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 byteof 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 inthe register is not changed.
3. Indexed addressing can be used for both source and destination. EX: If R5=4 then the instructionmov.b 3(R5), R6 ; load byte from address 3+(R5)=7 into R6Here the address of the source is computed as 3+(R5) = 3+4 = 7. Thus a byte is loaded from address 7into 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. Thusthe 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 ’+’ signafter 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 beenfetched 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 6because a word (2 bytes) was fetched.
3. This mode cannot be used for the destination.An important feature of the addressing modes is that alloperations on the first address are fully completed before the second address is evaluated.
ABHISHEK V BHAT 19 of 25 1MS12EC001
Microcontroller Assignment-2 MSP430
4.4 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 followingword. The instruction loads this word into R6 and increments PC to point to the next word, which inthis 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.
5 Draw the Simplified block diagram of the clock module ofMSP430F2xx 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 runwith 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 MSP430with 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.
6 Write the delay subroutine with R4 and R12 as inner and outerloop 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 MNEMONICS OPERAND COMMENTSDelayTenths: push.w R4 ; Stack R4: will be overwritten
jmp LoopTest ; Start with test in case R12 = 0OuterLoop: mov.w #DELAYLOOPS, R4 ; Initialize loop counterDelayLoop: dec.w R4 ; [clock cycles in brackets].Decrement loop
counter [1]jnz DelayLoop ; Repeat loop if not zero [2]dec.w R12 ; Decrement number of 0.1s delays
LoopTest: cmp.w #0, R12 ; Finished number of 0.1s delays?jnz OuterLoop ; No: go around delay loop againpop.w R4 ; Yes: restore R4 before returningret
7 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 MSP430
7.1 Active Mode
1. CPU, all clocks, and enabled modules are active, I≈300µA. The MSP430 starts up in this mode, whichmust be used when the CPU is required.
2. Interrupt automatically switches the device to active mode. The current can be reduced by running theMSP430 at the lowest supply voltage consistent with the frequency of MCLK; VCC can be lowered to 1.8Vfor fDCO = 1MHz, giving I≈200µA.
7.2 LPM0
1. CPU and MCLK are disabled, SMCLK and ACLK remain active, I≈85µA.
2. This is used when the CPU is not required but some modules require a fast clock from SMCLK and theDCO.
7.3 LPM3
1. CPU, MCLK, SMCLK, and DCO are disabled; only ACLK remains active; I ≈ 1µA.
2. This is the standard low-power mode when the device must wake itself at regular intervals and thereforeneeds a (slow) clock.
3. It is required if the MSP430 must maintain a real-time clock. The current can be reduced to about 0.5µAby 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.1µA.
2. The device can be wakened only by an external signal. This is also called RAM retention mode.
8 Many times it is better to return from a low power mode to themain 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 inactive mode. i.e returning to the function that put the device into the low-power mode. Hence must clearall the low-power bits in the saved value of SR on the stack before it is restored at the end of the interruptservice routine.
2. EX: Part of program timainC1.c to toggle LEDs using interrupts from Timer A. The device enters low-power mode 0, is awakened by an interrupt and returns to the main function to toggle the LED.
for (;;) // Loop forever
{
__low_power_mode_3 (); // Enter low power mode LPM3
// Wait here , pace loop until timer expire
//and ISR restores Active Mode
P2OUT^= LED1|LED2; // 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 assemblylanguage to light LED1 when button B1 is pressed”, except that the processor goes to sleep and waits to beawakened 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 finercontrol 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-powermode. SP(stack pointer) points to the most recently added word, which is the pushed value of SR. Thesimplest way to address this would be @SP but this is not permitted for a destination so the indexedmode is used with an offset of 0.
9 Explain the need for a watchdog timer. Explain the lower byte ofWDTCTL 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 keepclearing 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.
77
WDT-HOLD
WDT-NMIES
WDT-SSEL
WDT-CNTCL
WDT-TMSEL
WDT-NMI
WDTISx
7 6 5 4 3 2 1 0
rw–(0) rw–(0) rw–(0) rw–(0) r0(w) rw–(0) rw–(0) rw–(0)
9.2 Lower Byte of WDTCTL register
1. The operation of the watchdog is controlled by the 16-bit register WDTCTL. It is guarded against acci-dental 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 donedeliberately if you need to reset the chip from software. Reading WDTCTL returns 0x69 in the upperbyte, 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 resetscaused by the watchdog.
5. The exception is the WDTCNTCL bit, labeled r0(w). This means that the bit always reads as 0 but a 1can 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) orACLK, 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 bitsin WDTCTL. The intervals are roughly 2, 16, 250, and 1000 ms if the watchdog runs from ACLK at32 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 isthe 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 asfar as its limit. This is done by setting the WDTCNTCL bit in WDTCTL. The task is often calledpetting, feeding, or kicking the dog. The bit automatically clears again after WDTCNT has beenreset.
10 Draw the simplified block diagrams of ADC10 and SD16 A.
ABHISHEK V BHAT 24 of 25 1MS12EC001
Microcontroller Assignment-2 MSP430
Simplified block diagrams of ADC10
buffer
ADC10DIVx
ACLK
ADC10OSC
OUT1
ADC10MEM
analog inputs
INCHx
10-bit SAR core Sample
and hold
ADC10SHTx
A0A1
A6A7
A10 A11
Vmid
Vtemp
VCC
R
R
VREF+
Temperature
Start conversionENC
ADC10IFG ADC10SC
OUT0
OUT2
divider /1…../8
ADC10CLK SMCLK
MCLK
VR- VR+
SREF2 SREF,1
voltage reference
REF2_5V
REFON
V eRE
F-
V SS
V eRE
F+
VCC
VREF+
ADC10SR external references
Simplified block diagram of SD16A
ABHISHEK V BHAT 25 of 25 1MS12EC001