100% found this document useful (1 vote)
30 views2 pages

MSP Demo Program

The document contains three demo programs for the MSP430 microcontroller: an LED blink program, a switch-controlled LED program, and a function generator program using ADC and PWM. Each program includes initialization and configuration of various registers and ports. Additionally, there is a detailed explanation of the registers used in the function generator program.

Uploaded by

physizzmva
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
100% found this document useful (1 vote)
30 views2 pages

MSP Demo Program

The document contains three demo programs for the MSP430 microcontroller: an LED blink program, a switch-controlled LED program, and a function generator program using ADC and PWM. Each program includes initialization and configuration of various registers and ports. Additionally, there is a detailed explanation of the registers used in the function generator program.

Uploaded by

physizzmva
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/ 2

MSP430 Demo Program

1. LED Blink

#include <msp430g2553.h>
unsigned int i=0;
void Delay()
{
while(i<32768)
{
i++;
}
i=0;
}
int main(void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR = 0x01; //Configure P1.0 as Output

while(1)
{
P1OUT = 0x01;
Delay();
P1OUT = 0x00;
Delay();
}
}

2. Switch – LED

#include <msp430g2553.h>
int SW;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR = 0x01; //Configure P1.0 as Output
P1REN |= 0x02;

while(1)

{
SW = P1IN & 0x02;
if(SW == 0x02)
P1OUT = 0x01;
else
P1OUT = 0x00;
}
}

3. Function Generator

#include <msp430g2452.h>
//#include <msp430g2553.h>
void main(void)
{
WDTCTL=WDTPW + WDTHOLD;
ADC10CTL0 = ADC10ON + SREF_0 + ADC10SHT_2;
ADC10CTL1 = INCH_3;//Select input channel 3(P1.3)
ADC10AE0|= 0x08;
P1DIR|=BIT6;//Make Port1-->Pin 6 as output (P1.6)
P1SEL|=BIT6;
TA0CCR0=1024;
TA0CCR1=1;
ADC10CTL0|= ENC + ADC10SC;
TA0CCTL1|=OUTMOD_3;
TA0CTL|= TASSEL_2 + ID_3 + MC_1 + TAIE;
_BIS_SR(LPM0_bits + GIE);
}

#pragma vector=TIMER0_A1_VECTOR
__interrupt void timer(void)
{
ADC10CTL0|= ENC + ADC10SC; //ADC enable conversion & start conversion
//TA0CCR1= ADC10MEM; //Copy ADC buffer value into CCR1 to vary duty cycle
TA0CCR0=ADC10MEM;
TA0CCR1=ADC10MEM/2;

Register Explanation
WDTCTL → Setting Watch Dog timer by WDTPW + WDTHOLD
WDTPW → Watch Dog timer Password
WDTHOLD → Holding the Watch Dog Timer
ADC10CTL0 → Setting ADC Control register for ADC – 1
ADC10ON → Enable ADC – 1
SREF_0 → Setting the default ADC Reference Voltage
ADC10SHT_2 → Setting the ADC Sample and Hold time.
INCH_3 → Selecting the ADC1 channel 3
ADC10AE0 → Enabling ADC Pin as Analog
P1SEL → Select the P1.6 pin as PWM
TA0CCR0 → Configure default PWM Time Period
TA0CCR1 → Configure default PWM Duty Ratio
ENC → enable conversion on ADC
ADC10SC → Start conversion
TA0CCTL1|=OUTMOD_3; → Select timer 0 output mode 3 (set/reset)
TASSEL_2 → Configuring Timer 0
ID_3 → Clock UP mode
MC_1 → Select Master clock
TAIE → Enable timer interrupt
_BIS_SR(LPM0_bits + GIE); → Enable General Interrupt
#pragma vector=TIMER0_A1_VECTOR → Timer0 Interrupt Vector
ADC10CTL0|= ENC + ADC10SC; → enable and Start conversion
TA0CCR0 → PWM Frequency setting Register
TA0CCR1 → PWM Duty ratio setting Register
ADC10MEM → ADC Buffer memory holding the current value of ADC

*** END OF THE DOCUMENT***

You might also like