Anda di halaman 1dari 87

MICRO PROCESSORS & MICROCONTROLLERS

LAB MANUAL

BATCH (R15)

III-B.Tech (ECE & EEE), II- SEM

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

Prepared by:
G.Ramanjaneya Reddy
O.Mohana Chandrika

GOUTHAMI INSTITUTE OF TECHNOLOGY & MANAGEMENT FOR WOMEN


(Approved by AICTE, NewDelhi, Affiliated to JNTUA,Ananthapuram)
Sai Nagar, Peddasettypalli(V), Proddatur, Kadapa(Dt), A.P – 516361.

GITAMW/ECE 1
(15A04607) MICROPROCESSORS AND MICROCONTROLLERS LABORATORY
Part A : 8086 Microprocessor Programs using MASM/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.

GITAMW/ECE 2
Procedure for to run MASM on windows 7:
1. Switch on the computer.
2. Double click on dosbox
3. Type mount c c:\8086 and then enter
4. Type c: and then enter.
5. Type “edit” & press “enter” button
6. Type the program & select “file ->save as”
7. Save the file with an exetenxion “.asm”,(ex1.asm)
8. Select “file->exit”
9. Type the command “masm programname.asm” & press enter 4 times.
10. Check if any errors / warnings are there in your program ..if any errors are there modify
the program by giving the command ”edit programname.asm”
11. Again save the program.
12. Repeat step 9 until you get 0 errors & 0 warnings.
13. Then type the command “link programname.obj” (ex1.obj) & press enter 4 times
14. Then type the command “debug programname.exe”(ex1.exe) & press enter.
15. Give the command ” u “ to note the address & opcode of program.
16. give the command ” t“ to check the registers update after each & every instruction
execution. repeat this process until the program ends.
17. If the result is in memory location give the command “d ds:0000”
18. To quit from debugging mode type the command “q”
19. Repeat the same process from step 5 to execute the next program.

GITAMW/ECE 3
1. ARITHMETIC OPERATIONS

AIM:-

To perform arithmetic operations such as addition, subtraction, multiplication, division, signed


&unsigned operations,1’s complement and 2’s complement for a given numbers using MASM.

APPARATUS:-

Computer system with MASM software.

THEORY:-

PROCEDURE:-

1. Edit the program using EDIT.FILENAME.ASM in the MASM DIRECTORY.


2. Write the program code, save the file and go to exit in the file menu.
3. Source file as to be converted into object file using MASM file name.asm command.
4. Once the OBJ File is generated send the OBJ File to the linker in order to generate the
EXE.file this can be done with LINK file filename.obj command.
5. Debugging program using debug file filename.exe command.
6. Execute the program line by line using T command or at once by using G command.
7. Check the memory contents using D000 command.

1)16-BIT ADDITION:-

ASSUME CS: CODE, DS:DATA

DATA SEGMENT

A DW 2228H

B DW 2210H

RESULT DW ?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

GITAMW/ECE 4
MOV DS, AX

MOV AX, A

MOV BX, B

CLC

ADD AX, BX

MOV DI, OFFSET RESULT

MOV [DI], DX

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 28H

0B8B:0001 22H

0B8B:0002 10H

0B8B:0003 22H

OUTPUT:- ADDRESS DATA

0B8B:0004 38H

0B8B:0005 44H

2) 16-BIT SUBTRACTION:-

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

A DW 6668H

B DW 4428H

RESULTS DW?

DATA ENDS

CODE SEGMENT

GITAMW/ECE 5
START: MOV AX, DATA

MOV DS, AX

MOV AX, A

MOV BX, B

CLC

SUB AX, BX

MOV DI, OFFSET RESULT

MOV [DI], DX

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 68H

0B8B:0001 66H

0B8B:0002 28H

0B8B:0003 44H

OUTPUT:- ADDRESS DATA

0B8B:0004 40H

0B8B:0005 22H

3)16-BIT MULTIPLICATION:-

ASSUME CS: CODE, DS:DATA

DATA SEGMENT

A DW 2222H

B DW 0101H

RESULTS DW ?

DATA ENDS

GITAMW/ECE 6
CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AX, A

MOV BX, B

CLC

MUL AX, BX

MOV DI, OFFSET RESULT

MOV [DI],DX

INT 03H

CODE ENDS

ENDS START

INPUT:- ADDRESS DATA

0B8B:0000 22H

0B8B:0001 22H

0B8B:0002 45H

0B8B:0003 45H

OUTPUT:-ADDRESS DATA

0B8B:0004 22H

0B8B:0005 44H

0B8B:0006 22H

0B8B:0007 00H

GITAMW/ECE 7
4)16-BIT DIVISION:-

ASSUME CS:CODE, DS:DATA

DATA SEGMENT

A DW 8888H

B DW 2222H

RESULTS DW ?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AX, A

MOV BX, B

CLC

DIV AX, BX

MOV DI, OFFSET RESULT

MOV [DI], DX

INT 03H

CODE ENDS

ENDS START

INPUT:- ADDRESS DATA

0B8B:0000 88H

0B8B:0001 88H

0B8B:0002 22H

0B8B:0003 22H

GITAMW/ECE 8
OUTPUT:-ADDRESS DATA

0B8B:0004 04H

0B8B:0005 00H

0B8B:0006 00H

0B8B:0007 00H

5) 1’S COMPLIMENT:-

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

A DW 1234H

RESULT DW?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AX, A

CLC

NOT AX

MOV DI, OFFSET RESULT

MOV [DI], AX

INT 03H

CODE ENDS

ENDS START

INPUT:- ADDRESS DATA

0B8B:0000 12H

0B8B:0001 34H

OUTPUT:- ADDRESS DATA

GITAMW/ECE 9
0B8B:0002 EDH

0B8B:0003 CBH

6)2’S COMPLEMENT:-

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

A DW 5432H

RESULTS DW ?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AX, A

CLC

NOT AX

ADD AX, 01H

INC DI

MOV DI, OFFSET RESULT

MOV [DI], AX

INT 03H

CODE ENDS

ENDS START

GITAMW/ECE 10
INPUT:- ADDRESS DATA

0B8B:0000 54H

0B8B:0001 32H

OUTPUT:- ADDRESS DATA

0B8B:0002 ABH

0B8B:0003 CEH

RESULT:-The arithmetic operations are executed by using MASM software

GITAMW/ECE 11
1.b. LOGICAL OPERATIONS

Aim:-

1.To perform logical operations like AND,OR,NOT, XOR,NAND,SHR,


SHL,SAR,SAL,ROR,ROL, RCR, RCL operations.

Apparatus:-

Computer system with MASM software.

THEORY:-

Procedure:-

1. Edit the program using EDIT.FILENAME.ASM in the MASM DIRECTORY


2. Write the program code, save the file and go to exit in the file menu
3. Source file as to be converted into object file using MASM file name.asm command
4. Ones the OBJ FILE is generated send the OBJ FILE to the linker in order to generate the
EXE.file this can be done with LINK file name.obj; command
5. Debugging program using debug file name.exe, command
6. Excute the program line by line using T command or at once by using command
7. Check the memory contents using D000 command

PROGRAMS:

AND OPERATION

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

OPR1 DW 8642H

OPR2 DW 4286H

RESULT DW (?)

DATA ENDS

CODE SEGMENT

START: MOV AX,DATA

MOV DS,AX

GITAMW/ECE 12
MOV AX, OPR1

MOV BX, OPR2

CLC

AND AX, BX

MOV DI, OFFSET RESULT

MOV [DI], AX

INT 03H

CODE ENDS

END START

INPUT: - ADDRESS DATA

0B8B:0000 42H

0B8B:0001 86H

0B8B:0002 86H

0B8B:0003 42H

OUTPUT:- ADDRESS DATA

0B8B:0004 02H

0B8B:0005 02H

LOGICAL OR OPERATION:

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

OPR1 DW 4521H

OPR2 DW 5432H

RESULT DW?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

GITAMW/ECE 13
MOV DS, AX

MOV AX, OPR1

MOV BX, OPR2

CLC

OR AX, BX

MOV DI, OFFSET RESULT

MOV [DI], AX

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 42H

0B8B:0001 86H

0B8B:0002 86H

0B8B:0003 42H

OUTPUT:- ADDRESS DATA

0B8B:0004 C4H

0B8B:0005 C4H

LOGICAL XOR OPERATION

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

OPR1 DW 8642H

OPR2 DW 4286H

RESULT DW?

DATA ENDS

CODE SEGMENT

GITAMW/ECE 14
START: MOV AX, DATA

MOV DS, AX

MOV AX, OPR1

MOV BX, OPR2

CLC

XOR AX, BX

MOV DI, OFFSET RESULT

MOV [DI], AX

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 42H

0B8B:0001 86H

0B8B:0002 86H

0B8B:0003 42H

OUTPUT:- ADDRESS DATA

0B8B:0004 C4H

0B8B:0005 C4H

LOGICAL NOT OPERATION

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

OPR DW 8642H

GITAMW/ECE 15
RESULT DW?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AX, OPR

CLC

NOT AX

MOV DI, OFFSET RESULT

MOV [DI], AX

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 42H

0B8B:0001 86H

OUTPUT:- ADDRESS DATA

0B8B:0000 BDH

0B8B:0001 79H

LOGICAL NAND OPERATION

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

OPR1 DW 4286H

OPR2 DW 8642H

GITAMW/ECE 16
RESULT DW ?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AX, OPR1

MOV BX, OPR2

CLC

NAND AX, BX

MOV DI, OFFSET RESULT

MOV [DI], AX

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 42H

0B8B:0001 86H

0B8B:0002 86H

0B8B:0003 42H

OUTPUT:- ADDRESS DATA

0B8B:0004 C4H

0B8B:0005 C4H

LOGICAL SHL OPERATION

ASSUME CS; CODE, DS: DATA

GITAMW/ECE 17
DATA SEGMENT

OPR1 DW 4286H

COUNT DB 01H

RESULT DW(?)

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AX, OPR1

MOV CL, COUNT

CLC

SHL AX, CL

MOV DI, OFFSET RESULT

MOV [DI], AX

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 86H

0B8B:0001 42H

0B8B:0002 01H

OUTPUT:- ADDRESS DATA

0B8B:0003 0CH

0B8B:0004 85H

GITAMW/ECE 18
LOGICAL SHR OPERATION

ASSUME CS; CODE, DS: DATA

DATA SEGMENT

OPR1 DW 4286H

COUNT DB 01H

RESULT DW(?)

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AX, OPR1

MOV CL, COUNT

CLC

SHR AX, CL

MOV DI, OFFSET RESULT

MOV [DI], AX

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 86H

0B8B:0001 42H

0B8B:0000 01H

OUTPUT:- ADDRESS DATA

0B8B:0003 43H

GITAMW/ECE 19
0B8B:0004 21H

LOGICAL SAR OPERATION

ASSUME CS; CODE, DS: DATA

DATA SEGMENT

OPR1 DW 8642H

COUNT DB 02H

RESULT DW (?)

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AX, OPR1

MOV CL, COUNT

CLC

SAR AX, CL

MOV DI, OFFSET RESULT

MOV [DI], AX

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 86H

0B8B:0001 42H

0B8B:0000 02H

OUTPUT:- ADDRESS DATA

GITAMW/ECE 20
0B8B:0003 A1H

0B8B:0004 10H

LOGICAL SAL OPERATION

ASSUME CS; CODE, DS: DATA

DATA SEGMENT

OPR1 DW 8642H

COUNT DB 02H

RESULT DW(?)

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AX, OPR1

MOV CL, COUNT

CLC

SAL AX, CL

MOV DI, OFFSET RESULT

MOV [DI], AX

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 86H

0B8B:0001 42H

0B8B:0000 02H

OUTPUT:- ADDRESS DATA

GITAMW/ECE 21
0B8B:0003 18H

0B8B:0004 0AH

LOGICAL ROL OPERATION

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

OPR1 DW 8642H

COUNT DB 02H

RESULT DW?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AX, OPR1

MOV CL, COUNT

CLC

ROL AX, CL

MOV DI, OFFSET RESULT

MOV [DI], AH

MOV [DI], AL

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 86H

0B8B:0001 42H

GITAMW/ECE 22
0B8B:0000 02H

OUTPUT:- ADDRESS DATA

0B8B:0003 19H

0B8B:0004 0AH

LOGICAL ROR OPERATION

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

OPR1 DW 4286H

COUNT DB 02H

RESULT DW ?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AX, OPR1

MOV CL, COUNT

CLC

ROR AX, CL

MOV DI, OFFSET RESULT

MOV [DI], AH

MOV [DI], AL

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 86H

GITAMW/ECE 23
0B8B:0001 42H

0B8B:0000 02H

OUTPUT:- ADDRESS DATA

0B8B:0003 18H

0B8B:0004 0AH

LOGICAL RCL OPERATION

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

OPR1 DW 4286H

COUNT DB 02H

RESULT DW ?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AX, OPR1

MOV CL, COUNT

CLC

RCL AX, CL

MOV DI, OFFSET RESULT

MOV [DI], AH

MOV [DI], AL

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

GITAMW/ECE 24
0B8B:0000 86H

0B8B:0001 42H

0B8B:0000 02H

OUTPUT:- ADDRESS DATA

0B8B:0003 18H

0B8B:0004 0AH

LOGICAL RCR OPERATION

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

OPR1 DW 4286H

COUNT DB 02H

RESULT DW ?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AX, OPR1

MOV CL, COUNT

CLC

RCR AX, CL

MOV DI, OFFSET RESULT

MOV [DI], AH

MOV [DI], AL

INT 03H

CODE ENDS

END START

GITAMW/ECE 25
INPUT: - ADDRESS DATA

0B8B:0000 86H

0B8B:0001 42H

0B8B:0000 02H

OUTPUT:- ADDRESS DATA

0B8B:0003 A1H

0B8B:0004 10H

GITAMW/ECE 26
2. STRING OPERATIONS

AIM:-

To write a program for performing string operations using MASM .

APPARATUS:-

Computer system with MASM software

PROCEDURE:-

1. Edit the program using EDIT.FILENAME.ASM in the MASM DIRECTORY.


2. Write the program code, save the file and go to exit in the file menu.
3. Source file as to be converted into object file using MASM file name.asm command.
4. Once the OBJ FILE is generated send the OBJ FILE to the linker in order to generate the
EXE.file this can be done with LINK file filename.obj command.

5. Debugging program using debug file filename.exe command.

6. Execute the program line by line using T command or at once by using G command.

MOVE A STRING

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

STR DB 12H, 13H, 14H, 15H

COUNT DB 04H

B DB?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV SI, 0000H

MOV DI, OFFSET B

GITAMW/ECE 27
L1: MOV AL, [SI]

MOV [DI], AL

INC SI

DEC DI

LOOP L1

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 12H

0B8B:0001 13H

0B8B:0002 14H

0B8B:0003 15H

0B8B:0004 04H

OUTPUT:- ADDRESS DATA

0B8B:0005 12H

0B8B:0006 13H

0B8B:0007 14H

0B8B:0008 15H

Length of String

ASSUME CS: CODE,DS:DATA

DATA SEGMENT

A DB 12H, 09H, 03H, 10H, 0FFH

C DB?

DATA ENDS

CODE SEGMENT

GITAMW/ECE 28
START: MOV AX, DATA

MOV DS, AX

MOV SI, OFFSET A

MOV DX, 0FFFFH

MOV AH, 0FFH

L1: INC DX

MOV AL, [SI]

INC SI

CMP AH, AL

JNZ L1

INT 03H

CODE ENDS

END START

INPUT:- ADDRES DATA

0B8B:0000 12H

0B8B:0001 13H

0B8B:0002 14H

0B8B:0003 FFH

OUTPUT:- ADDRESS DATA

0B8B:0004 03H

COMARISION OF A STRING

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

GITAMW/ECE 29
STR1 DB 11H, 12H, 13H, 54H

STR2 DB 51H, 12H, 13H, 54H

COUNT DB 03H

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AX, DATA

MOV ES, AX

MOV SI, OFFSET STR1

MOV DI, OFFSET STR2

MOV CL, COUNT

CLD

REPE CMPSB

JNZ L1

MOV DX, 0000H

JMP L2

L1: MOV DX, 0001H

L2: MOV AH, 4CH

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 11H

0B8B:0002 12H

0B8B:0003 13H

GITAMW/ECE 30
0B8B:0004 54H

0B8B:0005 12H

0B8B:0006 13H

0B8B:0007 54H

0B8B:0008 04H

OUTPUT:- ADDRESS DATA

0B8B:0009 01H

0B8B:000A 00H

ASCENDING ORDER

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

STR DB 10H, 12H, 14H, 16H

COUNT DB 04H

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AX, 0000H

MOV DL, COUNT

L2: MOV CL, DL

MOV SI, OFFSET STR

L1: MOV AL, [SI]

CMP AL, 01[SI]

JL L3

XCHG AL, 01[SI]

MOV [SI], AL

GITAMW/ECE 31
L3: INC SI

LOOP L1

DEC DI

JNZ L2

INT 03H

CODE ENDS

END START

INPUT: - ADDRESS DATA

0B8B:0000 10H

0B8B:0001 12H

0B8B:0002 14H

0B8B:0003 16H

0B8B:0004 04H

OUTPUT:-ADDRESS DATA

0B8B:0005 10H

0B8B:0006 12H

0B8B:0007 14H

0B8B:0008 16H

DESCENDING ORDER

ASSUME CS: CODE, DS:DATA

DATA SEGMENT

STR DB 44H, 94H, 19H, 38H

COUNT EQU 05

RESULT DB?

GITAMW/ECE 32
DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AX, 0000H

MOV DL, COUNT-1

L2: MOV CL, DX

MOV SI, OFFSET STR

L1: MOV AL, [SI]

CMP AL, [SI+1]

JG L3

XCHG [SI+1], AL

XCHG [SI], AL

L3: INC SI

LOOP L1

DEC DL

JNZ L2

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 10H

0B8B:0001 12H

0B8B:0002 14H

0B8B:0003 16H

0B8B:0004 04H

GITAMW/ECE 33
OUTPUT:- ADDRESS DATA

0B8B:0005 16H

0B8B:0006 14H

0B8B:0007 12H

0B8B:0008 10H

REVERSE A STRING

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

STR DB 23H, 24H, 25H, 26H

RESULT DB?

COUNT EQU 04H

DATA ENDS

CODE SEGMENT

START: MOV AX,DATA

MOV DS,AX

MOV SI, OFFSET STR

MOV DI, OFFSET RESULT

MOV CL, COUNT

MOV DL, CL

L1: MOV AL, [SI]

PUSH AX

INC SI

DEC DL

JNZ L1

AGAIN: POP AX

MOV [DI], AX

GITAMW/ECE 34
INC DI

DEC DL

JNZ AGAIN

INT 03H

(OR)

ASSUME CS: CODE, DS:DATA

DATA SEGMENT

STR DB 54H, 44H, 23H, 12H

COUNT DB 04H

B DB?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV SI, 0000H

MOV DI, OFFSET B

L1: MOV AL, [SI]

MOV [DI], AL

INC SI

DEC DI

LOOP L1

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 23H

GITAMW/ECE 35
0B8B:0001 24H

0B8B:0002 25H

0B8B:0003 26H

0B8B:0004 04H

OUTPUT:- ADDRESS DATA

0B8B:0005 26H

0B8B:0006 25H

0B8B:0007 24H

0B8B:0008 23H

DISPLAY STRING

ASSUME CS: CODE, DS:DATA

DATA SEGMENT

OPR1 DB 0DH, 0AH,"SREC", 0DH,0AH,"$"

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV AH, 09H

MOV DX, OFFSET OPR1

INT 21H

MOV AH, 4CH

INT 21H

CODE ENDS

END START

INPUT:- ADDRESS DATA

GITAMW/ECE 36
0B8B:0000 0DH

0B8B:0001 0AH

0B8B:0002 SRECH

0B8B:0003 0DH

0B8B:0004 0AH

0B8B:0005 “ $”

OUTPUT:- ADDRESS DATA

0B8B:0006 SREC

RESULT:-The string operations are executed by using MASM software

SORTING USING MASM

DATA SEGMENT
STRING1 DB 99H,12H,56H,45H,36H
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX

MOV CH,04H

UP2: MOV CL,04H


LEA SI,STRING1

UP1: MOV AL,[SI]


MOV BL,[SI+1]
CMP AL,BL
JC DOWN
MOV DL,[SI+1]
XCHG [SI],DL
MOV [SI+1],DL

DOWN: INC SI
DEC CL
JNZ UP1
DEC CH

GITAMW/ECE 37
JNZ UP2

INT 3
CODE ENDS
END START

GITAMW/ECE 38
3.Code Conversions

. To perform PACKED BCD to unpacked BCD and PACKED BCD to ASCII conversion.

Apparatus:-

Computer system with MASM software.

THEORY:-

Procedure:-

1. Edit the program using EDIT.FILENAME.ASM in the MASM DIRECTORY


2. Write the program code, save the file and go to exit in the file menu
3. Source file as to be converted into object file using MASM file name.asm command
4. Ones the OBJ FILE is generated send the OBJ FILE to the linker in order to generate the
EXE.file this can be done with LINK file name.obj; command
5. Debugging program using debug file name.exe, command
6. Excute the program line by line using T command or at once by using command
7. Check the memory contents using D000 command

PACKED BCD TO UN PACKED BCD

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

COUNT DW 04H

OPR1 DW 84H

RESULT DW?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV SI, OFFSET OPR1

GITAMW/ECE 39
MOV AL, [SI]

MOV AH, AL

MOV CL, COUNT

AND AL, 0FH

AND AH, 0F0H

CLC

ROR AH, CL

MOV DI, OFFSET RESULT

MOV [DI], AL

INC DI

MOV [DI], AH

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 84H

0B8B:0001 04H

OUTPUT:- ADDRESS DATA

0B8B:0000 04H

0B8B:0001 08H

PACKED BCD TO ASCII NUMBER

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

COUNT DW 04H

OPR1 DW 84H

GITAMW/ECE 40
RESULT DW ?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV SI, OFFSET OPR1

MOV AL, [SI]

MOV AH, AL

MOV CL, COUNT

AND AL, 0FH

AND AH, 0F0H

CLC

ROR AH, CL

MOV DI, OFFSET RESULT

MOV [DI], AL

INC DI

MOV [DI], AH

OR AX, 3030H

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B8B:0000 84H

0B8B:0001 04H

OUTPUT:- ADDRESS DATA

0B8B:0000 38H

GITAMW/ECE 41
0B8B:0001 34H

RESULT:- The conversions(PACKED TO UNPACKED BCD,PACKED BCD TO ASCII ) are


executed by using MASM software.

GITAMW/ECE 42
4. MULTI BYTE OPERATIONS

AIM:-

To perform multi byte operations such as addition, subtractions of two bytes/16-bit length
number using MASM.

APPARATUS:-

Computer system with MASM software.

THEORY:-

PROCEDURE:-

1. Edit the program using EDIT.FILENAME.ASM in the MASM DIRECTORY.


2. Write the program code, save the file and go to exit in the file menu.
3. Source file as to be converted into object file using MASM file name.asm command.
4. Once the OBJ FILE is generated send the OBJ FILE to the linker in order to generate the
EXE.file this can be done with LINK file filename.obj command.
5. Debugging program using debug file filename.exe command.
6. Execute the program line by line using T command or at once by using G command.
7. Check the memory contents using D000 command.

1) MULTIBYTE 16-BIT ADDITION:-

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

A DW 0030H, 0022H

B DW 0040H, 0024H

COUNT DW 02H

RESULT DW ?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

GITAMW/ECE 43
MOV DS, AX

MOV SI, OFFSET A

MOV DI, OFFSET B

MOV BX, OFFSET RESULT

MOV CX, COUNT

L1: MOV AH, [SI]

MOV DH, [DI]

ADD AH, DH

MOV [BX], AH

INC SI

INC SI

INC DI

INC DI

INC BX

INC BX

LOOP L1

INT 03H

CODE ENDS

END START

INPUT: - ADDRESS DATA

0B8B:0000 00H

0B8B:0001 30H

0B8B:0002 00H

0B8B:0003 22H

0B8B:0004 00H

GITAMW/ECE 44
0B8B:0005 40H

0B8B:0006 00H

0B8B:0007 24H

0B8B:0008 02H

OUTPUT:-ADDRESS DATA

0B8B:0009 00H

0B8B:000A 70H

0B8B:000B 00H

0B8B:000C 46H

2)16-SUBTRACTION:-

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

A DW 0040H, 0024H

B DW 0030H, 0022H

COUNT DW 02H

RESULTS DW ?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

MOV SI, OFFSET A

MOV DI, OFFSET B

MOV BX, OFFSET RESULT

MOV CX, COUNT

L1: MOV AH, [SI]

MOV DH, [DI]

GITAMW/ECE 45
SUB AH, DH

MOV [BX], AH

INC SI

INC SI

INC DI

INC DI

INC BX

INC BX

LOOP L1

INT 03H

CODE ENDS

END START

INPUT ADDRESS DATA

0B8B:0000 00H

0B8B:0001 40H

0B8B:0002 00H

0B8B:0003 30H

0B8B:0004 00H

0B8B:0005 24H

0B8B:0006 00H

0B8B:0007 22H

0B8B:0008 02H

0B8B:0009 00H

0B8B:000A 10H

0B8B:000B 00H

0B8B:000C 02H

GITAMW/ECE 46
RESULT:-The multi byte operations 16-bit addition and subtraction are executed by using
MASM softwar

GITAMW/ECE 47
b. ASCII OPERATIONS

AIM:-

To perform the ASCII operation for addition, subtraction, multiplication and division using
MASM

APPARATUS:-

Computer system with MASM software

PROCEDURE:-

1. Edit the program using EDIT.FILENAME.ASM in the MASM DIRECTORY.

2. Write the program code, save the file and go to exit in the file menu.

3. Source file as to be converted into object file using MASM file name.asm command.

4. Once the OBJ FILE is generated send the OBJ FILE to the linker in order to generate the
EXE.file this can be done with LINK file filename.obj command.

