- Get link
- X
- Other Apps
Potentiometer interfacing with MSP430 Launchpad
Program
C Program Code for Interfacing Potentiometer (RED LED ON, When ADC10MEM >= 256 )
#include <msp430.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
if (ADC10MEM < 256) // ADC10MEM = A3 >= 256?
P1OUT &= ~0x01; // Clear P1.0 LED off
else
P1OUT |= 0x01; // Set P1.0 LED on
}
}
C Program Code for Interfacing Potentiometer (RED and GREEN LED ON, When ADC10MEM >= 768)
#include <msp430.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 |= 0x41; // Set P1.0 and P1.6 to output direction
while(1)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
if (ADC10MEM < 768) // ADC10MEM = A3 >= 768?
P1OUT &= ~0x41; // Clear P1.0 and P1.6 LED off
else
P1OUT |= 0x41; // Set P1.0 and P1.6 LED on
}
}
C Program Code for Interfacing Potentiometer (RED LED ON and GREEN LED OFF, When ADC10MEM >= 512)
#include <msp430.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
P1DIR |= 0x40; // Set P1.6 to output direction
while(1)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
if (ADC10MEM < 512) // ADC10MEM = A3 >= 512?
{
P1OUT &= ~0x01; // Clear P1.0 LED off
P1OUT |= 0x40; // Set P1.6 LED on
}
else
{
P1OUT |= 0x01; // Set P1.0 LED on
P1OUT &= ~0x40; // Clear P1.6 LED off
}
}
}
C Program Code for Interfacing Potentiometer (GREEN LED ON and RED LED OFF, When ADC10MEM >= 800)
#include <msp430.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
P1DIR |= 0x40; // Set P1.6 to output direction
while(1)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
if (ADC10MEM < 800) // ADC10MEM = A3 >= 800?
{
P1OUT &= ~0x40; // Clear P1.6 LED off
P1OUT |= 0x01; // Set P1.0 LED on
}
else
{
P1OUT |= 0x40; // Set P1.6 LED on
P1OUT &= ~0x01; // Clear P1.0 LED off
}
}
}
Circuit Connection
MSP430G2553 Overall Documentation given video description
Video 👇
Comments
Post a Comment