0% found this document useful (0 votes)
38 views

Mobile App and Embedded System Development Lab Manual

The document contains two C code programs for interfacing with an MSP430 microcontroller. The first program controls a DC motor by reading the value of a potentiometer connected to an analog pin and using it to set the duty cycle of a PWM signal to control motor speed. The second program reads the temperature from an onboard temperature sensor and converts the analog reading to Celsius, displaying the temperature in a continuous loop. Both programs initialize the ADC, set up digital I/O pins for outputs, and enter a low power mode to periodically take readings and output values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Mobile App and Embedded System Development Lab Manual

The document contains two C code programs for interfacing with an MSP430 microcontroller. The first program controls a DC motor by reading the value of a potentiometer connected to an analog pin and using it to set the duty cycle of a PWM signal to control motor speed. The second program reads the temperature from an onboard temperature sensor and converts the analog reading to Celsius, displaying the temperature in a continuous loop. Both programs initialize the ADC, set up digital I/O pins for outputs, and enter a low power mode to periodically take readings and output values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

NAME: SHAIK ASMA ROLL NO.

:209X1A04D2
DATE: EXP NO.:12

a) Code to turn the LED ON when the button is pressed and OFF when it is released.

#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
}
}}

b)Alter the code to turn the red LED ON when the button is pressed and the green LED ON
when the button is released.

#include<msp430.h>
voidmain(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= 0x41; // Set P1.6 to output direction
P1REN |= 0x08;
P1OUT |= 0X08;
while(1) {
if ((P1IN & BIT3))
{ // If button is open(P1.3 HIGH)

Page No :54
P1OUT = P1OUT & ~BIT0; // ... else turn it off.
P1OUT = P1OUT | BIT6; // ... turn on LED

} // or P1OUT |= BIT0;
else
{
P1OUT = P1OUT | BIT0; // ... turn on LED
P1OUT = P1OUT & ~BIT6; // ... else turn it off.

// or P1OUT &= ~BIT0


}
}}

Page No :55
NAME: SHAIK ASMA ROLL NO.:209X1A04D2
DATE: EXP NO.:13
Learn and understand how to configure MSP-EXP430G2 Launchpad
digital I/O pins. Write a C program for interfacing a DC Motor with
MSP430.
#include <msp430.h>
int pwmDirection = 1;
void 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 |= BIT6; // Green LED for output
P1SEL |= BIT6; // Green LED Pulse width modulation
TA0CCR0 = 1024; // PWM period
TA0CCR1 = 1; // PWM duty cycle,on 1/1000 initially
TA0CCTL1 = OUTMOD_7; // TA0CCR1 reset/set-high voltage
// below count,low voltage when past
TA0CTL = TASSEL_2 + MC_1 + TAIE +ID_3;
// Timer A control set to SMCLK,1MHz
// and count up mode MC_1
_BIS_SR(LPM4_bits + GIE);
while (1); // Enter Low power mode 0
}
#pragma vector= TIMER0_A1_VECTOR // Watchdog Timer ISR
interrupt void timer(void)
{
ADC10CTL0 |= ENC + ADC10SC;
TA0CCR1 = ADC10MEM;
}

Page No :56
NAME: SHAIK ASMA ROLL NO.:209X1A04D2
DATE: EXP NO.:14
Learn and understand how to configure MSP-EXP430G2 Launchpad digital I/O pins.
Write a C program for reading room temperature with MSP430.

#include <msp430.h>
//#include<msp430g2231.h>
void tempInit()
{
ADC10CTL0=SREF_1 + REFON + ADC10ON + ADC10SHT_3 ;
//1.5V ref,Ref on,64 clocks for sample
ADC10CTL1=INCH_10+ ADC10DIV_3; //temp sensor is at 10 and clock/4
}
int tempOut()
{
int t=0;
delay_cycles(1000); //wait 4 ref to settle
ADC10CTL0 |= ENC + ADC10SC; //enable conversion and start conversion
while(ADC10CTL1 & BUSY); //wait..i am converting..pum..pum..
t=ADC10MEM; //store val in t
ADC10CTL0&=~ENC; //disable adc conv
return (int) ((t * 27069L - 18169625L) >> 16); //convert and pass
}
void main(void)
{ volatile int temp;
//initialise
WDTCTL = WDTPW + WDTHOLD;
//stop..bow..boww
temp=0;
tempInit();//initialize adc
while(1)
{
delay_cycles(500); //wait and set break point
temp=tempOut(); //read temp
delay_cycles(500); //wait and set breakpoint
}
}

Page No :57

You might also like