Skip to content

Instantly share code, notes, and snippets.

@pmcalabrese
Created November 3, 2017 15:47
Show Gist options
  • Save pmcalabrese/ac749758ac50e3db34a29c1c64dba6ca to your computer and use it in GitHub Desktop.
Save pmcalabrese/ac749758ac50e3db34a29c1c64dba6ca to your computer and use it in GitHub Desktop.
#include "msp430.h"
/*
* Piedinatura
* 1.6 -> uscita PWM PP1
* 2.1 -> uscita PWM PP2
* 2.2 -> uscita PWM continua
* 1.0 -> uscita led lampeggiante in sync con 1.6
*/
/*
* DEFINE LED PORT & PIN
*/
#define LED_PDIR P1DIR
#define LED_POUT P1OUT
#define LED_PIN BIT0
void blinkDelay()
{
//Configure the LED
LED_PDIR |= LED_PIN; //Set P1.0 as an Output pin
LED_POUT &= ~LED_PIN; //Set P1.0 LOW (turn LED off)
//Infinite loop to blink the LED
while (1)
{
LED_POUT ^= LED_PIN; //Toggle the LED, using XOR operator'
P2DIR ^= BIT1;
P1DIR ^= BIT6;
//Delay for 100000 cycles – the CPU is occupied during this
__delay_cycles(574555); // 1 sec
}
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= ~BIT6; // P1.6 to output (bitwise OR it will make it a 1)
P1SEL |= BIT6; // P1.6 to TA0.1
P1SEL2 &= ~BIT6; // P1.6 to TA0.1 (it will make it a 0)
P2DIR |= BIT1; // P1.6 to output (bitwise OR it will make it a 1)
P2SEL |= BIT1; // P1.6 to TA0.1
P2SEL2 &= ~BIT1; // P1.6 to TA0.1 (it will make it a 0)
P2DIR |= BIT2; // P1.6 to output (bitwise OR it will make it a 1)
P2SEL |= BIT2; // P1.6 to TA0.1
P2SEL2 &= ~BIT2; // P1.6 to TA0.1 (it will make it a 0)
TA0CCR0 = 20; // Set maximum count value (PWM Period
TA0CCTL1 = OUTMOD_7; // set output on counter reset, clear output on CCR1
TA0CCR1 = 3; // initialise counter compare value
TA0CTL = TASSEL_2 + MC_1; // Use the SMCLK to clock the counter and set to count up mode
TA1CCR0 = 20; // Set maximum count value (PWM Period
TA1CCTL1 = OUTMOD_7; // set output on counter reset, clear output on CCR1
TA1CCR1 = 17; // initialise counter compare value
TA1CTL = TASSEL_2 + MC_1; // Use the SMCLK to clock the counter and set to count up mode
blinkDelay();
_BIS_SR(LPM0_bits); // Enter LPM0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment