LAB MANUAL ON · lab manual on microprocessors and microcontrollers (15a04607) iii b.tech – ii...
Transcript of LAB MANUAL ON · lab manual on microprocessors and microcontrollers (15a04607) iii b.tech – ii...
LAB MANUAL
ON
MICROPROCESSORS AND MICROCONTROLLERS
(15A04607)
III B.TECH – II SEMESTER EEE
(JNTUA – R15)
PREPARED BY
Mrs.T.Vedavathi .,M.Tech
ASSISTANT PROFESSOR
DEPARTMENT OF ELECTRONICS AND
ELECTRICAL ENGINEERING
CHADALAWADA RAMANAMMA ENGINEERING
COLLEGE
CHADALAWADA NAGAR, RENIGUNTA ROAD, TIRUPATI (A.P) - 517506
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY ANANTAPUR
B. Tech III-II Sem. (EEE)
15A04607 MICROPROCESSORS AND MICROCONTROLLERS LABORATORY
Part A : 8086 Microprocessor Programs using NASM/8086 microprocessor kit.
1. Introduction to MASM Programming.
2. Programs using arithmetic and logical operations
3. Programs using string operations and Instruction prefix: Move Block, Reverse string,
Sorting, String comparison
4. Programs for code conversion
5. Multiplication and Division programs
6. Sorting and multi byte arithmetic
7. Programs using CALL and RET instructions
Part B Embedded C Experiments using MSP430 Microcontroller
1. Interfacing and programming GPIO ports in C using MSP430 (blinking LEDs , push
buttons)
2. Usage of Low Power Modes: ( Use MSPEXP430FR5969 as hardware platform and
demonstrate the low power modes and measure the active mode and standby mode current)
3. Interrupt programming examples through GPIOs
4. PWM generation using Timer on MSP430 GPIO
5. Interfacing potentiometer with MSP430
6. PWM based Speed Control of Motor controlled by potentiometer connected to MSP430
GPIO
7. Using ULP advisor in Code Composer Studio on MSP430
8. Low Power modes and Energy trace++:
a. Enable Energy Trace and Energy Trace ++ modes in CCS
b. Compute Total Energy, and Estimated lifetime of an AA battery.
Note : Any six experiment from Part A and Six experiments from Part B are to be
conducted
LIST OF EXPERIMENTS
Note: The students are required to perform any Six Experiments from each Part of the
following.
S.NO NAME OF THE EXPERIMENT
PART A: 8086 Microprocessor Program using MASM/8086 kit
1. Introduction to MASM Programming.
2. Programs using arithmetic and logical operations.
3. Programs using string operations and Instruction prefix: Move Block, Reverse string, Sorting,String comparison.
4. Programs for code conversion.
5. Multiplication and Division programs.
6. Sorting and multi byte arithmetic.
7. Programs using CALL and RET instructions.
PART B: Embedded C Experiments using MSP430 Microcontroller
1. Interfacing and programming GPIO ports in C using MSP430 (blinkingLEDs, push buttons).
2. Usage of Low Power Modes: (Use MSPEXP430FR5969 as hardwareplatform and demonstrate the low power modes and measure the activemode and standby mode current).
3. Interrupt programming examples through GPIOs.
4. PWM generation using Timer on MSP430 GPIO.
5. Interfacing potentiometer with MSP430.
6. PWM based Speed Control of Motor controlled by potentiometerconnected to MSP430 GPIO.
7. Using ULP advisor in Code Composer Studio on MSP430.
8. Low Power modes and Energy trace++: a. Enable Energy Trace and Energy Trace ++ modes in CCS b. Compute Total Energy, and Estimated lifetime of an AA battery.
PART A
INTRODUCTION TO 8086 MICROPROCESSORS
This chapter is intended serve as an introduction to the programming and
some features of 8086 Microprocessor. The users are requested to read 8086
Architecture and organization of 8086 for better understanding.
The 8086-programming model includes general purpose registers, segment
registers, flag registers, base and pointer register whose functions are briefly given
below.
SEGMENT REGISTERS:
Code segment register-CS-stores the base address of the code segment.
Stack segment register-SS-stores the base address of the Stack.
Data segment register-DS-stores the base address of the Data.
Extra segment register-ES-stores the base address of the Extra segment.
INDEX REGISTERS:
Source index Register-SI-Store the base address of the Source data.
Destination index Register-DI-Store the base address of the Destination data.
POINTER REGISTERS:
Instruction Pointer-IP-stores the address of next instruction.
Stack Pointer-SP-stores the address of Top of the stack.
Base Pointer-BP-stores the base address.
GENERAL PURPOSE REGISTERS:
Accumulator-AX-Used in all arithmetic Instructions.
Base Register-BX-used to store Base address while programming.
Counter Register-CX-Used as counter during programming.
Destination Register-DX-used to store base address while programming.
Extended Accumulator-DX; AX-used in some arithmetic Instructions.
All these 16 bit registers can also be used as a pair of 28-bit registers.
FLAG REGISTERS:
The flag register in 8086 is of 16 bit Wide in which only 9 bits are used as flags
and other bits are in don’t care condition. For complete flag format the users are
requested to refer to the books, here only the functions of each flags are briefly given
in order to be helpful while programming.
A flag is a flip flop, which is set or reset after an operation according to the
data conditions of the result in the accumulator and other registers.
1. Zero flag-Z: the flag is set to 1 when the result is Zero, otherwise it is
Reset.
2. Carry flag (barrow)-CY : If an arithmetic operation result in a carry, the
CY flag is set, otherwise it is Reset.
3. Sign flag-S: the sign flag is set if the MSB bit of the result is 1, otherwise
it is Reset.
4. Parity flag-P: If the Result has an even number of 1’s, the flag is set, For
odd number of 1’s the flag is Reset.
5. Direction flag-D: This flag selects increment or decrement mode for the
DI and /or SI registers during string instructions. If the D=1, the
registers are automatically decremented; if D=0 the registers are
automatically incremented.
6. Overflow flag-O: Overflow occurs when signed numbers are added or
subtracted. An overflow indicates that the result has exceeded the
capacity of machine.
7. Trap flag-T: The trap flag unable trapping through an on chip
debugging feature.
8. Interrupt flag-I: The Interrupt flag controls the operation of INTR input
Pin .if I=1 INTR is enabled otherwise it is disabled.
9. Auxiliary carry flag-AC: The Auxiliary carry holds the carry (half
carry) after addition or barrow after subtraction between bit positions 3
and 4 of the result. This bit is tested in special instructions like DAA
and DAS.
Instructions set of 8086:
An instruction is an command to the microprocessor to perform a given task
on specified data. Each instruction has two parts. One is task to be performed, called
the operation code (opcode) and the second is the data to be operated on, called the
operand. The entire group of instructions, called the instruction set, determines what
functions the microprocessor can perform.
The 8086 instructions can be classified into following categories depending on
their functions.
1. Data transfer instructions:
This group of instructions copies the data from a location called source
to another location called destination, without modifying the contents
of the source. The one more specialty of this group is they will not
affect any of the flags in the flag register. The data transfer may be
between registers, memory location and a register, immediate data and
memory or register and between I/O devices and the accumulator.
2. Arithmetic Instructions:
This Instruction performs arithmetic operations such as addition,
subtraction, increment and decrement. The flags are effected by this
group of instructions depending on the results they produce but some
special instructions will not effect flags.
3. Logical, shift or rotate Instructions:
These Instructions perform various logical operations such as AND,
OR, NOT, Compare etc.These instructions will also effect flags.
4. Branching Instructions:
This group of instructions alters the sequence of program execution
either conditionally or unconditionally. Flags are generally used to
generate conditions in case of first type of branch instructions.
5. Machine control Instructions:
These Instructions control machine functions such as HALT, Interrupt
and do nothing etc.
6. String Instructions:
These Instructions special set which are not present in 8085 and these
serve the purpose of operations on strings.
1. INTRODUCTION TO MASM/TASM
Aim: To perform 16-bit addition& subtraction operations using 8086 µp.
THEORY:
There are two ways to execute 8086 programs using a computer. One is using the
DOS tool called DEBUG and the second way is using the Assembler MASM. Hence both the
ways are to be learned.
DEBUG:
The DOS utility called DEBUG allows entering assembly language programs, to
execute these programs to view memory locations and also to trace the program execution.
Starting and Quitting DEBUG:
The simple way of starting the DEBUG is to type the command DEBUG at the DOS
prompt. After the DEBUG is loaded the DEBUG prompt ‘-‘is displayed. Then the DEBUG is
ready to accept any DEBUG commands.
To quit DEBUG the command is Q. This command takes control back to DOS.
DEBUG can be started along with a file also. To load DEBUG with a program say test 1.com
at the DOS prompt type DEBUG test 1.com
DEBUG Commands:
The commands which are required to run / enter the programs are the following.
A Assemble
D Display/Dump
E Enter data
F Fill memory
G Run the program
L Load
N Name a program
P Proceed
Q Quit
R register
T Trace
U Unassembled
W Write
The DEBUG does not detect errors until Enter Key is pressed. If there is any syntax
mistake then the command line is redisplayed with the word error added at the point at which
the error was detected. If a command line contains more than one error, only the first error
will be detected and indicated and execution will stop at that point.
Assemble (A) Command:
The Assemble command is used for entering assembly language mnemonics and
translating them directly to machine language instructions. The syntax for this command is A
address.
Display/Dump (D) Command:
This command displays the content of a block of memory locations. The syntax for
the command is D address 1 address 2
Address 1 is the starting address of the memory block and address 2 is the ending address.
When the ending address is not specified then from the starting address the contents of 128
locations will be displayed. The display consists of both HEX and ASCII formats. In each
line 16 HEX/ASCII numbers will be displayed.
Enter (E) Command:
This command can be used to change the contents of specific memory locations. The
Syntax of this command is E address changes
Address is the beginning address for entering the changes and changes is an optional
list of changes to be made. If the changes are not specified in the command line then DEBUG
enters a special entry mode in which the values of memory locations, beginning at address are
displayed. Then these values can be changed one byte at a time. After each entry press space
bar to display the contents of next location. To exit the entry
Mode and to go back to DEBUG prompt press Enter. If no changes are required for any byte
then simply press Space Bar to go for the next location without changing the values.
Go (G) Execute Command:
This command can be used to run the machine language programs. The syntax of this
command is G=start break1 break2.
=start is an optional starting address of the program and break1 and break2.. are the break
point addresses. If the start address is not specified then the execution starts form the current
value of the instruction pointer. First time DEBUG is loaded with a COM program IP is set to
100. So to execute the COM program simply type the command G.
Load (L) Command:
This command will load a COM file or EXE file in to memory. The syntax of the
command is simply L. The file should be given with another command N. The COM file will
loaded into the memory from CS: 0100 address. After a file have been loaded BX: CX
contains the number of bytes successfully read.
Name (N) Command:
The Name command can be used to specify the file name for Load and Write
commands. The syntax of the command is N file name
Eg: N Test1.com
Register (R) Command:
This command allows us to view the contents of a register and also to change the
values. The syntax for this command isR Register. This “Register” is the optional name of
the register to modify the any of the AX, BX, CX, DX, SP, BP, SI, DI, DS, ES, SS, CS, IP or
F. If the command is given without any parameter DEBUG displays the contents of all the
registers. If a particular register is specified then DEBUG displays the content of that register
and allows us to change the content.
Trace (T) Command:
Trace command is used for single step execution of the program. After the execution
of each instruction the contents of all the registers will be displayed. The Syntax of this
command isT=start count
Start is the beginning address and count is the number os instructions to trace, both
these parameters are optional. If the start is not specified then execution will begin with the
current address stored in IP. If the count is excluded then only one instruction will be
executed.
Unassembled (U) Command:
This command is used to list the program which is already loaded or assembled.
The syntax of this command is U range
Range is an optional when it is used start and end address should be given separated
by a space. If the range is not specified then DEBUG displays the instructions starting from
the current contents of the IP or with the byte following the last byte displayed by the most
recent U command. When range is not specified 16 bytes will decoded and displayed.
Write (W) command:
This command can be used to store the Assembled program on the Hard disk or
Floppy disk. The syntax is just W.
MASM/TASM is an assembler which converts the assembly program to machine
code. While writing the program labels can be used so that there is no need to calculate the
addresses as in case of DEBUG. The program can be just entered in the same way as we
write. The machine code generated by the assembler will not be in the format ready for
execution. The memory specifications will not be there. For this Linker software is required.
The linker software substitutes all the required memory values and makes the machine
program ready for execution.
The input file given to the assembler should be .ASM. It can be created by any text
editors. The assembler converts this .ASM file to .OBJ file when the given program is syntax
error free. This OBJ file is converted into .EXE by using the linker software. The machine
program thus generated can be executed by using DEBUG. If the results are stored in
memory then DEBUG is compulsory to execute the program. If the results are to be displayed
on CRT then the Program can be directly executed just by typing the name of the EXE
program at the DOS prompt.In addition to the mnemonics used in a program we can write
some instructions to the complier also. These instructions are called Assembler Directives.
Assembler directives are not converted into machine language.
PROCEDURE:
1. Writing an ALP
Assembly level programs generally abbreviated as ALP are written in text editor
EDIT.
Type EDIT in front of the command prompt to open an untitled text file.
EDIT<file name>
After typing the program save the file with appropriate file name with an extension
.ASM.
Ex: Add.ASM
2. Assembling an ALP
To assemble an ALP we needed executable file called MASM.EXE. Only if this file
is in current working directory we can assemble the program. The command is
MASM<filename.ASM>
If the program is free from all syntactical errors, this command will give the OBJECT
file. In case of errors it lists out the number of errors, warnings and kind of error.
Note: No object file is created until all errors are rectified.
3. Linking
After successful assembling of the program we have to link it to get Executable file.
The command is LINK<File name.OBJ>
This command results in <Filename.exe> which can be executed in front of the
command prompt.
4. Executing the Program
Open the program in debugger by the command(note only exe files can be open)by
the command. CV <Filename.exe>
This will open the program in debugger screen where in you can view the assemble
code with the CS and IP values at the left most side and the machine code. Register
content, memory content also be viewed using VIEW option of the debugger.
Execute option in the menu in the menu can be used to execute the program either in
single steps(F7) or burst execution(F5).
Result:
2. ARITHMETIC & LOGICAL OPERATIONS
(A) Arithmetic Operations
Aim: To perform 16-bit addition& subtraction operations using 8086 µp.
Apparatus Required:
1. TASM SOFTWARE
2. PERSONAL COMPUTER
Program for addition:
CODE SEGMENT
ASSUME CS: CODE, DS: CODE, ES: CODE, SS: CODE
START: ORG 1000H MOV AX, 0006H
MOV BX, 0004H ADD AX, BX
INT 03H
CODE ENDS
END START
Input:AX, 0006H
BX, 0004H
Output: AX= 000AH
Program for Subtraction:
CODE SEGMENT
ASSUME CS: CODE, DS: CODE, ES: CODE, SS: CODE
START: ORG 1000H
MOV AX, 0008H
MOV BX, 0005H
SUB AX, BX
INT 03H
CODE ENDS
END START
Input:AX = 0008H
BX = 0005H
Output:AX= 0003H
Result:
(B) Logical Operations
Aim: To perform Logical operations of a 16-bit Number using 8086 µp.
Apparatus Required:
1. TASM SOFTWARE
2.PERSONAL COMPUTER
Logical, shift and Rotate Operations:
1) Logical AND:
START: ORG 1000H
MOV AX, 000FH
MOV BX, 000BH
AND AX, BX
INT 03 H
CODE ENDS
END START
Input:AX= 000FH
BX= 000BH
Output:AX= 000BH
2) Logical OR:
START: ORG 1000H
MOV AX, 000CH
MOV BX, 000DH
OR AX, BX
INT 03H
CODE ENDS
END START
Input:AX = 000CH
BX = 000DH
Output:AX= 000DH
3) Logical NOT:
START: ORG 1000H
MOV AX, 000EH
NOT AX
CODE ENDS
END START
Input:AX= 0012H
Output:AX= FFECH
4) 1’s complement:
START: ORG 1000H
MOV AX, 0005H
NOT AX
CODE ENDS
END START
Input:AX= 0005H
Output:AX= FFFAH
5) 2’s complement:
SATRT: ORG 1000H
MOV AX, 0005H
NOT AX
ADD AX, 0001H
INT 03H
CODE ENDS
END START
Input:AX= 0005H
Output:AX= FFEBH
6) Logical EX-OR:
START: ORG 1000H
MOV AX, 000BH
MOV BX, 000CH-
XOR AX, BX
INT 03H
CODE ENDS
END START
Input:AX= 000BH
BX= 000CH
Output:AX= 0000H
7) Logical SHL:
START: ORG 1000H
MOV AX, 0012H
SHL AX, 01H
INT 03H
CODE ENDS
END START
Input:AX= 0012H
Output:AX= 0024H
8) Logical SHR:
START: ORG 1000H
MOV AX, 0012H
SHR AX, 01H
INT 03H
CODE ENDS
END START
Input:AX= 0012H
Output:AX= 0006H
9) Logical ROR:
START: ORG 1000H
MOV AX, 0012H
MOV CL ,01H
ROR AX, CL
INT 03H
CODE ENDS
END START
Input:AX= 0012H
Output:AX= 0006H
10) Logical ROL:
START: ORG 1000H
MOV AX, 0012H
MOV CL, 01H
ROL AX, CL
CODE ENDS
END START
Input:AX= 0012H
Output:AX= 0006H
Result:
3. STRING OPERATIONS AND INSTRUCTION PREFIX
3(A) String Operations
Aim:To perform string operations like Reverse of a string, String copy, String
concatenation, String length, String comparison, String Insertion, String
Deletion
Apparatus Required:
1. TASM SOFTWARE
2.PERSONAL COMPUTER
Program: (I) Reverse order of a String
ASSUME CS: CODE, DS: CODE, ES: CODE, SS: CODE
Data Segment
ORG 1000H
STR1 DB “VIDYA $”
Org 2000H
Str2 DB “ “
DATA ENDS
CODE SEGMENT
START: ORG 3000H
MOV AX, DATA
MOV DS, AX
MOV CS, AX
MOV SI, 1000H
ADD SI, + 05H
MOV DI, 2000H
MOC CL, 05H
L : MOV AL, [SI]
MOV [DI], AL
INC DI
DEC SI
DEC CL
JNZ L
INT 03H
CODE ENDS
END START
Input:Str 1 = VIDYA $
Output: AX= 0B4FH
0B4F: 2000 41 59 44 49 56 “AYDIV$”
Program: (II) String Copy
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 1000H
STR1 DB “SISTK $”
ORG 2000H
STR2 DB ‘’ $ ’’
DATA ENDS
CODE SEGMENT
START: ORG 3000H
MOV AX, OB45H
MOV DS, AX
MOV CS, AX
MOV CL, 06H
MOV SI, 1000H
MOV DI, 2000H
L: MOV AL,[SI]
MOV [DI], AL
INC DI
INC SI
DEC CL
JNZ L
INT 03H
CODE ENDS
END START
Input: STR1: “SISTK $”
Output: AX= 0B4BH
0B4F: 2000 53 49 53 54 4B
Program: (III) Stringconcatenation
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 1000H
STR1 DB ‘’GOOD’’
ORG 2000H
STR2 DB ‘’ MORNING’’
DATA ENDS
CODE SEGMENT
START: ORG 3000H
MOV AX, DATA
MOV DS, AX
MOV CS, AX
MOV CL, 06H
MOV DL, 05H
MOV SI, 2000H
MOV DI, 1000H
ADD DI, +05H
L: MOV AL, [SI]
MOV [DI], AL
INC SI
INC DI
DEC CL
JNZ L
INT 03H
CODE ENDS
END START
Input: STR1: GOOD
STR2: MORNING
Output: AX= 0B234H
0B234: 1000 67 75 64 24 6D 72-6E 67 24
GOOD MORNING
Program: (IV) String Length
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 1000H
STR1 DB “CHINNI $”
DATA ENDS
CODE SEGMENT
START: ORG 2000H
MOV AX, DATA
MOV DS, AX
MOV CX, 0000H
MOV SI, 1000H
L: MOV AX, [SI]
CMP AX, “$”
JZ L
INC SI
INC SI
JMP L
EXIT: INT 03H
CODE ENDS
END START
Input: STR1: CHINNI $
Output: AX = 0024H
CX = 0007H
0B4F:2000 43 48 49 4E 4E 49 24 CHINNI $
Program: (V) String Comparison
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 1000H
STR1 DB “SIETK $”
ORG 2000H
STR2 DB “SISTK $ “
ORG 4000H
Display 1 DB “EQUALS $ “
ORG 5000H
Display 2 DB “NOT EQUALS $”
DATA ENDS
CODE SEGMENT
START: ORG 3000H
MOV AX, DATA
MOV DS, AX
MOV CX, AX
MOV CL, 05H
MOV SI, 1000H
MOV DI, 2000H
L1: MOV BL, [SI]
MOV DL, [DI]
CMP BL, DL
JNZ L
INC SI
INC DI
DEC CL
JNZ L1
MOV AH, 09H
MOV DX, 4000H
INT 03H
JMP STOP
L : MOV AX, 09H
MOV DX, 5000H
INT 21H
STOP: MOV AH, 4CH
INT 21H
CODE ENDS
END START
Input: strg 1: SIETK $
strg2 : SIETK $
Output: AX= 094FH “NOT EQUAL $”
0B4F: 5000 4E 4F 54 45 51 55 41 4C-24
“NOT EQUAL $”
Program: (VI) String Insertion
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 1000H
STR1 DB “VERY MORNING $”
STR2 DB “GOOD $ “
Org 3000H
STR3 DB “ “
DATA ENDS
CODE SEGMENT
START: ORG 3000H
MOV AX, DATA
MOV DS, AX
MOV ES, AX
MOV DI, 3000H
MOV SI, 1000H
CLD
MOV CL, 05H
L1: MOV AL,[SI]
MOV [DI], AL
INC DI
INC SI
DEC CL
JNZ L1
CLD
MOV SI, OFFSET STR3
MOV CL, 04H
L2: MOV AL,[SI]
INC DI
INC SI
DEC CL
JNZ L2
MOV SI, OFFSET STR1
MOV CL, 08H
L3: MOV AL, [SI]
MOV [DI], AL
INC DI
INC SI
DEC CL
INT 03H
CODE ENDS
END START
Input: VERY MORNING $
GOOD $
Output: AX = 0B67H
0B4F: 3000 76 65 72 79 20 67 6F 6F-64 20 6D 6F
72 6E 69 6E 67
VERY GOOD MORNING
Program: (VII) String Deletion
ASSUME CS: CODE, DS: CODE, ES: CODE
DATA SEGMENT
ORG 2000H
STR1 DB “WELCOME TO CSE $”
Org 2040H
STR3 DB “ “
DATA ENDS
CODE SEGMENT
START : ORG 1000H
MOV AX, DATA
MOV DS, AX
MOV ES, AX
MOV SI, 2000H
MOV DI, 2040H
MOV CL, 05H
MOVDL, 05H
L1: MOV AL, [SI]
MOV [DI], AL
INC DI
INC SI
DEC CL
JNZ L1
ADD SI, 04H
MOV CL, O8H
L2: MOV AL, [SI]
MOV [DI], AL
INC SI
INC DI
DEC CL
JNZ L2
INT 03H
CODE ENDS
END START
Input: WELCOME TO CSE $
Output: AX = 0B4FH WELCO CSE
0B4F: 2040 77 65 6C 63 6F 6F 20 63-73
65 WELCO CSE
Result:
3(B) Instruction Prefix
Aim:To perform data transfer operations like Move block with and without
overlapping.
Apparatus Required:
1. TASM SOFTWARE
2.PERSONAL COMPUTER
Program: (I) Block move without overlapping
DATA SEGMENT
X DB 01H,02H,03H,04H,05H ;Initialize Data Segments Memory Locations
Y DB 05 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA ; Initialize DS to point to start of the memory
MOV DS,AX ; set aside for storing of data
MOV CX,05H ; Load counter
LEA SI,X+04 ; SI pointer pointed to top of memory block
LEA DI,X+04+03 ; 03 is displacement of over lapping, DI
; pointed to the top of the destination block
Before execution After execution
Program: (II) Block move with overlapping
DATA SEGMENT
X DB 01H,02H,03H,04H,05H ;Initialize Data Segments Memory Locations
Y DB 05 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA ; Initialize DS to point to start of the memory
MOV DS,AX ; set aside for storing of data
MOV CX,05H ; Load counter
LEA SI,X+04 ; SI pointer pointed to top of memory block
LEA DI,X+04+03 ; 03 is displacement of over lapping, DI
; pointed to the top of the destination block
UP: MOV BL,[SI] ; Move the SI content to BL register
MOV [DI],BL; Move the BL register to content of DI
DEC SI ; Update SI and DI
DEC DI
DEC CX ; Decrement the counter till it becomes zero
JNZ UP
MOV AH,4CH
INT 21H
CODE ENDS
END START
Before Execution After Execution
Result:
4. CODE CONVERSION
(A) Packed BCD to Unpacked BCD
Aim:To performALP for Conversion of packed BCD to unpacked BCD
Using 8086 µp.
Apparatus Required:
1. TASM SOFTWARE
2.PERSONAL COMPUTER
Program:
CODE SEGMENT
ASSUME CS: CODE, DS: CODE, ES: CODE, SS: CODE
START: ORG 1000H
MOV AL, 82H
AND AL, F0H
MOV CL, 04H
ROR AL, CL
MOV AH, AL
MOV AL, 84H
AND AL 0FH
INT 03H
CODE ENDS
END START
Input: AL= 82H
Output: AX = 0802H
Result:
(B) Packed BCD to ASCII
Aim:To performALP For Conversion of BCD to ASCII using 8086 µp
Apparatus Required:
1. TASM SOFTWARE
2.PERSONAL COMPUTER
Program:
CODE SEGMENT
ASSUME CS: CODE, DS: CODE, ES: CODE, SS: CODE
START: ORG 1000H
MOV AL, 45H
AND AL, F0H
MOV CL, 04H
ROR AL, CL
MOV AH, AL
MOV AL, 45H
AND AL 0FH
MOV AX, 3030H
INT 03H
CODE ENDS
END START
Input: AL = 45H
Output: AX = 3435H
Result:
5. MULTIPLICATION AND DIVISON OPERATIONS
(A)Multiplication operation
Aim: To perform 16-bit Multiplication operation using 8086 µp.
Apparatus Required:
1. TASM SOFTWARE
2.PERSONAL COMPUTER
Program:
CODESEGMENT
ASSUME CS: CODE, DS: CODE, ES: CODE, SS: CODE
START: ORG 1000H
MOV AX, 0002H
MOV BX, 0003H
MUL BX
INT 03H
CODE ENDS
END START
Input:AX= 0002H
BX= 0003H
Output:AX= 0006H
Result:
(B) Division operation
Aim: To perform 16-bit Division operation using 8086 µp.
Apparatus Required:
1. TASM SOFTWARE
2.PERSONAL COMPUTER
Program:
CODE SEGMENT
ASSUME CS: CODE, DS: CODE, ES: CODE, SS: CODE
START: ORG 1000H
MOV AX, 0006H
MOV BX, 0002H
DIV BX
INT 03H
CODE ENDS
END START
Input:AX= 0006H
BX= 0002H
Output:AX= 0003H
Result:
6. SORTING AND MULTI BYTE ARITHMETIC
(A) Sorting operations
(I) Sorting of array in ascending order
Aim: To perform ALP for sorting numbers in ascending order
Apparatus Required:
1. TASM SOFTWARE
2. PERSONAL COMPUTER
Program:
ASSUME CS: CODE, DS: CODE, ES: CODE, SS:CODE
DATA SEGMENT
ORG 1000H
LIST1 DB 05H, 06H, 03H, 02H, 09H
DATA ENDS
CODE SEGMENT
START: ORG 2000H
MOV AX, DATA
MOV DS, AX
MOV CL, 04H
MOV DL, 04H
L1: MOV DL, CL
MOV SI OFFSET LIST
L2: MOV AL, [SI]
CMP AL, [SI+1]
JC L
XCHG AL, [SI+1]
MOV [SI], AL
L: INC SI
DEC DL
JNZ L2
DEC CL
JNZ L1
MOV SI, OFFSET LIST
MOV [SI], AL
INT 03H
CODE ENDS
END START
Input: 05H, 06H, 03H, 02H, 09H
Output: 1000 02H, 03H, 05H, 06H, 09H.
Result:
(II) Sorting of array in descending order
Aim: To perform ALP for sorting numbers in descending order
Apparatus Required:
1. TASM SOFTWARE
2. PERSONAL COMPUTER
Program:
ASSUME CS: CODE, DS: CODE, ES: CODE, SS: CODE
DATA SEGMENT
ORG 1000H
LIST1 DB 05H, 06H, 03H, 02H, 09H
DATA ENDS
CODE SEGMENT
START: ORG 2000H
MOV AX, DATA
MOV DS, AX
MOV CL, 04H
MOV DL, 04H
L1: MOV DL, CL
MOV SI OFFSET LIST
L2: MOV AL, [SI]
CMP AL, [SI+1]
JNC L
XCHG AL, [SI+1]
MOV [SI], AL
L: INC SI
DEC DL
JNZ L2
DEC CL
JNZ L1
MOV SI, OFFSET LIST
MOV [SI], AL
INT 03H
CODE ENDS
END START
Input: 05H, 06H, 03H, 02H, 09H
Output: 1000 09H, 06H, 05H, 03H, 02H.
Result:
(B) MULTI BYTE ARITHMETIC OPERATIONS
(i) Aim: To perform 32-Bit addition operation using 8086 µp.
Apparatus Required:
1. TASM SOFTWARE
2. PERSONAL COMPUTER
Program:
DATA SEGMENT
NUM1 DW 0FFFFH,0FFFFH
NUM2 DW 1111H,1111H
SUM DW 4 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,NUM1 ;Move LSB of NUM1 to AX
ADD AX,NUM2 ;Add LSB of NUM2 to AX
MOV SUM,AX ;Store the LSB in SUM
MOV AX,NUM1+2 ; Move MSB of NUM1 to AX
ADC AX,NUM2+2 ; Add MSB of NUM2 to AX
JNC DOWN ; Check for carry
MOV SUM+4,01H ; Store the carry in SUM+4
DOWN: MOV SUM+2,AX ; Store the MSB in SUM+2
MOV AH,4CH
INT 21H
CODE ENDS
END START
Input: 0FFFFFFFFH, 011111111H
Output: 0111111110H
Result:
(ii) Aim: To perform 32-Bit subtraction operation using 8086 µp.
Apparatus Required:
1. TASM SOFTWARE
2. PERSONAL COMPUTER
Program:
DATA SEGMENT
NUM1 DW 2345H,6762H
NUM2 DW 1111H,1111H
DIF DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
LEA SI,NUM1 ; SI pointed to the LSB of NUM1
LEA DI,NUM2 ; DI pointed to the LSB of NUM2
MOV AX,[SI] ; Move the content of SI to AX
MOV BX,[DI] ; Move the content of DI to BX
SUB AX,BX ; Subtract from BX to AX
MOV DIF,AX ; Store the LSB result in DIF
INC SI ;Update SI to point the MSB of NUM1
;(if ADD SI,02 instruction its affect carry flag)
INC SI
INC DI ;Update DI to point the MSB of NUM2
INC DI
MOV AX,[SI] ; Move the content of SI to AX
MOV BX,[DI] ; Move the content of DI to BX
SBB AX,BX ; Subtract with borrow from BX to AX
MOV DIF+2,AX ; Store the MSB result in DIF+2
MOV AH,4CH
INT 21H
CODE ENDS
END START
Input: 23456762,-11111111 Output:12345651
Result:
7. CALL AND RETURN INSTRUCTIONS
Aim: To write an ALP program using CALL & RET instruction operations using
8086 µp.
Apparatus Required:
1. TASM SOFTWARE
2. PERSONAL COMPUTER
Program:
START: ORG 1000H
MOV A, #55H
MOV R0, #10H
LCALL FILL
MOV A, #60H
MOV R0, #10H
LCALL FILL
MOV A, #65H
MOV R0, #70H
LCALL FILL
HG: SJMP HG
FILL: MOV R1, #05H
M1: MOV@R0, A
INC R0
DJNZ R1,M1
RET
END START
Input:
Output:
Result:
ADDITIONAL EXPERIMENTS
1. KEYBOARD DISPLAY CONTROLLER
Aim:1.Write a Program to interfacing of Keyboard Display Controller with
Microcontroller 8051.
Apparatus required:
1. 8051 Microcontroller Trainer Kit,
2. Keyboard Display Controller Interface Module
3. AT-8051 Software
Program:
CMDB8255 EQU 0FF23H
PAB8255 EQU 0FF20H
PBB8255 EQU 0FF21H
PCB8255 EQU 0FF22H
ACC EQU 0E0H
B EQU 0F0H
ORG 8000H
MOV A,#81H
MOV DPTR,#CMDB8255
MOVX @DPTR,A
READKEY:
MOV R7,#00
MOV A,#0FH
MOV DPTR,#PCB8255
MOVX @DPTR,A
RELEZ:
MOV DPTR,#PCB8255
MOVX A,@DPTR
ANL A,#0FH
CJNE A,#0FH,RELEZ
CALL DELY
KEYCHK:
MOV DPTR,#PCB8255
MOVX A,@DPTR
ANL A,#0FH
CJNE A,#0FH,DECODE
JMP KEYCHK
DECODE:
CALL DELY
MOV A,#0FEH
MOV B,#02H
MOV R6,A
NXTCOLM:
MOV A,R6
RR A ;scan each column
MOV R6,A ;and wait for the data
MOV DPTR,#PCB8255
MOVX @DPTR,A ;in any of the four
MOV DPTR,#PCB8255 ;rows
MOVX A,@DPTR
ANL A,#0FH
MOV R5,#04H
NXTROW:
RRC A
JNC COD
INC R7 ;increment to get
DJNZ R5,NXTROW;the desired address from
;the lookup table
MOV A,R6
DEC B
MOV A,B
JNZ NXTCOLM
JMP KEYCHK
COD:
MOV A,R7
MOV DPTR,#LOOKUP
MOVC A,@A+DPTR
MOV DPTR,#PBB8255
MOVX @DPTR,A
MOV DPTR,#PAB8255
SWAP A
MOVX @DPTR,A
JMP READKEY
;Software delay routine
DELY:
PUSH ACC
MOV A,#0FFH
LOP:
NOP
NOP
DEC A
JNZ LOP
POP ACC
RET
LOOKUP:
DB 04H,05H,06H,07H
DB 00H,01H,02H,03H
END
Result:
2.SEVEN SEGMENT DISPLAY INTERFACE
Aim: Write a Program to interfacing of seven segment display with
Microcontroller 8051.
Apparatus Required:
1. 8051 Microcontroller Trainer Kit
2. seven segment display Interface Module
3. AT-8051 Software
Program: CMDB8255 EQU 0FF23H
PAB8255 EQU 0FF20H
PBB8255 EQU 0FF21H
PCB8255 EQU 0FF22H
ACC EQU 0E0H
B EQU 0F0H
DPH EQU 83H
DPL EQU 82H
ORG 8000H
MOV A,#80H
MOV DPTR,#CMDB8255
MOVX @DPTR,A
START: MOV R0,#00H
UP: MOV A,R0
LCALL DOUT
CJNE R0,#0AH,UP
LCALL DELAY
LCALL DELAY
MOV R0,#00H
UP1: MOV A,R0
SWAP A
LCALL DOUT
CJNE R0,#0AH,UP1
LCALL DELAY
LCALL DELAY
MOV A,#00H
MOV DPTR,#PAB8255
MOVX @DPTR,A
MOV R0,#00H
UP2: MOV A,R0
LCALL DOUT1
CJNE R0,#0AH,UP2
LCALL DELAY
LCALL DELAY
MOV R0,#00H
UP3: MOV A,R0
SWAP A
LCALL DOUT1
CJNE R0,#0AH,UP3
LCALL DELAY
LCALL DELAY
MOV A,#00H
MOV DPTR,#PBB8255
MOVX @DPTR,A
LCALL DELAY
LCALL DELAY
;SEGMENT
MOV R4,#08H
MOV A,#0FEH
MOV DPTR,#PCB8255
GOP: MOVX @DPTR,A
RR A
LCALL DELAY
LCALL DELAY
DJNZ R4,GOP
LCALL DELAY
LCALL DELAY
MOV R6,#00H
MOV A,#00H
GAIN: MOV DPTR,#DAT
MOVC A,@A+DPTR
MOV DPTR,#PCB8255
MOVX @DPTR,A
LCALL DELAY
LCALL DELAY
INC R6
MOV A,R6
CJNE R6,#10H,GAIN
LCALL DELAY
LJMP START
DOUT:
MOV DPTR,#PAB8255
MOVX @DPTR,A
LCALL DELAY
LCALL DELAY
INC R0
RET
DOUT1:
MOV DPTR,#PBB8255
MOVX @DPTR,A
LCALL DELAY
LCALL DELAY
INC R0
RET
DAT:
DB 40H,0E6H,88H,82H,26H,12H,30H,0C6H
DB 00H,06H,04H,30H,58H,0A0H,18H,1CH
DELAY:
MOV R3,#45H
DE: MOV R1,#0FFH
XX: DJNZ R1,XX
MOV R2,#0FFH
YY: DJNZ R2,YY
DJNZ R3,DE
RET
END
Result:
3. SERIAL COMMUNICATION
Aim:Write an ALP using 8051 microcontroller to transfer the message“YES”
serially at 9600 baud, 8-bit data, 1 stop bit, do this continuously.
Apparatus Required:
1. KEIL µVision software
2. Personal computer.
Program:
MOV TMOD,#20H Initialize the TMOD register
MOV TH1,#--3 set the band rate to 9600
MOV SCON,#50 Initialize the SCON register
SETB TR1 Set the TR flag
AGAIN MOV A,#"Y" Load they' ASCII value
ACALL TRANS call the sub-program
MOV A,#"E" Load 'e' ASCII value
ACALL TRANS Call the sub program
MOV A,#"S" Load the 's' ASCII value
ACALL TRANS Call the subprogram
SJMP AGAIN Repeat the same process
TRANS MOV SBUF,A Initialize the buffer register
HERE JNB TI,HERE check the TI flag
CLR TI Clear TI
RET Return to main
Result:
4. UART
Aim: Write a Program to interfacing of UART with Microcontroller 8051.
Apparatus Required:
1. 8051 Microcontroller Trainer Kit
2. UART
Program:
TMOD EQU 89H
TH1 EQU 8DH
SCON EQU 98H
TCON EQU 88H
SBUF EQU 99H
ORG 8000H
MOV TMOD,#20H
MOV TH1,#0FDH
MOV SCON,#50H
SETB TCON.6 ;TR1
HERE: JNB SCON.0,HERE
MOV A,SBUF
MOV DPTR,#8500H
MOVX @DPTR,A
INC DPTR
CLR SCON.0
SJMP HERE
END
RESULT:
PART B
PART-B
EMBEDDED C USING MSP430 MICROCONTROLLER
MSP-EXP430FR5969 Pin map
(1A) To Blink GREEN LED with GPIO
AIM:The main objective of this experiment is to blink the on-board, GREEN LED (connected to
P1.0) using GPIO.
APPARATUS REQUIRED:
● Code composer studio software
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
The MSP430FR5969 has two LED’s connected to GREEN LED (P1.0) and RED LED (P4.6) on
the MSP430FR5969 LaunchPad for visual feedback. In this experiment, the code programmed
into the MSP430FR5969 processor toggles the output on Port P1.0 at fixed time intervals
computed within the code. A HIGH on P1.0 turns the LED ON, while a LOW on P1.0 turns the
LED OFF. Thus, the toggling output blinks the GREEN LED connected to it.
PROCEDURE:
1. Connect the MSP430FR5969 LaunchPad to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS to view the status of the
LED.
3. In the CCS debug perspective, select View --> Registers.
PROGRAM:
#include<msp430.h> intmain(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode to //activate previously configured port settings P1DIR |= 0x01;// set the pin 1.0 direction to O/P while(1){ volatileunsignedlongi; P1OUT ^=0x01;// blink LED i = 50000; doi--; while(i != 0); } return 0; }
RESULT:
(1B) To Blink an RED LED with GPIO
AIM:The main objective of this experiment is to blink the onboard, RED LED (connected to
P4.6) using GPIO.
APPARATUS REQUIRED:
● Code composer studio software
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
The MSP430FR5969 has two LED’s connected to GREEN LED (P1.0) and RED LED (P4.6) on
the MSP430FR5969 LaunchPad for visual feedback. In this experiment, the code programmed
into the MSP430FR5969 processor toggles the output on Port P4.6 at fixed time intervals
computed within the code. A HIGH on P4.6 turns the LED ON, while a LOW on P4.6 turns the
LED OFF. Thus, the toggling output blinks the RED LED connected to it.
PROCEDURE:
1. Connect the MSP430FR5969 LaunchPad to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS to view the status of the
LED.
3. In the CCS debug perspective, select View --> Registers.
PROGRAM:
#include<msp430.h> intmain(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default //high- //impedance mode to activate previously configured port settings P4DIR |= 0x40;;// set the pin 4.6 direction to O/P while(1){ volatileunsignedlongi; P4OUT ^=0x40;// blink LED i = 50000; doi--; while(i != 0); } return 0; }
RESULT:
(1C) To Blink an RED LED & GREEN LED Together
AIM:The main objective of this experiment is to blink the onboard, RED LED (connected to
P4.6) and GREEN LED(connected to P1.0) together using GPIO.
APPARATUS REQUIRED:
● Code composer studio software
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
The MSP430FR5969 has two LED’s connected to GREEN LED (P1.0) and RED LED (P4.6) on
the MSP430FR5969 LaunchPad for visual feedback. In this experiment, the code programmed
into the MSP430FR5969 processor toggles the output on Port P4.6 & P1.0 at fixed time intervals
computed within the code. A HIGH on P4.6 & P1.0 turns the LED ON, while a LOW on P4.6 &
P1.0 turns the LED OFF. Thus, the toggling output blinks the RED LED & GREEN LED
together connected to it.
PROCEDURE:
1. Connect the MSP430FR5969 LaunchPad to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS to view the status of the
green & red LED.
3. In the CCS debug perspective, select View --> Registers.
PROGRAM:
#include<msp430.h> intmain(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default //high-impedance mode to activate previously configured port settings P1DIR |= 0x01; P4DIR |= 0x40; P1OUT |= 0x01; P4OUT |= 0x40; while(1){ volatileunsignedlongi; P1OUT ^= 0x01; P4OUT ^=0x40; i = 50000; doi--; while(i != 0); } return 0; }
RESULT:
(1D)To Blink an RED LED & GREEN LED Alternatively
AIM:The main objective of this experiment is to blink the onboard, RED LED (connected to
P4.6) and GREEN LED(connected to P1.0) alternatively using GPIO.
APPARATUS REQUIRED:
● Code composer studio software
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
The MSP430FR5969 has two LED’s connected to GREEN LED (P1.0) and RED LED (P4.6) on
the MSP430FR5969 LaunchPad for visual feedback. In this experiment, the code programmed
into the MSP430FR5969 processor toggles the output on Port P4.6 & P1.0 at different time
intervals computed within the code. For the first time GREEN LED turns ON and RED LED
turns OFF,after one second GREEN LED turns OFF and RED LED turns ON.Thus, the toggling
output blinks the RED LED & GREEN LED alternatively connected to it.
PROCEDURE:
1. Connect the MSP430FR5969 LaunchPad to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS to view the status of the
green & red LED.
3. In the CCS debug perspective, select View --> Registers
PROGRAM:
#include<msp430.h> intmain(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default //high-//impedance mode to activate previously configured port settings P1DIR |= 0x01; P4DIR |= 0x40; P1OUT |= 0x01; P4OUT &= ~0x40; while(1){ volatileunsignedlongi; P1OUT ^= 0x01; P4OUT ^=0x40; i = 50000; doi--; while(i != 0); } return 0; }
RESULT:
(1E)To Blink an GREEN LED using Button
AIM:The main objective of this experiment is to blink the onboard, GREEN LED(connected to
P1.0) whenever button (connected to P.1.1) is pressed and OFF when released using GPIO.
APPARATUS REQUIRED:
● Code composer studio software
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
The MSP430FR5969 has two LED’s and two push BUTTONS connected to GREEN LED
(P1.0),S2(P1.1) and RED LED (P4.6),S1(P4.5) on the MSP430FR5969 LaunchPad for visual
feedback. In this experiment, the code programmed into the MSP430FR5969 processor to turn on
GREEN LED when button is pressed & OFF when button is released are computed within the
code.
PROCEDURE:
1. Connect the MSP430FR5969 LaunchPad to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS to view the status of the
LED.
3. In the CCS debug perspective, select View --> Registers.
PROGRAM:
#include<msp430.h> intmain(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode //to activate previously configured port settings P1DIR |= 0x01; P1REN |= 0x02; while(1){ if(P1IN & BIT1){ P1OUT &= ~BIT0; }else{ P1OUT |= BIT0; } } return 0; }
RESULT:
(1F) To Blink an GREEN LED using Button with Delay 1sec
AIM:The main objective of this experiment is to make the green LED stay ON for around 1
second every time the button is pressed.
APPARATUS REQUIRED:
● Code composer studio software
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
The MSP430FR5969 has two LED’s and two push BUTTONS connected to GREEN LED
(P1.0),S2(P1.1) and RED LED (P4.6),S1(P4.5) on the MSP430FR5969 LaunchPad for visual
feedback. In this experiment, the code programmed into the MSP430FR5969 processor make the
green LED stay ON for around 1 second every time the button is pressed.
PROCEDURE:
1. Connect the MSP430FR5969 LaunchPad to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS to view the status of the red
LED.
3. In the CCS debug perspective, select View --> Registers.
PROGRAM:
#include<msp430.h> intmain(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer // Disable the GPIO power-on default //high-//impedance mode to activate previously configured port settings PM5CTL0 &= ~LOCKLPM5; P1DIR |= 0x01; P1REN |= 0x02; while(1){ volatileunsignedlongi; if(P1IN & BIT1){ P1OUT &= ~BIT0; }else{ P1OUT |= BIT0; i = 50000; doi--; while(i != 0); } } return 0; }
RESULT:
(1G) To Blink an GREEN LED & RED LED using Button
AIM:The main objective of this experiment is to turn the red LED ON when the button is
pressed and the green LED ON when the button is released.
APPARATUS REQUIRED:
● Code composer studio software
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
The MSP430FR5969 has two LED’s and two push BUTTONS connected to GREEN LED
(P1.0),S2(P1.1) and RED LED (P4.6),S1(P4.5) on the MSP430FR5969 LaunchPad for visual
feedback. In this experiment, the code programmed into the MSP430FR5969 processor turn the
red LED ON when the button is pressed and the green LED ON when the button is released.
PROCEDURE:
1. Connect the MSP430FR5969 LaunchPad to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS to view the status of the
LED.
3. In the CCS debug perspective, select View --> Registers
PROGRAM:
#include<msp430.h> intmain(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer // Disable the GPIO power-on default //high-impedance mode to activate previously configured port settings PM5CTL0 &= ~LOCKLPM5; P1DIR |= 0x01; P1REN |= 0x02; P4DIR |= 0x40; while(1){ volatileunsignedlongi; if(P1IN & BIT1){ P1OUT |= BIT0; P4OUT &= ~BIT6; }else{ P1OUT &= ~BIT0; P4OUT |= BIT6; } } return 0; }
RESULT:
2. LOW POWER MODE(S)
AIM:The main objective of this experiment is to Configure the MSP-EXP430FR Launchpad for
Low Power Mode (LPM3) and measure current consumption both in active and low power
modes.
APPARATUS REQUIRED:
● Code composer studio software
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
The RTC_B module is used to set the time, start RTC operation,and read the time from the
respective RTC registers. Software will set the original time to 11:59:30 am on Friday
October 7, 2011. Then the RTC will be activated through software, and an alarm will be
created for the next minute (12:00:00 pm). The device will then enter LPM3.5 awaiting the
event interrupt. Upon being woken up by the event, the LED on the board will be set.we will
use MSP-EXP430FR5969 as hardware platform and measure active mode and standby mode
current.
ACLK = 32.768kHz, MCLK = SMCLK = DCO = ~1MHz
MSP430FR59xx
-----------------
/|\| XIN|-
| | | 32kHz
--|RST XOUT|-
| |
| P1.0 |--> LED
PROCEDURE:
1. Connect the MSP430FR5969 LaunchPad to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS to view the status of the
LED.
3. In the CCS debug perspective, select View --> Others-->Energy Trace Technology
4. Note down the power consumption in Active mode and Low power mode 3.5.
PROGRAM:
#include<msp430.h> voidBoard_Init(void); voidRTC_Init(void); voidEnterLPM35(void); voidWakeUpLPM35(void); intmain(void) { WDTCTL = WDTPW | WDTHOLD; // Stop WDT
// Determine whether we are coming out of an LPMx.5 or a regular RESET. if (SYSRSTIV == SYSRSTIV_LPM5WU) { // When woken up from LPM3.5, reinit WakeUpLPM35(); // LPMx.5 wakeup specific init code __enable_interrupt(); // The RTC interrupt should trigger now... while (1); // Forever loop after returning from RTC ISR. } else { // Init board & RTC, then enter LPM3.5 Board_Init(); // Regular init code for GPIO and CS RTC_Init(); // Regular init code for RTC_B EnterLPM35(); // This function will NOT return. } } voidBoard_Init(void) { // Port Configuration P1OUT = 0x00; P1DIR = 0xFF; P2OUT = 0x00; P2DIR = 0xFF; P3OUT = 0x00; P3DIR = 0xFF; P4OUT = 0x00; P4DIR = 0xFF; PJOUT = 0x00; PJSEL0 |= BIT4 | BIT5; PJDIR = 0xFFFF; // Disable the GPIO power-on default high-impedance mode to activate // previously configured port settings PM5CTL0 &= ~LOCKLPM5; // Setup Clocks CSCTL0_H = CSKEY >>8; // Unlock CS registers CSCTL1 = DCOFSEL_0; // Set DCO to 1MHz CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK; // set ACLK = XT1;MCLK = DCO CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers to 1 CSCTL4 &= ~LFXTOFF; // Enable LFXT1 do { CSCTL5 &= ~LFXTOFFG; // Clear XT1 fault flag SFRIFG1 &= ~OFIFG; }while (SFRIFG1&OFIFG); // Test oscillator fault flag CSCTL0_H = 0; // Lock CS registers } voidRTC_Init(void) { // Configure RTC_B RTCCTL01 = RTCBCD | RTCHOLD | RTCTEV__MIN | RTCTEVIE; // BCD mode, RTC hold, enable RTC // event interrupt for each minute RTCYEAR = 0x2011; // Year = 0x2011
RTCMON = 0x10; // Month = 0x10 = October RTCDAY = 0x07; // Day = 0x07 = 7th RTCDOW = 0x05; // Day of week = 0x05 = Friday RTCHOUR = 0x11; // Hour = 0x11 RTCMIN = 0x59; // Minute = 0x59 RTCSEC = 0x30; // Seconds = 0x30 RTCCTL01 &= ~RTCHOLD; // Start RTC calendar mode } voidEnterLPM35(void) { PMMCTL0_H = PMMPW_H; // Open PMM Registers for write PMMCTL0_L |= PMMREGOFF; // and set PMMREGOFF // Enter LPM3.5 mode with interrupts enabled. Note that this operation does // not return. The LPM3.5 will exit through a RESET event, resulting in a // re-start of the code. __bis_SR_register(LPM4_bits | GIE); } voidWakeUpLPM35(void) { // Restore Port settings P1OUT = 0x00; P1DIR = 0xFF; P2OUT = 0x00; P2DIR = 0xFF; P3OUT = 0x00; P3DIR = 0xFF; P4OUT = 0x00; P4DIR = 0xFF; PJOUT = 0x00; PJSEL0 |= BIT4 | BIT5; PJDIR = 0xFFFF; // Reconfig/start RTC RTCCTL01 |= RTCBCD | RTCHOLD | RTCTEV__MIN | RTCTEVIE; // BCD mode, RTC hold, enable RTC // event interrupt for each minute RTCCTL01 &= ~RTCHOLD; // Disable the GPIO power-on default high-impedance mode to activate // previously configured port settings. This will also re-activate the RTC // settings. PM5CTL0 &= ~LOCKLPM5; // Restore Clocks so that RTC will be read CSCTL0_H = CSKEY >>8; // Unlock CS registers CSCTL1 = DCOFSEL_0; // Set DCO to 1MHz CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK; // Set ACLK = XT1; MCLK = DCO CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers to 1 CSCTL4 &= ~LFXTOFF; // Enable LFXT1 do { CSCTL5 &= ~LFXTOFFG; // Clear XT1 fault flag SFRIFG1 &= ~OFIFG; }while (SFRIFG1&OFIFG); // Test oscillator fault flag CSCTL0_H = 0; // Lock CS registers }
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=RTC_VECTOR __interruptvoidRTC_ISR(void) #elif defined(__GNUC__) void__attribute__ ((interrupt(RTC_VECTOR))) RTC_ISR (void) #else #error Compiler not supported! #endif { switch (__even_in_range(RTCIV, RTCIV_RTCOFIFG)){ case RTCIV_NONE: break; case RTCIV_RTCRDYIFG: break; case RTCIV_RTCTEVIFG: P1OUT |= BIT0; // Turn on LED break; case RTCIV_RTCAIFG: break; case RTCIV_RT0PSIFG: break; case RTCIV_RT1PSIFG: break; case RTCIV_RTCOFIFG: break; } }
RESULT:
(3A) GPIO BASED INTERRUPT
AIM:The main objective of this experiment is to write a C program and associated GPIO ISR
using interrupt programming technique.
APPARATUS REQUIRED:
● Code composer studio software
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
The MSP430FR5969 has two LED’s and two push BUTTONS connected to GREEN LED
(P1.0),S2(P1.1) and RED LED (P4.6),S1(P4.5) on the MSP430FR5969 LaunchPad for visual
feedback. In this experiment, the code programmed into the MSP430FR5969 processor toggle
the GREEN LED whenever interrupt is generated.
MSP430FR59xx
-----------------
/|\| XIN|-
| | | 32kHz
--|RST XOUT|-
| |
| P1.0 |--> LED
| P1.1 |--->S2
PROCEDURE:
1. Connect the MSP430FR5969 LaunchPad to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS to view the status of the
LED.
3. In the CCS debug perspective, select View --> Registers
4. Press the S2 and observe the GREEN LED toggled.
PROGRAM:
#include<msp430.h> intmain(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT PM5CTL0 &= ~LOCKLPM5; P1DIR |= BIT0; // Set P1.0 to output direction P1REN |= BIT1; // Enable P1.1 internal resistance P1OUT |= BIT1; // Set P1.1 as pull up resistance P1IES |= BIT1; // P1.1 High/Low Edge P1IFG &= ~BIT1; // P1.1 IFG Cleared P1IE |= BIT1; // P1.1 Interrupt Enabled _bis_SR_register(LPM4_bits + GIE); // Enter LPM4 w/ interrupt _no_operation(); return 0; }
#pragma vector=PORT1_VECTOR __interruptvoidPort_1 (void) { P1OUT ^= BIT0; // Toggle P1.0 P1IFG &= ~BIT1; // P1.1 IFG Cleared }
RESULT:
(3B) TIMER INTERRUPT
AIM:The main objective of this experiment is to write a C program and TIMER ISR using
interrupt programming technique.
APPARATUS REQUIRED:
● Code composer studio software
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
The MSP430FR5969 has two LED’s and two push BUTTONS connected to GREEN LED
(P1.0),S2(P1.1) and RED LED (P4.6),S1(P4.5) on the MSP430FR5969 LaunchPad for visual
feedback. In this experiment, the code programmed into the MSP430FR5969 processor Toggle
P1.0 using software and TA_0 ISR. Timer0_A is configured for continuous mode, thus the timer
overflows when TAR counts to CCR0. In this example, CCR0 is loaded with 50000.
// ACLK = n/a, MCLK = SMCLK = TACLK = default DCO = ~1MHz
MSP430FR59xx
-----------------
/|\| XIN|-
| | | 32kHz
--|RST XOUT|-
| |
| P1.0 |--> LED
PROCEDURE:
1. Connect the MSP430FR5969 LaunchPad to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS to view the status of the
LED.
3. In the CCS debug perspective, select View --> Registers
4. Observe the GREEN LED blinks whenever timer overflows.
PROGRAM:
#include<msp430.h> intmain(void) { WDTCTL = WDTPW | WDTHOLD; // Stop WDT // Configure GPIO P1DIR |= BIT0; P1OUT |= BIT0; // Disable the GPIO power-on default high-impedance mode to activate // previously configured port settings PM5CTL0 &= ~LOCKLPM5; TA0CCTL0 = CCIE; // TACCR0 interrupt enabled TA0CCR0 = 20000;
TA0CTL = TASSEL__SMCLK | MC__UP; // SMCLK, UP mode __bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt __no_operation(); // For debugger } // Timer0_A0 interrupt service routine #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector = TIMER0_A0_VECTOR __interruptvoidTimer0_A0_ISR (void) #elif defined(__GNUC__) void__attribute__ ((interrupt(TIMER0_A0_VECTOR))) Timer0_A0_ISR (void) #else #error Compiler not supported! #endif { P1OUT ^= BIT0; }
RESULT:
4. PULSE WIDTH MODULATION
AIM:The main objective of this experiment is to understand how to configure the PWM module
of the MSP-EXP430FR5969 Launchpad to control the brightness of LED using external input.
APPARATUS REQUIRED:
● Code composer studio software
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
The MSP430FR5969 has two LED’s and two push BUTTONS connected to GREEN LED
(P1.0),S2(P1.1) and RED LED (P4.6),S1(P4.5) on the MSP430FR5969 LaunchPad for visual
feedback. In this experiment, the code programmed into the MSP430FR5969 processor increase
the brightness of LED when button is pressed gradually and decrease the brightness of LED
when another button is presses gradually.Actually here we are increasing and decreasing the
width of the pulse by varying the values in CCR1 of the Timer.
MSP430FR59xx
-----------------
/|\| XIN|-
| | | 32kHz
--|RST XOUT|-
| |
LED<--| P4.6 P1.0 |--> LED
S1←| P4.5 P1.1 |-->S2
-------------------
PROCEDURE:
1. Connect the MSP430FR5969 LaunchPad to the PC using the USB cable supplied.
2. Build, program and debug the code into the LaunchPad using CCS to view the status of the
LED.
3. In the CCS debug perspective, select View --> Registers
4. Observe the GREEN LED brightness increase whenever S1 is pressed and decreases when S2
is pressed.
PROGRAM:
#include<msp430.h> int j=0; intmain(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance //mode to activate previously configured port settings P1DIR |= BIT0; // Set P1.0 to output direction P1OUT &= ~BIT0; // Switch LED off P1DIR &= ~BIT1; // Set P1.1 as input P1OUT |= BIT1; // Configure P1.1 for Pull-Up P1REN |= BIT1; // Enable Pull Up of P1.1 P4DIR &= ~BIT5; // Set P4.5 as input
P4OUT |= BIT5; // Configure P4.5 for Pull-Up P4REN |= BIT5; // Enable Pull Up of P4.5 TA0CCTL1 = OUTMOD_7; // Reset/Set Mode TA0CTL = TASSEL_2 + MC_1 +TACLR ; // SMCLK / Upmode TA0CCR0 = 100-1; // PWM Frequency 10 kHz TA0CCR1 = 50; // 50% Duty Cycle P1SEL0 |= BIT0; // PWM output to LED P1.0 P1SEL1 &= ~BIT0; while(1) { if(!(P1IN & BIT1)) { if(TA0CCR1 <= 90) { TA0CCR0 = 0; TA0CCR1 += 10; TA0CCR0 = 100; } } elseif(!(P4IN & BIT5)) { if(TA0CCR1 >= 10) { TA0CCR0 = 0; TA0CCR1 -= 10; TA0CCR0 = 100; } } for(j=100;j>0;j--) { __delay_cycles(1000); } } }
RESULT:
5. INTERFACING POTENTIOMETER
AIM: The main objective of this experiment is to understand how to interface potentiometer and
control the state of LED based on potentiometer values.
APPARATUS REQUIRED:
● Code composer studio software
● MSP430FR5969 target Launchpad
● USB cable
● Potentiometer
THEORY:
A potentiometer is connected to the pin P1.3(A3) and LED is connected to P1.0. Software
sets ADC12SC to start sample and conversion - ADC12SC automatically cleared at EOC.
ADC12 internal oscillator times sample (16x) and conversion. In Main loop MSP430 waits in
LPM0 to save power until ADC12 conversion complete, ADC12_ISR will force exit from
LPM0 in Mainloop on reti. If Potentiometer value A3>=2048, P1.0 set(LED ON), else
reset(LED OFF). The full, correct handling of and ADC12 interrupt is shown as well.
Pin diagram
ADC12CTL0, ADC12 Control Register 0
ADC12CTL1, ADC12 Control Register 1
PROGRAM:
#include<msp430.h> intmain(void) { WDTCTL = WDTPW | WDTHOLD; // Stop WDT // GPIO Setup P1OUT &= ~BIT0; // Clear LED to start P1DIR |= BIT0; // Set P1.0/LED to output P1SEL1 |= BIT3; // Configure P1.3 for ADC P1SEL0 |= BIT3; // Disable the GPIO power-on default high-impedance mode to activate // previously configured port settings PM5CTL0 &= ~LOCKLPM5; // Configure ADC12 ADC12CTL0 = ADC12SHT0_2 | ADC12ON; // Sampling time, S&H=16, ADC12 on ADC12CTL1 = ADC12SHP; // Use sampling timer ADC12CTL2 |= ADC12RES_2; // 12-bit conversion results ADC12MCTL0 |= ADC12INCH_3; // A3 ADC input select; Vref=AVCC ADC12IER0 |= ADC12IE0; // Enable ADC conv complete interrupt while (1) { __delay_cycles(5000); ADC12CTL0 |= ADC12ENC | ADC12SC; // Start sampling/conversion __bis_SR_register(LPM0_bits | GIE); // LPM0, ADC12_ISR will force exit __no_operation(); // For debugger } } #pragma vector = ADC12_VECTOR __interrupt voidADC12_ISR(void) { switch(__even_in_range(ADC12IV, ADC12IV_ADC12RDYIFG)) { case ADC12IV_NONE: break; // Vector 0: No interrupt case ADC12IV_ADC12OVIFG: break; // Vector 2: ADC12MEMx Overflow case ADC12IV_ADC12TOVIFG: break; // Vector 4: Conversion time overflow case ADC12IV_ADC12HIIFG: break; // Vector 6: ADC12BHI case ADC12IV_ADC12LOIFG: break; // Vector 8: ADC12BLO case ADC12IV_ADC12INIFG: break; // Vector 10: ADC12BIN case ADC12IV_ADC12IFG0: // Vector 12: ADC12MEM0 Interrupt if (ADC12MEM0 >= 0x7ff) // ADC12MEM0 = A1 > 0.5AVcc? P1OUT |= BIT0; // P1.0 = 1 else P1OUT &= ~BIT0; // P1.0 = 0 __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU break; // Clear CPUOFF bit from 0(SR) case ADC12IV_ADC12IFG1: break; // Vector 14: ADC12MEM1 case ADC12IV_ADC12IFG2: break; // Vector 16: ADC12MEM2 case ADC12IV_ADC12IFG3: break; // Vector 18: ADC12MEM3 case ADC12IV_ADC12IFG4: break; // Vector 20: ADC12MEM4 case ADC12IV_ADC12IFG5: break; // Vector 22: ADC12MEM5
case ADC12IV_ADC12IFG6: break; // Vector 24: ADC12MEM6 case ADC12IV_ADC12IFG7: break; // Vector 26: ADC12MEM7 case ADC12IV_ADC12IFG8: break; // Vector 28: ADC12MEM8 case ADC12IV_ADC12IFG9: break; // Vector 30: ADC12MEM9 case ADC12IV_ADC12IFG10: break; // Vector 32: ADC12MEM10 case ADC12IV_ADC12IFG11: break; // Vector 34: ADC12MEM11 case ADC12IV_ADC12IFG12: break; // Vector 36: ADC12MEM12 case ADC12IV_ADC12IFG13: break; // Vector 38: ADC12MEM13 case ADC12IV_ADC12IFG14: break; // Vector 40: ADC12MEM14 case ADC12IV_ADC12IFG15: break; // Vector 42: ADC12MEM15 case ADC12IV_ADC12IFG16: break; // Vector 44: ADC12MEM16 case ADC12IV_ADC12IFG17: break; // Vector 46: ADC12MEM17 case ADC12IV_ADC12IFG18: break; // Vector 48: ADC12MEM18 case ADC12IV_ADC12IFG19: break; // Vector 50: ADC12MEM19 case ADC12IV_ADC12IFG20: break; // Vector 52: ADC12MEM20 case ADC12IV_ADC12IFG21: break; // Vector 54: ADC12MEM21 case ADC12IV_ADC12IFG22: break; // Vector 56: ADC12MEM22 case ADC12IV_ADC12IFG23: break; // Vector 58: ADC12MEM23 case ADC12IV_ADC12IFG24: break; // Vector 60: ADC12MEM24 case ADC12IV_ADC12IFG25: break; // Vector 62: ADC12MEM25 case ADC12IV_ADC12IFG26: break; // Vector 64: ADC12MEM26 case ADC12IV_ADC12IFG27: break; // Vector 66: ADC12MEM27 case ADC12IV_ADC12IFG28: break; // Vector 68: ADC12MEM28 case ADC12IV_ADC12IFG29: break; // Vector 70: ADC12MEM29 case ADC12IV_ADC12IFG30: break; // Vector 72: ADC12MEM30 case ADC12IV_ADC12IFG31: break; // Vector 74: ADC12MEM31 case ADC12IV_ADC12RDYIFG: break; // Vector 76: ADC12RDY default: break; } }
RESULT:
6. PWM BASED SPEED CONTROL OF MOTOR
AIM: The main objective of this experiment is to understand how to configure the PWM module
of the MSP-EXP430FR5969 Launchpad to control the brightness of LED using external input.
APPARATUS REQUIRED:
● Code composer studio software.
● MSP430FR5969 target Launchpad.
● USB cable.
● Potentiometer.
● DC motor.
THEORY:
A potentiometer is connected to the pin P1.3(A3) and DC MOTOR is connected to P1.2.
Timer operates in UP MODE with Reset/set(output MODE 7) and set the PWM frequency in
Capture/Compare register 1(CCR1). Software sets ADC12SC to start sample and conversion
- ADC12SC automatically cleared at EOC. ADC12 internal oscillator times sample (16x) and
conversion. In Main loop MSP430 waits in LPM0 to save power until ADC12 conversion
complete, ADC12_ISR will force exit from LPM0 in Mainloop on reti. Values of
potentiometer is stored in ADC memory. The Contents of ADC memory is assigned to
Capture/Compare register 0 (CCR0) which sets the duty cycle of the generated pulse. The
full, correct handling of and ADC12 interrupt is shown as well.
Pin diagram
ADC12CTL0, ADC12 Control Register 0
ADC12CTL1, ADC12 Control Register 1
PROGRAM:
#include<msp430.h> intmain(void) { WDTCTL = WDTPW | WDTHOLD; // Stop WDT // GPIO Setup P1OUT &= ~BIT2; // Clear MOTOR to start P1DIR |= BIT2; // Set P1.2/MOTOR to output P1SEL1 = BIT3; // Configure P1.3 for ADC P1SEL0 = BIT3 | BIT2; // PWM output to MOTOR P1.2 // Disable the GPIO power-on default high-impedance mode to activate // previously configured port settings PM5CTL0 &= ~LOCKLPM5; // Configure TimerA0 TA0CCTL1 = OUTMOD_7; // Reset/Set Mode TA0CTL = TASSEL_2 + MC_1 +TACLR ; // SMCLK / Upmode TA0CCR0 = 64-1; // PWM frequency // Configure ADC12 ADC12CTL0 = ADC12SHT0_2 | ADC12ON; // Sampling time, S&H=16, ADC12 on ADC12CTL1 = ADC12SHP; // Use sampling timer ADC12CTL2 |= ADC12RES_2; // 12-bit conversion results ADC12MCTL0 |= ADC12INCH_3; // A3 ADC input select; Vref=AVCC ADC12IER0 |= ADC12IE0; // Enable ADC conv complete interrupt while (1) { __delay_cycles(5000); ADC12CTL0 |= ADC12ENC | ADC12SC; // Start sampling/conversion __bis_SR_register(LPM0_bits | GIE); // LPM0, ADC12_ISR will force exit __no_operation(); // For debugger } } #pragma vector = ADC12_VECTOR __interrupt voidADC12_ISR(void) { switch(__even_in_range(ADC12IV, ADC12IV_ADC12RDYIFG)) { case ADC12IV_NONE: break; // Vector 0: No interrupt case ADC12IV_ADC12OVIFG: break; // Vector 2: ADC12MEMx Overflow case ADC12IV_ADC12TOVIFG: break; // Vector 4: Conversion time overflow case ADC12IV_ADC12HIIFG: break; // Vector 6: ADC12BHI case ADC12IV_ADC12LOIFG: break; // Vector 8: ADC12BLO case ADC12IV_ADC12INIFG: break; // Vector 10: ADC12BIN
case ADC12IV_ADC12IFG0: TA0CCR1 = ADC12MEM0/64; // Vector 12: ADC12MEM0 Interrupt __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU break; // Clear CPUOFF bit from 0(SR) case ADC12IV_ADC12IFG1: break; // Vector 14: ADC12MEM1 case ADC12IV_ADC12IFG2: break; // Vector 16: ADC12MEM2 case ADC12IV_ADC12IFG3: break; // Vector 18: ADC12MEM3 case ADC12IV_ADC12IFG4: break; // Vector 20: ADC12MEM4 case ADC12IV_ADC12IFG5: break; // Vector 22: ADC12MEM5 case ADC12IV_ADC12IFG6: break; // Vector 24: ADC12MEM6 case ADC12IV_ADC12IFG7: break; // Vector 26: ADC12MEM7 case ADC12IV_ADC12IFG8: break; // Vector 28: ADC12MEM8 case ADC12IV_ADC12IFG9: break; // Vector 30: ADC12MEM9 case ADC12IV_ADC12IFG10: break; // Vector 32: ADC12MEM10 case ADC12IV_ADC12IFG11: break; // Vector 34: ADC12MEM11 case ADC12IV_ADC12IFG12: break; // Vector 36: ADC12MEM12 case ADC12IV_ADC12IFG13: break; // Vector 38: ADC12MEM13 case ADC12IV_ADC12IFG14: break; // Vector 40: ADC12MEM14 case ADC12IV_ADC12IFG15: break; // Vector 42: ADC12MEM15 case ADC12IV_ADC12IFG16: break; // Vector 44: ADC12MEM16 case ADC12IV_ADC12IFG17: break; // Vector 46: ADC12MEM17 case ADC12IV_ADC12IFG18: break; // Vector 48: ADC12MEM18 case ADC12IV_ADC12IFG19: break; // Vector 50: ADC12MEM19 case ADC12IV_ADC12IFG20: break; // Vector 52: ADC12MEM20 case ADC12IV_ADC12IFG21: break; // Vector 54: ADC12MEM21 case ADC12IV_ADC12IFG22: break; // Vector 56: ADC12MEM22 case ADC12IV_ADC12IFG23: break; // Vector 58: ADC12MEM23 case ADC12IV_ADC12IFG24: break; // Vector 60: ADC12MEM24 case ADC12IV_ADC12IFG25: break; // Vector 62: ADC12MEM25 case ADC12IV_ADC12IFG26: break; // Vector 64: ADC12MEM26 case ADC12IV_ADC12IFG27: break; // Vector 66: ADC12MEM27 case ADC12IV_ADC12IFG28: break; // Vector 68: ADC12MEM28 case ADC12IV_ADC12IFG29: break; // Vector 70: ADC12MEM29 case ADC12IV_ADC12IFG30: break; // Vector 72: ADC12MEM30 case ADC12IV_ADC12IFG31: break; // Vector 74: ADC12MEM31 case ADC12IV_ADC12RDYIFG: break; // Vector 76: ADC12RDY default: break; } }
RESULT:
7. ULTRA LOW POWER (ULP) ADVISOR
AIM:The main objective of this experiment is to optimize the power efficiency of an application
on MSP- EXP430FR Launchpad using ULP Advisor in CC Studio. This experiment will help to
learn and understand the ULP Advisor capabilities and usage of ULP Advisor to create
optimized, power-efficient applications on the MSP-EXP430FR Launchpad.
APPARATUS REQUIRED:
● Code composer studio software
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
ULP (Ultra-Low Power) Advisor is a tool that provides advice on how to improve the
energy efficiency of an application based on comparing the code with a list of ULP rules at
compile time. The ULP Advisor helps the developer to fully utilize the ULP capabilities of
MSP430 microcontrollers, This tool works at build time to identify possible areas where
energy and power use is inefficient. A description of the ULP rule that is violated, a link to
the ULP Advisor wiki page, links to relevant documentation, code examples and forum posts
are all included for each rule violation in the application code. Once the feedback has been
presented, the developer can then learn more about the violation and go back to edit the code
for increased power efficiency or continue to run the code as-is. The ULP Advisor is built
into Code Composer StudioTM IDE version 5.2 and newer. After compiling the code, a list
of the ULP rule violations is provided in the Advice window. Unlike errors, these suggestions
will not prevent the code from successfully compiling and downloading onto the target.A list
of some unique rule violations are shown in Table 7-1.
This experiment explains in detail how to use ULP Advisor on MSP430FR5969.
Three code files are used in this experiment and one file is included in the build at a time.
Each file performs the same function: every second an Analog-to-Digital Converter (ADC)
temperature measurement is taken,the degrees Celsius and Fahrenheit are calculated, and the
results are sent through the back channel Universal Asynchronous Receiver/Transmitter
(UART) at 9600bps.
The first code file - Inefficient.c, begins with an inefficient implementation of this
application. The ULP Advisor is used to observe the extreme inefficiency of this version.
Based on the feedback from the ULP Advisor,improvements are made for the somewhat
efficient second version of the code - Efficient.c. The process is repeated, and ULP Advisor is
used to compare this improved version with the original. Finally, steps are taken to improve
the code even further in the very efficient third version of the code - MostEfficient.c. Table 7-
2 briefs the descriptions of the experiment code
Table 7-1 : ULP Rule Violations
Table 7-2 : Experiment Code Descriptions
PROCEDURE:
1. Connect the MSP-EXP430FR LaunchPad to the PC using the USB cable supplied.
2. Download the CCS example project ULP_Case_Study from http://www.ti.com/lit/zip/slaa603
and extract using 7zip.
3. Import the project into your CCS workspace as shown in Figure 7-1.
a. Click Project Import Existing CCS Eclipse Project.
b. Browse the directory for the downloaded file.
c. Check the box next to the ULP_Case_Study project in the Discovered projects window.
d. Uncheck the check box Copy projects into workspace.
e. Click Finish
Figure 7-1 : Importing Project
4. To set as active project, click on the project name. The active build configuration should be
Inefficient. If not, right click on the project name in the Project Explorer, then click Build
Configurations Set Active Inefficient as shown in Figure 7-2.
Figure 7-2: Selection of Build Configuration
5. Build the project
6. The Advice window shows suggestions from the ULP Advisor under the Power (ULP) Advice
heading. Click View Advice as shown in Figure 7-3.
Figure 7-3 Opening the Advice Window
The Advice window appears as shown in Figure 7-4.
Figure 7-4: Advice Window
7. Click the link #1532-D, which corresponds to the first ULP violation (for using sprintf()), to
open the ULP Advisor wiki page in a second Advice tab. All the information for this particular
rule violation is provided as shown in Figure 7-5.
8. Scroll down to the Remedy section. Here, the first suggestion is to avoid using sprintf()
altogether and work with the raw data.
Figure 7-5 ULP Advisor Wiki Page
Observation
In the ULP Advisor of Inefficient.c, the first suggestion given is to avoid using sprintf(). The
ULP Advisor implements the advice for the next version of code i,e., Efficient.c as shown in
Figure 7-6.
Figure 7-6 ULP Advice Window for Effiecient.c
There are no advices related to Power optimization in ULP Advisor of MostEfficient.c, as shown
inFigure 7-7 below
Figure 7-7 ULP Advice Window for MostEffiecient.c
RESULT:
8. ENERGY TRACE++ANDESTIMATION OF BATTERY LIFE
AIM:The main objective of this experiment is to compute the total energy of MSP-EXP430FR
Launchpad running an application and to estimate the lifetime of a battery.
APPARATUS REQUIRED:
● Code composer studio software
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
To measure the total energy of the MSP-EXP430FR and estimated life time of a battery the
Energy Trace Technology is must and should. Energy Trace Technology is an energy-based code
analysis tool that measures and displays the application's energy profile and helps to optimize it
for ultra-low power consumption. MSP430 devices with built-in Energy Trace+ [CPU State]+
[Peripheral States] (or in short, Energy Trace++™) technology allow real-time monitoring of
many internal device states while user program code executes. Energy Trace++ technology is
supported on selected MSP430 devices and debuggers.
To achieve this, the on-board emulation of a Launchpad that contains the Energy Trace
technology circuitry is used to program and debug the intended target. In this experiment, to
program and debug we use the MSP-EXP430FR5969 Launchpad which contains the Energy
Trace Technology on-board circuitry. When the Energy Trace mode is enabled in the target
device, the profile window shows some statistical data about the application that has been
profiled. The following are the parameters shown in the profile window:
• Captured time
• Total energy consumed by the application (in mJ)
• Minimum, mean, and maximum power (in mW)
• Mean voltage (in V)
• Minimum, mean, and maximum current (in mA)
• Estimated life time of the selected battery (in days) for the captured energy profile
PROCEDURE:
1. Build the example code of Experiment 2: Low Power Modes and Current Measurement for
which you want to compute the total energy and estimate the life time of a battery using Energy
Trace technology.
2. Enable Energy Trace technology
• Click Window -->Preferences -->Code Composer Studio-->Advanced Tools→ Energy
Trace Technology
• Make sure that the box next to Enable is checked
• Select the Energy Trace++ mode
• Click Apply and OK.
3. Debug the example code, the Energy Trace window will open automatically. If the window
does not open automatically, click View-->Others -->MSP430 Energy Trace -->Energy
Trace Technology
4. Run the code. The Energy Trace Technology window will update the real time data.
Observation
Figure 8-1 Energy Trace Profile Window in Active Mode
The Energy trace profile for active and stand by code is analyzed using Energy Trace
technology. The Energy Trace profile window of the application in active mode provides us the
estimated lifetime of a battery of 35.9 days. If the same application run in standby mode, the
estimated lifetime of a battery exceeds to 94.3 days
The formula to calculate the battery lifetime assumes an ideal 3-V battery and does not
account for temperature, aging, peak current and other factors that could negatively affect battery
capacity. Figure 8-1 and Figure 8-2 show the Energy Trace Profile windows for the application in
active and standby modes respectively.
Figure 8-2 Energy Trace Profile Window in Standby Mode
RESULT:
ADDITIONAL EXPERIMENTS
1. TEMPERATURE SENSING
AIM:The main objective of this experiment is to interface Temperature sensor to
MSP430FR5969 Launchpad and give the signal whenever temperature reaches certain value.
APPARATUS REQUIRED:
● Energia IDE
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
The MSP430FR5969 has two LED’s and two push BUTTONS connected to GREEN LED
(P1.0), S2(P1.1) and RED LED (P4.6),S1(P4.5) on the MSP430FR5969 LaunchPad for visual
feedback. In this experiment, the code programmed into the MSP430FR5969 processor to blink
RED LED whenever temperature exceeds 100 (Temperature sensor is connected to P4.2-in
Energia it will take as pin A10). In this experiment we are Energia IDE which is used to dump
the program.
MSP430FR59xx
-----------------
/|\| XIN|-
|| | 32kHz
--|RST XOUT|-
TEMPERATURE sensor |P4.2 | P1.3
LED<--| P4.6 P1.0 |--> LED
S1←| P4.5 P1.1|-->S2
-------------------
PROCEDURE:
1. Connect the MSP430FR5969 LaunchPad to the PC using the USB cable supplied.
2. Select the Microcontroller board and communication Port which you have connected to PC.
3. Save the program and compile it.
4. Once compiling is done successfully then Upload the program to board.
5. Observe the Temperature readings in ”Serial Monitor” window in Energia IDE also increase
the temperature to blink LED when value reaches 100.
PROGRAM:
#define LED RED_LED//choosing which LED we want to use intTempSensorValue=0;//initialize sensor value to zero voidsetup() { Serial.begin(9600);//begin the serial communication pinMode(A10,INPUT);//defining Temperature sensor is input pinMode(LED,OUTPUT);//defining led as output }
voidloop() { int value=analogRead(A10); //read value from sensor (here temperature sensor is analog) TempSensorValue = value/4;//divide by 4 to get the values in 0-255 range (default 0-1023) Serial.println(TempSensorValue); //print the sensor value in serial monitor if(TempSensorValue>100) { digitalWrite(LED,HIGH); //turn ON LED when temperature exceeds 100 Serial.println("Temperature="+TempSensorValue); //print sensor value in serial monitor } else { digitalWrite(LED,LOW);//turn OFF LED when temperature is less than 100 } }
OBSERVATION:
RESULT:
2. MOTION DETECTION
AIM:The main objective of this experiment is to interface Motion sensor to MSP430FR5969
Launchpad and give the signal whenever any Motion is detected.
APPARATUS REQUIRED:
● Energia IDE
● MSP430FR5969 target Launchpad
● USB cable
THEORY:
The MSP430FR5969 has two LED’s and two push BUTTONS connected to GREEN LED
(P1.0), S2(P1.1) and RED LED (P4.6),S1(P4.5) on the MSP430FR5969 LaunchPad for visual
feedback. In this experiment, the code programmed into the MSP430FR5969 processor to blink
GREEN LED whenever motion is detected (Motion sensor is connected to P1.3-in Energia it will
take as pin11). In this experiment we are Energia IDE which is used to dump the program.
MSP430FR59xx
-----------------
/|\| XIN|-
| | | 32kHz
--|RST XOUT|-
| P1.3|-Motion sensor
LED<--| P4.6 P1.0 |--> LED
S1←| P4.5 P1.1 |-->S2
-------------------
PROCEDURE:
1. Connect the MSP430FR5969 LaunchPad to the PC using the USB cable supplied.
2. Select the Microcontroller board and communication Port which you have connected to PC.
3. Save the program and compile it.
4. Once compiling is done successfully then Upload the program to board.
5. Observe the readings in ”Serial Monitor” window in Energia IDE also move around motion
sensor to blink LED.
PROGRAM:
#define LED GREEN_LED//choosing which LED we want to use voidsetup() { Serial.begin(9600);//begin the serial communication pinMode(11,INPUT);//defining motion sensor is input pinMode(LED,OUTPUT);//defining led as output } voidloop() { inti=digitalRead(11);//read the value from sensor(here motion sensor is digital) Serial.println(i);//print the sensor value in serial monitor if(i==1) {
digitalWrite(LED,HIGH);//turn ON LED when motion is detected Serial.println("Motion is Detected"); } else { digitalWrite(LED,LOW);//turn OFF LED when motion is not detected } }
OBSERVATION:
RESULT: