#include "msp430g2553.h"
//unsigned char SPWM_FLAG;
unsigned char i=0;
void main(void)
{
//unsigned char i=0;
//unsigned char a[32]={0x80,0x98,0xb0,0xc6,0xda,0xea,0xf5,0xfd,0xff,0xfd,0xf5,0xea,0xda,0xc6,0xb0,0x98,0x7f,0x67,0x4f,0x39,0x25,0x15,0x0a,0x02,0x00,0x02,0x0a,0x15,0x25,0x39,0x4f,0x67};
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P2DIR |= 0x22; // P1.2 and P1.3 output
P2SEL |= 0x22; // P1.2 and P1.3 TA1/2 options
TA1CCR0 = 0x0ff; // PWM Period
TA1CCTL0 = CCIE; // CCR0 interrupt enabled
TA1CCTL1 = OUTMOD_2; // CCR1 reset/set
TA1CCTL2 = OUTMOD_2; // CCR1 PWM duty cycle
TA1CTL = TASSEL_2 + MC_1;// SMCLK, up mode
TA1CCR1=0X80;
TA1CCR2=0X5F;
_BIS_SR(LPM0_bits+GIE);
}
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR(void)
{
// unsigned char i=0;
unsigned char a[32]={0x80,0x98,0xb0,0xc6,0xda,0xea,0xf5,0xfd,0xff,0xfd,0xf5,0xea,0xda,0xc6,0xb0,0x98,0x7f,0x67,0x4f,0x39,0x25,0x15,0x0a,0x02,0x00,0x02,0x0a,0x15,0x25,0x39,0x4f,0x67};
TA1CCR1=a;
TA1CCR2 =a[31-i];
if(i==31)
i=0;
else
i++;
}
欢迎大家拍砖学习
几个中断源混合的程序 大家可以各抒己见
#include
unsigned char i=0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled
ADC10CTL1 = INCH_3; // input A1
ADC10AE0 |= 0x04; // PA.1 ADC option select
P1DIR |= 0x41; // Set P1.0 to output direction
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 50000;
TACTL = TASSEL_2 + MC_1; // SMCLK, upmode
ADC10CTL0 |= ENC + ADC10SC;
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0TXIE; // Enable USCI_A0 RX interrupt
UCA0TXBUF = 0x10;
// Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
//UCA0TXBUF = ADC10MEM;
// __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
if(i==10)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
P1OUT ^= 0x01;
UCA0TXBUF = ADC10MEM;
i=0;
}
else
i++;
}
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
// while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
IFG2&=~UCA0TXIFG;
P1OUT^=BIT6;
}