You are on page 1of 53

SR. NO. NAME OF EXPERIMENT DATE SIGN.

1 Introduction to IAR Embedded Workbench


2 Introduction to Proteus software
3 Interface LED with Port1.0 and write a program
in C to turn on and off LED

4 Interface LED with all Ports write a program in


C to turn on and off all LED

5 Interface LED with all Ports write a program C


in to alternate turn on and off all LED

6 Write a program in C to turn on and off LED


according to switch pressed

7 Interface 2 LED with Port and write a program


in C to turn on and off LED according to switch
pressed

8 Write a program in an assembly language to


push and pop data

9 Write a program in an assembly language to


addition of 32 bit num

10 Write a program in an assembly language to


subtract

11 Interface 7 segment with msp430 and write a


program in C to display any number
12 Interface 7 segment display with MSP430 and
write a program in C to display 0 to 9
13 Interface 4 x 4 keyboard with MSP430 and
write a program for keyboard
14 Interface LED with MSP430 and write a
program in C for toggle LED using interrupt
15 Interface LED with MSP430 and write a
program in C for toggle LED using watchdog
timer as an interval timer
16 Interface LED with MSP430 and generate 1 sec
delay using basic timer 1
17 Interface LCD with MSP430 and write a
program in C to display ‘h’ on the LCD.
18 To interface an LED with MSP430 and write a
program in C to measure the external voltage
using a polling loop in ADC(LED is turned on if
voltage exceeds Vcc/2)
19 To interface DAC with MSP430 and write a
program in C to generate a stair step ramp
output
20 To interface stepper motor with MSP430 and
write a program in C to rotate it clockwise if
output is 1 and anti-clockwise if output is 0
PRACTICAL 1

AIM: To study IAR work bench.

THEORY:

IAR Systems provides several products that integrate different sets of tools or middleware that
work together right out of the box.

This figure shows the various tools from IAR Systems and third-party vendors and how they
interact with each other.

IAR Embedded Workbench provides an integrated development environment that allows you to
develop and manage complete application projects for embedded systems. The environment
comprises tools for compiling, linking, and debugging and they have comprehensive and specific
target support. You will have the same user interface regardless of which microcontroller you use.
IAR visual STATE integrates a set of development tools for designing, testing, and implementing
embedded applications based on state machines. It provides formal verification and validation
tools and generates C source code from your design. To get started, the product installation
provides tutorials, a Getting Started guide and several examples, where some are generic and some
are adapted for certain evaluation boards.

IAR Power Pac is an integrated middleware family that combines a small memory footprint
RTOS, a versatile file system, USB protocol stacks for both the host and the device, a TCP/IP
protocol stack, and a library for graphical interfaces. To get started, there are ready-to-go example
projects and board support packages for a wide range of devices.

IAR J-Link is a JTAG hardware debug probe which connects via USB to the host PC. IAR J-
Trace is a high-speed hardware trace probe that also connects via USB to the host PC.

Third-party tools and utilities There are a wide range of third-party tools and utilities that can
be integrated with IAR Embedded Workbench. Examples of such products are version control
systems, editors, C-SPY plugin modules for RTOS-aware debugging and different ICEs, protocol
stacks, etc.

THE IDE

The IDE is the framework where all tools needed to build your application are integrated: a C/C++
compiler, an assembler, a linker, library tools, an editor, a project manager, and the IAR C-SPY®
Debugger. In addition to these tools, you can invoke external tools to the tool chain.

The tool chain that comes with your product package is adapted for a certain microcontroller.
However, the IDE can simultaneously manage multiple tool chains for various microcontrollers.
This means that if you have IAR Embedded Workbench installed for several microcontrollers, you
can choose which microcontroller to develop for in the IDE.

Note: The compiler, assembler, linker, and the C-SPY debugger can also be run from a command
line environment, if you want to use them as external tools in an already established project
environment.

To start the IDE:


Click the start button on the Windows taskbar, or double-click a workspace filename (filename
extension eww), or use the file IarIdePm.exe, located in the common\bin directory of your IAR
Systems installation. When you first open IAR Embedded Workbench, the IDE main window
displays the IAR Information Center. Here you can find all the information you need to get started:
tutorials, example projects, user guides, support information, and release notes.

The IAR Assembler is a relocating macro assembler with a versatile set of directives and
expression operators for the microcontroller you are using. The assembler features a built-in C
language preprocessor and supports conditional assembly.

The assembler translates symbolic assembler language mnemonics into executable machine code.
To write efficient assembler applications, you should be familiar with the architecture and
instruction set of the microcontroller you are using.

Menu Information Toolba


bar Center r

Workspace Language selection—only


Status for products where there
bar window
is a Japanese version

There are two high-level programming languages you can use with the IAR C/C++ Compiler:
C, which follows the standard ISO 9899:1990 (commonly known as ANSI C).

C++ (depends on your product package). IAR Systems supports two levels of the C++ language:
Embedded C++ (EC++), a subset of the C++ programming standard. It is defined by an industry
consortium, the Embedded C++ Technical committee.

IAR Extended Embedded C++, with additional features such as full template support, multiple
inheritance (depending on your product package), namespace support, the new cast operators, as
well as the Standard Template Library (STL).

DESIGN:
PRACTICAL 2

AIM: Introduction to PROTEUS software.

THEORY:

Proteus is a simulation and design software tool developed by Lab center Electronics for Electrical
and Electronic circuit design. It also possesses 2D CAD drawing feature. It deserves to bear the
tagline “From concept to completion”. Proteus is a software suite containing schematic, simulation
as well as PCB designing. ISIS is the software used to draw schematics and simulate the circuits
in real time. The simulation allows human access during run time, thus providing real time
simulation. ARES is used for PCB designing. It has the feature of viewing output in 3D view of
the designed PCB along with components. The designer can also develop 2D drawings for the
product.

Features:

ISIS has wide range of components in its library. It has sources, signal generators, measurement
and analysis tools like oscilloscope, voltmeter, ammeter etc., probes for real time monitoring of
the parameters of the circuit, switches, displays, loads like motors and lamps, discrete components
like resistors, capacitors, inductors, transformers, digital and analog Integrated circuits, semi-
conductor switches, relays, microcontrollers, processors, sensors etc. ARES offers PCB designing
up to 14 inner layers, with surface mount and through hole packages. It is embedded with the foot
prints of different category of components like ICs, transistors, headers, connectors and other
discrete components. It offers Auto routing and manual routing options to the PCB Designer. The
schematic drawn in the ISIS can be directly transferred ARES.Proteus PIC Bundle is the complete
solution for developing, testing and virtually prototyping your embedded system designs based
around the Microchip Technologies TM series of microcontroller. This software allows you to
perform schematic capture and to simulate the circuits you design.
Starting New Design

Step 1: Open ISIS software and select New design in File menu

Proteus File Menu

Step 2: A dialogue box appears to save the current design. However, we are creating a new
design file so you can click Yes or No depending on the content of the present file. Then a Pop-
Up appears asking to select the template. It is similar to selecting the paper size while printing.
For now, select default or according to the layout size of the circuit.

Proteus Default Template Select


Step 3: An untitled design sheet will be opened, save it according to your wish, it is better to
create a new folder for every layout as it generates other files supporting your design. However,
it is not mandatory.

Proteus Design Sheet

Step 4: To Select components, Click on the component mode button.


Step 5: Click On Pick from Libraries. It shows the categories of components available and a
search option to enter the part name.

Pick from Libraries

Step 6: Select the components from categories or type the part name in Keywords text box.
Example shows selection of push button. Select the components accordingly.

Step 7: The selected components will appear in the devices list. Select the component and place
it in the design sheet by left-click.

Component Selection
Place all the required components and route the wires i.e., make connections.

Either selection mode above the component mode or component mode allows to connect through
wires. Left click from one terminal to other to make connection. Double right-click on the
connected wire or the component to remove connection or the component respectively.

Component Properties Selection

Double click on the component to edit the properties of the components and click on Ok.

Component Properties Edit


Step 8: After connecting the circuit, click on the play button to run the simulation.

Simulation Run

In this example simulation, the button is depressed during simulation by clicking on it to make
LED glow.
Simulation can be stepped, paused or stopped at any time.

Simulation Step-Pause-Stop Buttons


Practical 3(a)
Aim: Write a program in C to turn on and off LED connected to port p1.0.
Program code:
#include "io430.h"
int main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer//

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


P1OUT = 0x00;
int i;
while(1)
{
for(i=0;i<0xFFFF;i++); //delay of 1 sec//
P1OUT ^= BIT0; // Toggle P1.0 //
for(i=0;i<0xFFFF;i++); // delay 1 sec//
}
}
Output:
Practical 3(b)
Aim: Demonstrate the practical 3(a) in proteus.
Output:
Practical 4(a)
AIM: Write a program in c turn on and off led connected with all ports.

Program code:
#include "io430.h"

int main (void)

WDTCTL = WDTPW + WDTHOLD;

P1DIR|= 0xFF ;

P1OUT = 0x00;

int i;

while (1)

For (i=0; i<0xFFFF; i++);

P1OUT ^= 0xFF;

For (i=0; i<0xFFFF; i++);

}
Practical 4(b)

Aim: Demonstrate the practical 4(a) in proteus.

Output:
Led off:

Led on:
Practical 5(a)
AIM: Write a program in c alternative turn on and off led connected with all ports.

Program code:
#include "io430.h"

int main(void)

WDTCTL = WDTPW + WDTHOLD ;

P1DIR|= 0xFF;

P1OUT = 0x00;

int i;

while (1)

For (i=0; i<0xFFFF; i++);

P1OUT ^= 0xAA;

For (i=0; i<0xFFFF; i++);

P1OUT ^= 0x55;

}
Practical 5(b)

Aim: Demonstrate the practical 5(a) in proteus.

Output:
Practical 6(a)
AIM: Interface ON-OFF switch and LED with MSP430 and write a C program which turns on
and off the LED according to the switch pressed.

Program code:
#include"io430.h"

#define LED1 BIT3

#define B1 BIT1

int main(void)

WDTCTL=WDTPW+WDTHOLD;

P2OUT|=LED1;

P2DIR=LED1;

for(;;){

if((P2IN & B1)==2)

{ P2OUT &= ~LED1;

} else {

P2OUT|=LED1;

}
Practical 6(b)
Aim: Demonstrate the practical 6(a) in proteus.

Output:
Practical 7(a)
AIM: Interface ON-OFF switch and 2 LED with MSP430 and write a C program which turns
on and off the both LED according to the switch pressed.

Program code:
#include"io430.h"

int main(void)

WDTCTL=WDTPW+WDTHOLD;

P1OUT=0X00;

P1DIR=BIT1;

P2DIR=BIT4;

For (;;)

If ((P1IN & B1) ==2)

P1OUT |= BIT1;

P2OUT &= ~BIT4;

Else

P1OUT &= ~BIT1;

P2OUT|=BIT4;

}
Practical 7(b)
Aim: Demonstrate the practical 7(a) in proteus.

Output:
Practical 8
AIM: Write an assembly language program to push and pop the data.

Program code:
#include <msp430x11x1.h>

XYZ: mov.w #0X0280,SP

XYZ: mov.w #0X1505,R6

PUSH R6

POP R7

XYZ1: JMP XYZ1

ORG 0xFFFE

DW XYZ

END
Practical 9
AIM: Write an assembly language program to add 32 bit num.

Program code:
#include <msp430.h>

ORG 0XF800

JUMP:

mov.w WDTPW|WDTHOLD,&WDTCTL

mov.w #0X01AB,R4

mov.w #0X0121,R5

add.w R4,R5

mov.w #0X0122,R6

mov.w #0XFFFF,R7

addc.w R6,R7

addc.w #0x0000,R9

ORG 0xFFFE

DW JUMP

END

Output:
Practical 10
AIM: Write an assembly language program to subtract 32 bit num.

Program code:
#include <msp430.h>

ORG 0XF800

JUMP:

mov.w WDTPW|WDTHOLD,&WDTCTL

mov.w #0X01AB,R4

mov.w #0X0121,R5

sub.w R4,R5

mov.w #0X0122,R6

mov.w #0XFFFF,R7

subc.w R6,R7

subc.w #0x0000,R9

ORG 0xFFFE

DW JUMP

END

Output:
Practical 11(a)
AIM: Interface 7 segment display with MSP430 and write a C program to display any number
on the 7 segment.

Program code:
#include<msp430.h>

int main(void)

WDTCTL=WDTPW+WDTHOLD;

P1DIR=0XFF;

P1OUT=0X06;

}
Practical 11(b)
Aim: Demonstrate the practical 11(a) in proteus.
Output:
Practical 12(a)
AIM: Interface 7 segment display with MSP430 and write a C program to display 0 to 9 on the
7 segment.

Program code:
#include"io430.h"

int main(void)

{ int j; WDTCTL=WDTPW+WDTHOLD;

P1DIR=0XFF;

for (j=0; j<=20000; j++)

P1OUT=0x3F;

for (j=0; j<=20000; j++)

P1OUT=0x06;

for (j=0; j<=20000; j++)

P1OUT=0x5B;

for (j=0; j<=20000; j++)

P1OUT=0x4F;

for (j=0; j<=20000; j++)

P1OUT=0x66;

for (j=0; j<=20000; j++)

P1OUT=0x6D;

for (j=0; j<=20000; j++)

P1OUT=0x7D;

for (j=0; j<=20000; j++)

P1OUT=0x07;

for (j=0; j<=20000; j++)


P1OUT=0x7F;

for (j=0; j<=20000; j++)

P1OUT=0x6F;}
Practical 12(b)
Aim: Demonstrate the practical 12(a) in proteus.
Output:
Practical 13(a)
AIM: Interface 4x4 keypad with MSP430 and write a C program using interrupted I/O to show
output on PORT2.

Program code:
#include"msp430.h"

#include <intrinsics.h >

#define key_prt P1OUT

#define key_dir P1DIR

#define key_pin P1IN

unsigned char keypad[4][4]={'0','1','2','3',

'4','5','6','7',

'8','9','A','B',

'C','D','E','F'};

void delay_ms(void)

int i;

for(i=0x00; i<=0xFF; i++)

}}

int main(void)

WDTCTL=WDTPW+WDTHOLD;

unsigned char rowloc, colloc;

P2DIR= 0XFF;

key_dir= 0XF0;
key_prt=0xFF;

while(1)

do

key_prt &= 0x0F;

colloc=(key_pin & 0x0F);

while (colloc !=0x0F);

delay_ms ();

colloc = (key_pin & 0x0F);

} while (colloc == 0x0F);

while(1)

key_prt = 0xEF;

colloc = (key_pin & 0x0F);

if(colloc != 0x0F)

rowloc = 0;

break;

key_prt = 0xDF;

colloc = (key_pin & 0x0F);

if(colloc != 0x0F)
{

rowloc = 1;

break;

key_prt = 0xBF;

colloc = (key_pin & 0x0F);

if(colloc != 0x0F)

rowloc = 2;

break;

key_prt = 0x7F;

colloc = (key_pin & 0x0F);

if(colloc != 0x0F)

rowloc = 3;

break;

if(colloc == 0x0E)

P2OUT = (keypad[rowloc][0]);

else if(colloc == 0x0D)

P2OUT = (keypad[rowloc][1]);

else if(colloc == 0x0B)


P2OUT = (keypad[rowloc] [2]);

else

P2OUT = (keypad[rowloc] [3]); }

return 0;

}}

}}
Practical 13(b)
Aim: Demonstrate the practical 13(a) in proteus.
Output:
Practical 14(a)
AIM: Interface LED with MSP430 and write a C program with interrupted I/O to toggle the
LED.

Program code:
#include<io430x11x1.h>

#include<intrinsics.h>

void main (void)

WDTCTL=WDTPW|WDTHOLD;

P2OUT_bit. P2OUT_3=1;

P2DIR_bit. P2DIR_3=1;

P2IE_bit. P2IE_1=1;

P2IES_bit. P2IES_1=1;

Do {

P2IFG=0;

} while (P2IFG !=0);

For (;;) {

__low_power_mode_4();

} }

#pragma vector = PORT2_VECTOR

__interrupt void PORT_ISR (void)

P2OUT_bit. P2OUT_3 ^=1;

P2IES_bit. P2IES_1 ^=1;

Do {
P2IFG =0;

} while (P2IFG !=0);

}
Practical 14(b)
Aim: Demonstrate the practical 14(a) in Proteus.
Output:
Practical 15(a)
AIM: Interface LED with MSP430 and write a C program to toggle the LED using watchdog
timer as an interval timer.

Program code:
#include <msp430.h>

#include<intrinsics.h>

int main(void)

WDTCTL=WDTPW|WDTTMSEL|WDTSSEL|WDTCNTCL|WDTIS1|WDTIS0;

P2DIR=BIT0;

P2OUT=0;

for(;;){

while(WDTIFG==1)

P2OUT=~P2OUT;

WDTCTL= WDTPW|WDTCNTCL;

}
Practical 15(b)
Aim: Demonstrate the practical 15(a) in proteus.
Output:
Practical 16(a)
AIM: Interface LED with MSP430 and write a C program to generate 1 second delay using
Basic Timer 1.

Program code:
#include “io430.h”

#include “intrinsics.h”

int main(void)

WDTCTL = WDTPW + WDTHOLD;

P2DIR_bit.P2DIR_1 = 1;

P2OUT_bit.P2OUT_1 = 0;

BTCTL = BTSSEL+ BTDIV + BTIP1 + BTIP0;

IE2_bit.IE2_BTIE = 1;

BTCNT2 = 1000;

do{

BTIFG = 0; }

while (BTIFG! = 0);

for(;;){

__low_power_mode(2);

}}

#pragma vector=WDT_VECTOR

__interrupt void watchdog_timer(void)

{ P1OUT ^= BIT0;

}
Practical 16(b)
Aim: Demonstrate the practical 16(a) in proteus.
Output:
PRACTICAL-17(a)
Aim: Interface LCD with MSP430 and write a C program to display ‘h’ on the LCD.
Program code:

#include "io430.h"
void lcdcmnd (unsigned char cmnd)
{
int i;
P1OUT= cmnd;
P2OUT_bit. P2OUT_0=1;
P2OUT_bit. P2OUT_1=0;
P2OUT_bit. P2OUT_2=0;
For ( i=0; i<=5000; i++);
P2OUT_bit. P2OUT_0=0;
for(i=0; i<=5000;i++);
}
void lcddata (unsigned char data)
{
int i;
P1OUT=data;
P2OUT_bit. P2OUT_0=1;
P2OUT_bit. P2OUT_1=0;
P2OUT_bit. P2OUT_2=1;
for(i=0; i<=5000;i++);
P2OUT_bit. P2OUT_0=0;
for(i=0; i<=5000;i++);
}
int main (void )
{
int i;
WDTCTL = WDTPW + WDTHOLD;
P1DIR=0XFF;
P2DIR=0XFF;
P2OUT_bit. P2OUT_0=0;
lcdcmnd (0x38);
lcdcmnd (0x0E);
lcdcmnd (0x01);
for(i=0; i<=5000;i++);
lcdcmnd (0x06);
lcddata ('h');
while (1);
return 0;
}
PRACTICAL-17(b)
Aim: Demonstrate the Practical 17(a) in Proteus.

Output:
PRACTICAL-18(a)
Aim: To interface an LED with MSP430 and measure the external voltage using a polling loop
in ADC (LED is turned on if voltage exceeds Vcc/2).
Program code:
#include <io430x20x2.h>
#include <intrinsics.h>
#define LED P2OUT_bit.P2OUT_1
void main (void)
{
WDTCTL = WDTPW | WDTHOLD;
P2SEL = 0;
P2OUT = 0;
P2DIR = BIT1|BIT5;
P1OUT = BIT5;
P1DIR = BIT3|BIT5|BIT6|BIT7;

ADC10CTL0 = SREF_0 | ADC10SHT_2 | ADC10ON;


ADC10CTL1 = INCH_1 | SHS_0 | ADC10DIV_0 | ADC10SSEL_0 | CONSEQ_0;
ADC10AE0 = BIT1;
ADC10CTL0_bit.ENC = 1;
for (; ;)
{
ADC10CTL0_bit.ADC10SC = 1
while (ADC10CTL1_bit.ADC10BUSY == 1) {
}
if (ADC10MEM >= BIT9) {
LED = 1;
} else {
LED = 0; // No: Turn LED off
}
}
}
PRACTICAL-18(b)
Aim: Demonstrate the Practical 18(a) in Proteus.

Output:
PRACTICAL-19(a)
Aim: To interface DAC with MSP430 and generate a stair step ramp output.
Program code:
#include “io430.h”
Int main(void)
{
unsigned char i=0;
P1DIR = 0Xff;
while(1)
{
PORT1 = i;
i++;
}
return 0;
}
PRACTICAL-19(b)
Aim: Demonstrate the Practical 19(a) in Proteus.

Output:
PRACTICAL-20(a)
Aim: To interface stepper motor with MSP430 and rotate it clockwise if output is 1 and anti-
clockwise if output is 0.

Program code:
#include <msp430.h>

#include <intrinsics.h>

int main(void)

int i;

WDTCTL = WDTPW+ WDTHOLD;

P2DIR = 0xFF;

for (; ;)

if (P1IN==0)

P2OUT = 0x66;

for (i=0; i<=1000; i++) { }

P2OUT = 0xCC;

for (i=0; i<=1000; i++) { }

P2OUT = 0x99;

for (i=0; i<=1000; i++) { }

P2OUT = 0x33;

for (i=0; i<=1000; i++) { }

else
{

P2OUT = 0x66;

for (i=0; i<=1000; i++) { }

P2OUT = 0x33;

for (i=0; i<=1000; i++) { }

P2OUT = 0x99;

for (i=0; i<=1000; i++) { }

P2OUT = 0xCC;

for (i=0; i<=1000; i++) { }

}
PRACTICAL-20(b)
Aim: Demonstrate the Practical 20(a) in Proteus.

Output:

You might also like