5. Debugging program using debug file filename.exe command.

6. Execute the program line by line using T command or at once by using G command.

7. Check the memory contents using D000 command.

PROGRAM FOR ASCII ADDITION OPERATION:-

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

OPRI DB 51H

OPR2 DB 36H

RESULT DB?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

GITAMW/ECE 48
MOV DS, AX

MOV AH, 00H

MOV AL, OPR1

MOV BL, OPR2

CLC

ADD AL, BL

AAA

MOV DI, OFFSET RESULT

MOV [DI], AX

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B7B:0000 51H

0B7B:0001 36H

OUTPUT:- ADDRESS DATA

0B7B:0002 07H

PROGRAM FOR ASCII SUBTRACTION OPERATION:-

ASSUME CS; CODE, DS: DATA

DATA SEGMENT

OPR1 DB 45H

OPR2 DB 34H

RESULT DB ?

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

GITAMW/ECE 49
MOV AH, 00H

MOV AL, OPR2

CLC

SUB AL, BL

AAS

MOV DI, OFFSET RESULT

MOV [DI], AX

INT 03H

CODE ENDS

END START

INPUT: - ADDRESS DATA

0B7B: 0000 45H

0B7B:0001 34H

OUTPUT: - ADDRESS DATA

0B7B:0002 01H

PROGRAM FOR AASCII MULTIPLICATION OPERTAION:-

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

OPR1 DB 34H

OPR2 DB 04H

RESULT DB ?

DATA ENDS

CODE SEGMENT

START: MOV AX, DATA

MOV DS, AX

` MOV AH, 00H

GITAMW/ECE 50
MOV AL OPR1

MOV BL OPR2

CLC

MUL BL

AAM

MOV DI, OFFSEET RESULT

MOV [DI], AX

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B7B:0000 34H

0B7B:0001 04H

OUTPUT:- ADDRESS DATA

0B7B:0002 00H

PROGRAM FOR ASCII DIVISION OPERATION:-

ASSUME CS: CODE, DS: DATA

DATA SEGMENT

OPR1 DB 34H

OPR2 DB 02H

RESULT DB ?

DATA ENDS

CODE SEGMENT

STARTL:- MOV AX,DASTA

MOV DS, AX

MOV AH, 00H

GITAMW/ECE 51
MOV AL, OPR1

MOV BL, OPR2

CLC

DIV BL

AAD

MOV DI, OFFSET RESULT

MOV [DI], AX

INT 03H

CODE ENDS

END START

INPUT:- ADDRESS DATA

0B7B:000 34H

0B7B:0001 04H

OUTPUT:- ADDRESS DATA

OB7B:0002 0DH

RESULT:-The ASCII operations (addition, subtraction, multiplication, division) are executed


and verified by using MASM software.

GITAMW/ECE 52
PART-B: Embedded C Experiments using MSP430

1. Blinking an Onboard LED

AIM:

The main objective of this experiment is

1) to blink the on-board, red LED (connected to P1.0)


2) Alter the delay with which the LED blinks and Modify
the code to make the GREEN
LED blink and Modify the code to make the GREEN and RED LEDs blink: i) Together ii)
Alternately using GPIO. This experiment will help you to learn and understand the
procedure for programming the MSP-EXP430G2 Launch Pad digital I/O pins.

LEARNING OBJECTIVE:

To understand GPIO programming using MSP430.

REQUIREMENTS:

 Code Composer Studio


 MSP430G2553 LaunchPad plugged into your PC via USB

Procedure

1. Connect the MSP-EXP430G2 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.

The pin diagram for the MSP430G2553


Flow chart:

GITAMW/ECE 53
C PROGRAM CODE FOR RED LED Blink

#include<msp430.h>

int main(void) {

WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

P1DIR |= 0x01; // Set P1.0 to output direction

//P1DIR |= 0x40;

while(1) {

volatile unsigned long i; // Volatile to prevent

//optimization

GITAMW/ECE 54
P1OUT ^= 0x01; // Toggle P1.0 using XOR

//P1OUT ^= 0x40;

i = 50000; // SW Delay

do i--;

while(i != 0);

C PROGRAM CODE FOR GREEN LED BLINK

#include<msp430.h>

int main(void) {

WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

//P1DIR |= 0x01; // Set P1.0 to output direction

P1DIR |= 0x40;

while(1) {

volatile unsigned long i; // Volatile to prevent

//optimization

//P1OUT ^= 0x01; // Toggle P1.0 using XOR

P1OUT ^= 0x40;

i = 50000; // SW Delay

do i--;

while(i != 0);

C PROGRAM CODE FOR LED on alternatively:

#include<msp430.h>

int main(void) {

GITAMW/ECE 55
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

P1DIR |= 0x01; // Set P1.0 to output direction

P1DIR |= 0x40;

while(1) {

volatile unsigned long i; // Volatile to prevent

//optimization

P1OUT ^= 0x01; // Toggle P1.0 using XOR

P1OUT ^= 0x40;

i = 50000; // SW Delay

do i--;

while(i != 0);

C PROGRAM CODE FOR LED BLINK TOGETHER

#include<msp430.h>

int main(void) {

WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

P1DIR |= 0x01; // Set P1.0 to output direction

P1DIR |= 0x40;

while(1) {

volatile unsigned long i; // Volatile to prevent

//optimization

P1OUT ^= 0x01; // Toggle P1.0 using XOR

P1OUT ^= 0x40;

GITAMW/ECE 56
}

C PROGRAM CODE FOR BUTTON PRESSED TO BLINK GREEN LED

#include<msp430.h>

int main(void) {

WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

P1DIR |= 0x40; // Set P1.6 to output direction

P1REN |= 0x08;

P1OUT |= 0X08;

while(1) {

if ((P1IN & BIT3)) { // If button is open(P1.3 HIGH)

P1OUT = P1OUT & ~BIT6;// ... turn on LED

} // or P1OUT |= BIT0;

else {

P1OUT = P1OUT | BIT6;

// ... else turn it off.

// or P1OUT &= ~BIT0

C PROGRAM CODE FOR BUTTON PRESSED TO BLINK RED LED

#include<msp430.h>

int main(void) {

WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

P1DIR |= 0x01; // Set P1.6 to output direction

P1REN |= 0x08;

GITAMW/ECE 57
P1OUT |= 0X08;

while(1) {

if ((P1IN & BIT3)) { // If button is open(P1.3 HIGH)

//P1OUT = P1OUT | BIT6; // ... turn on LED

P1OUT &= ~BIT0;

else {

//P1OUT = P1OUT & ~BIT6; // ... else turn it off.

P1OUT |= BIT0;

C PROGRAM CODE FOR GREEN LED STAY ON 1SEC WHEN BUTTON PRESSED

#include<msp430.h>

int main(void) {

WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

P1DIR |= 0x40; // Set P1.6 to output direction

P1REN |= 0x08;

P1OUT |= 0X08;

while(1) {

volatile unsigned long i;

GITAMW/ECE 58
if ((P1IN & BIT3))

{ // If button is open(P1.3 HIGH)

// ... turn on LED

i = 50000; // SW Delay

do i--;

while(i != 0);

P1OUT = P1OUT & ~BIT6;

//P1OUT &= ~BIT0;

else {

P1OUT = P1OUT | BIT6; // ... else turn it off.

//P1OUT |= BIT0;

C PROGRAM CODE FOR WHEN BUTTON PRESSED RED LED BLINK,ELSE


GREEN LED BLINK

#include<msp430.h>

int main(void) {

WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

P1DIR |= 0x01;

P1DIR |= 0x40; // Set P1.6 to output direction

P1REN |= 0x08;

P1OUT |= 0X08;

while(1) {

if ((P1IN & BIT3)) { // If button is open(P1.3 HIGH)

GITAMW/ECE 59
P1OUT = P1OUT | BIT6; // ... turn on LED

P1OUT &= ~BIT0;

else {

P1OUT = P1OUT & ~BIT6; // ... else turn it off.

P1OUT |= BIT0;

RESULTS:

In the Debug Perspective in your CCS Studio window, select View Registers. Pause the running
code and in the

Registers tab, expand and view the registers P1OUT, P1DIR and WDTCTL. Compare the values
with your code.

GITAMW/ECE 60
2. LOW POWER MODES AND CURRENT MEASUREMENT

AIM:

To learn the various low power modes and measure current consumption both in active and
standby mode.

LEARNING OBJECTIVE:

Configuration of MSP430 Launchpad for low power modes (LPM3).

REQUIREMENTS:

Code Composer Studio

MSP430G2553 Launchpad plugged into your PC via USB

Digital Multimeter.

PROCEDURE:

Measurement of Active Current:

1.Copy the code main_active.c in the CCS new project.

2.Build, load, and run the code. The green LED will blink once every three or four seconds.

3.When done, halt the code and click the Terminate button to return to the “CCS Edit”.

4.Remove all five jumpers on header J3.

5.The red lead of the multimeter should connect to the top (emulation side) Vcc pin on header J3
and the black lead

of the multimeter should connect to the bottom (target side) Vcc pin on header J3.

Press the Reset button on the Launchpad board.

Measure the current drawn by the MSP430.

Measurement of Standby Current:

1.Copy the code main_standby.c in the CCS new project.

2.Build, load, and run the code. The green LED will blink once every three or four seconds.

3.When done, halt the code and click the Terminate button to return to the “CCS Edit”.

GITAMW/ECE 61
4.Remove all five jumpers on header J3.

5.The red lead of the multimeter should connect to the top (emulation side) Vcc pin on header J3
and the black lead

of the multimeter should connect to the bottom (target side) Vcc pin on header J3.

Press the Reset button on the Launchpad board.

Measure the current drawn by the MSP430.

C LANGUAGE PROGRAM CODE:

Main_active.c

#include <msp430g2553.h>

#ifndef TIMER0_A1_VECTOR

#define TIMER0_A1_VECTOR TIMERA1_VECTOR

#define TIMER0_A0_VECTOR TIMERA0_VECTOR

#endif

volatile long tempRaw;

volatile unsigned int i;

void FaultRoutine(void);

void ConfigWDT(void);

void ConfigClocks(void);

void ConfigPins(void);

void ConfigADC10(void);

void ConfigTimerA2(void);

void main(void)

GITAMW/ECE 62
{

ConfigWDT();

ConfigClocks();

ConfigPins();

ConfigADC10();

ConfigTimerA2();

_BIS_SR(GIE);

while(1)

for (i = 100; i > 0; i--);

for (i = 5000; i > 0; i--); }

void ConfigWDT(void)

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

void ConfigClocks(void)

if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)

FaultRoutine(); // If calibration data is erased

// run FaultRoutine()

BCSCTL1 = CALBC1_1MHZ; // Set range

DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation

BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO

IFG1 &= ~OFIFG; // Clear OSCFault flag

BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3; // MCLK = DCO/8, SMCLK = DCO/8

GITAMW/ECE 63
}

void FaultRoutine(void)

P1OUT = BIT0; // P1.0 on (red LED)

while(1); // TRAP

void ConfigPins(void)

P1DIR = ~BIT3; // P1.6 and P1.0 outputs

P1OUT = 0;

P2SEL = ~(BIT6 + BIT7);

P2DIR |= BIT6 + BIT7;

P2OUT = 0;// LEDs off

void ConfigADC10(void)

ADC10CTL1 = INCH_10 + ADC10DIV_0; // Temp Sensor ADC10CLK

void ConfigTimerA2(void)

CCTL0 = CCIE;

CCR0 = 36000;

TACTL = TASSEL_1 + MC_2;

GITAMW/ECE 64
#pragma vector=TIMER0_A0_VECTOR

__interrupt void Timer_A (void)

ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON;

_delay_cycles(4); // Wait for ADC Ref to settle

ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start

P1OUT |= BIT6; // P1.6 on (green LED)

_delay_cycles(100);

ADC10CTL0 &= ~ENC; // Disable ADC conversion

ADC10CTL0 &= ~(REFON + ADC10ON); // Ref and ADC10 off

tempRaw = ADC10MEM; // Read conversion value

P1OUT &= ~BIT6; // green LED off

CCR0 +=36000; // add 3 second to the timer

Main_standby.c:

#include <msp430g2553.h>

#ifndef TIMER0_A1_VECTOR

#define TIMER0_A1_VECTOR TIMERA1_VECTOR

#define TIMER0_A0_VECTOR TIMERA0_VECTOR

#endif

volatile long tempRaw;

//volatile unsigned int i;

void FaultRoutine(void);

void ConfigWDT(void);

GITAMW/ECE 65
void ConfigClocks(void);

void ConfigPins(void);

void ConfigADC10(void);

void ConfigTimerA2(void);

void main(void)

ConfigWDT();

ConfigClocks();

ConfigPins();

ConfigADC10();

ConfigTimerA2();

// _BIS_SR(GIE);

while(1)

_bis_SR_register(LPM3_bits + GIE); // Enter LPM3 with interrupts

void ConfigWDT(void)

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

void ConfigClocks(void)

if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)

FaultRoutine(); // If calibration data is erased run Fault Routine ()

BCSCTL1 = CALBC1_1MHZ; // Set range

GITAMW/ECE 66
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation

BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO

IFG1 &= ~OFIFG; // Clear OSCFault flag

BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3; // MCLK = DCO/8, SMCLK = DCO/8

void FaultRoutine(void)

P1OUT = BIT0; // P1.0 on (red LED)

while(1); // TRAP

void ConfigPins(void)

P1DIR = ~BIT3; // P1.6 and P1.0 outputs

P1OUT = 0;

P2SEL = ~(BIT6 + BIT7);

P2DIR |= BIT6 + BIT7;

P2OUT = 0;// LEDs off

void ConfigADC10(void)

ADC10CTL1 = INCH_10 + ADC10DIV_0; // Temp Sensor ADC10CLK

void ConfigTimerA2(void)

CCTL0 = CCIE;

CCR0 = 36000;

GITAMW/ECE 67
TACTL = TASSEL_1 + MC_2;

#pragma vector=TIMER0_A0_VECTOR

__interrupt void Timer_A (void)

ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON;

_delay_cycles(4); // Wait for ADC Ref to settle

ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start

P1OUT |= BIT6; // P1.6 on (green LED)

_delay_cycles(100);

ADC10CTL0 &= ~ENC; // Disable ADC conversion

ADC10CTL0 &= ~(REFON + ADC10ON); // Ref and ADC10 off

tempRaw = ADC10MEM; // Read conversion value

P1OUT &= ~BIT6; // green LED off

CCR0 +=36000; // add 1 second to the timer

_bic_SR_register_on_exit(LPM3_bits); // Clr LPM3 bits from SR on exit

RESULTS:

The current consumption in both active and standby mode is measured while running same
application code. In Main_standby.c the processer enters into low power mode LPM3 and waits
for ADC interrupt. The reading for both the cases are tabularized and show below for
MSP430G2553.

Platform Active current Standby current


consumption consumption

MSP430G2553 123 uA 1.2 uA

GITAMW/ECE 68
3. Interrupt Programming through GPIO

AIM:

To learn on-chip Timer and Interrupts. Configuration of Timer, Interrupts and its operations.

LEARNING OBJECTIVE:

Configuration of Timer and Interrupts.

Objective

The main objective of this experiment is to configure GPIO and interrupts for the
MSP430G2553. This experiment

will help to learn and understand the GPIO and interrupt peripherals and their operation.

REQUIREMENTS:

Code Composer Studio

MSP430G2553 LaunchPad plugged into your PC via USB

PROCEDURE

1. Connect the MSP-EXP430G2 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.
FLOW CHART:

GITAMW/ECE 69
PROGRAM:

INTERRUPT TO BLINK GREEEN LED P1.6

GITAMW/ECE 70
#include <msp430.h>

int main(void)

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

P1DIR |= BIT6; // Set P1.6 to output direction

P1REN |= BIT3; // Enable P1.3 internal resistance

P1OUT |= BIT3; // Set P1.3 as pull up resistance

P1IES |= BIT3; // P1.3 High/Low Edge

P1IFG &= ~BIT3; // P1.3 IFG Cleared

P1IE |= BIT3; // P1.3 Interrupt Enabled

_bis_SR_register(LPM4_bits + GIE); // Enter LPM4 w/ interrupt

_no_operation(); // For debugger

#pragma vector=PORT1_VECTOR __interrupt void Port_1 (void)

P1OUT ^= BIT6; // Toggle P1.6

P1IFG &= ~BIT3; // P1.3 IFG Cleared

INTERRUPT TO BLINK RED LED P1.1

#include <msp430.h>

int main(void)

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

P1DIR |= BIT6; // Set P1.6 to output direction

P1REN |= BIT3; // Enable P1.3 internal resistance

P1OUT |= BIT3; // Set P1.3 as pull up resistance

GITAMW/ECE 71
P1IES |= BIT3; // P1.3 High/Low Edge

P1IFG &= ~BIT3; // P1.3 IFG Cleared

P1IE |= BIT3; // P1.3 Interrupt Enabled

_bis_SR_register(LPM4_bits + GIE); // Enter LPM4 w/ interrupt

_no_operation(); // For debugger

#pragma vector=PORT1_VECTOR__interrupt void Port_1 (void)

P1OUT ^= BIT6; // Toggle P1.6

P1IFG &= ~BIT3; // P1.3 IFG Cleared

RESULT:

The Timer is configured for counter/compare mode to raise a interrupt every second. Interrupt
Service Routine (ISR) for Timer is created, that blink the led which is connected to P1.6.

4. Interfacing Potentiometer with MSP430

GITAMW/ECE 72
AIM:

To control the on-board RED LED by taking the analog input from a Potentiometer.

LEARNING OBJECTIVE:

To understand the configuration of ADC and interfacing of potentiometer.

DESCRIPTION:

The MSP430G2553 has 10-bit ADC Converters denoted as ADC10. This means that an
analog input is converted into a maximum of 1024 discreet levels. There are multiple possible
input channels (8 external lines and 4 internal analog sources). The ADC10 can be configured to
convert a single channel or a block of contiguous channels and can optionally repeat its
conversions automatically. Each conversion takes multiple cycles. The timing is controlled by an
ADC clock. While a conversion is in progress and busy flag set; when the conversion is
complete, a valid result is stored in the ADC10MEM register. There is a possible interrupt
(signaled when a conversion is complete). There is also a 'data transfer controller' that can steal
cycles from the CPU and store a block of conversion results directly in memory.In the current
experiment, the analog input is provided by the potentiometer on analog channel A3 which is the
same pin as P1.3. The resistance of the potentiometer is varied by turning its knob, thereby
resulting in a varying analog voltage on A3.

This voltage is converted into 1024 discrete levels from 0V to 3V (since we set Vref=Vcc). The
Red LED must turn on when the voltage crosses the threshold of Vcc/2 (or the digital level 512)

REQUIREMENTS:

Code Composer Studio

MSP430G2553 Launch Pad plugged into your PC via USB

10,000 Ohm Potentiometer

HARDWARE CONNECTIONS:

Connect the positive lead of the potentiometer to the VCC pin on the MSP430 Launchpad and
the negative lead to the GND pin. The output lead of the potentiometer is connected to pin P1.3
or Analog Channel A3. The jumpers for RXD and TXD are connected horizontally.

FLOW CHART

GITAMW/ECE 73
C LANGUAGE PROGRAM CODE:

#include <msp430g2553.h>

int main(void)

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

ADC10CTL0 = SREF_0 + ADC10SHT_2 + ADC10ON;

ADC10CTL1 = INCH_3; // input A3

ADC10AE0 |= 0x08; // PA.3 ADC option select

P1DIR |= 0x01; // Set P1.0 to output direction

while(1)

ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start

GITAMW/ECE 74
if (ADC10MEM < 512) // ADC10MEM = A3 > 512?

P1OUT &= ~0x01; // Clear P1.0 LED off

else

P1OUT |= 0x01; // Set P1.0 LED on

RESULTS:

The LED is initially OFF when the resistance is at its maximum. As we turn the potentiometer
the LED turns ON after a certain point. This point is the ADC voltage level of 512.

The potentiometer reading can be viewed by watching the ADC10MEM register on CCStudio

Debug Perspective.

GITAMW/ECE 75
5. Using ULP Advisor on MSP430

AIM:

To optimize the power efficient application on MSP430 Launchpad by using ULP Advisor in
CCS Studio.

LEARNING OBJECTIVE:

Understanding of ULP Advisor capabilities and using ULP Advisor for creating optimized power
efficient applications on MSP430 Launchpad.

DESCRIPTION:

ULP Advisor provides advice on how to improve the energy efficiency of your
application based on comparing your code with a list of ULP rules at compile time. ULP Advisor
software is used at compile time to draw attention to inefficient code and help the developer to
fully utilize the ULP capabilities of MSP430 microcontrollers. This tool works at build time to
check your code against a list of ULP rules and identify possible areas where energy and power
use is inefficient. A description of the ULP rule in violation, 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 or continue to run the code as-is.
The ULP Advisor is built into Code Composer Studio™ IDE version 5.2 and newer. After

GITAMW/ECE 76
compiling the code, a list of the ULP rule violations is provided in the Advice window. Unlike
errors, these suggestions will not prevent your code from

Successfully compiling and downloading. This current experiment explains in detail how to use
ULP Advisor on MSP430G2. Three code files are included in this experiment, but only 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 backchannel Universal
Asynchronous Receiver/Transmitter (UART) at 9600bps. The first experiment begins with an
inefficient implementation of this application. 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. The process is repeated, and ULP
Advisor is used to compare this improved version with the original. Lastly, final steps are taken
to improve the code even further in the very efficient third version of the code.

Experiment code descriptions:

File Name Description

*Inefficient.c First draft of the application code. ULP Advisor


identify an abundance of inefficiencies.
*Efficient.c Some improvements are implemented.

However, ULP Advisor identifies


still more inefficiencies.

*MostEfficient.c Fully optimized version of the code.

*The above codes are written for MSP430FR5969 Launchpad. ULP Advisor tool help us in
evaluating the code for optimizing power and energy before debugging and is the feature of
CCS.

List of some unique rule violations are shown below:

Rule Violations Detailed description

(ULP 5.3) Detected sprintf() operations.


(ULP 5.2) Detected floating point operations
(ULP 5.1) Detected divide operations.

(ULP 3.1) Detected flag polling.

(ULP 2.1) Detected software delay loop using

GITAMW/ECE 77
delay_cycles

(ULP 4.1) Detected uninitialized port in this project.

(ULP 1.1) Detected no uses of low-power mode state


changes using LPMx or _bis_SR_register() or

low_power_mode_x() in this project.

REQUIREMENTS:

Code Composer Studio

MSP430G2553 Launch Pad plugged into your PC via USB

STEPS FOR CREATING, BUILDING AND DEBUGGING PROJECT:

Download the CCS example project ULP_Case_Study from http://www.ti.com/lit/zip/slaa603


and extract using 7zip.

Import the project into your CCS workspace:

Click Project --Import Existing CCS Eclipse Project.

Browse for the directory where downloaded the file.

Check the box next to the 'ULP_Case_Study' project in the Discovered projects window.

Un-check the box next to Copy projects into workspace.

Click Finish.

GITAMW/ECE 78
• Set as active project by left-clicking 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.

GITAMW/ECE 79
• Build the project.
• The Advice window shows suggestions from the ULP Advisor under the Power (ULP)
Advice heading. Click View→ Advice.

GITAMW/ECE 80
• 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 tab titled Advice. All of the information for this
particular rule violation is provided
• Scroll down to the Remedy section. The first suggestion is to avoid using sprintf() altogether
and work with the raw data

GITAMW/ECE 81
RESULTS1:

In the ULP Advisor of Inefficient.c, the first suggestion is to avoid using sprintf(). The next
version of code I,e Efficient.c ULP Advisor implements that advice as shown in the below

GITAMW/ECE 82
diagram.

RESULT2:

In ULP Advisor of MostEfficient.c there are no Advises related to Power optimization as


shown below.

7. Estimated Life time of an AA Battery on MSP430

GITAMW/ECE 83
AIM:

To test and represent the state of charge present in a AA battery

Learning Objective:

Measure the battery life of AA battery.

Description:

In this experiment, we are going to use our Launchpad’s analog input pin to read the voltage of
an AA battery. AA batteries when fully charged have a voltage level of around 1.5 – 1.6V.

At a voltage reading of 1.5 V (assuming the ADC can read up to 3.6V):

Integer Value After Conversion = (1.5/3.6)*1024= ~426.

Throughout the life of an AA battery, not only does the charge in the battery go down, but the
voltage also starts to dip. Eventually, the battery’s charge and voltage will drop all the way down
to its end-of life limit, which for an AA battery is typically around ~0.9V.

At 0.9V, we can expect the ADC10 to give an integer reading of around 256.

Integer Value After Conversion = (0.9/3.6)*1024= ~256

So to check if a battery has any life left in it, we can use the given code to check if the ADC10
reading is >256. If not then we know that this battery has no life left to be useable.

In the present experiment, we will connect our AA battery to the analog input channel A4 and
use the Green LED to indicate sufficient voltage.

Requirements:

Code Composer Studio

MSP430G2553 Launch Pad plugged into your PC via USB

1 AA Battery

2 wires/probes

GITAMW/ECE 84
The positive terminal of the AA battery is connected to channel A4 which is the same as pin P1.4

GITAMW/ECE 85
FLOW CHART:

C LANGUAGE PROGRAM CODE:

#include <msp430.h>

int main(void)

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

ADC10CTL0 = SREF_0 + ADC10SHT_2 + ADC10ON;

ADC10CTL1 = INCH_4; // input A4

ADC10AE0 |= 0x10; // PA.4 ADC option select

P1DIR |= 0x40; // Set P1.6 to output direction

GITAMW/ECE 86
while(1)

{ ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start

if (ADC10MEM > 256) // ADC10MEM = A4 > 256?

P1OUT |= 0x40; // Set P1.6 LED on

else P1OUT &= ~0x40; // Clear P1.6 LED off

RESULTS: As long as the green LED glows, we know that the battery has sufficient charge

GITAMW/ECE 87

Anda mungkin juga menyukai