2019-03-23 22:21发布
#include<msp430g2553.h>#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0)) char sintable[10]={100,78,70,78,100,126,148,156,148,126};char y=0;unsigned int i;char flag=0;void main(){ WDTCTL=WDTPW+WDTHOLD; BCSCTL1=CALBC1_16MHZ; DCOCTL=CALDCO_16MHZ; P1IE|=BIT4; //P1.4触发 P1IES&=~0x10; //上升沿触发 P1IFG&=~0x10; P1DIR=0x04; // P1.2输出 P1SEL=0x04; P1OUT=0; //先输出低 //ta1 congigure //ta0configure TACTL=TASSEL1+TACLR; CCR0=157; CCR1=sintable[y]; CCTL1=OUTMOD_3; //CCTL1|=CCIE; CCTL0=CCIE; TACTL|=MC_1; _EINT(); while(1) { if(flag==1) { flag=0; TACTL|=MC_1; } }}#pragma vector=TIMER0_A0_VECTOR __interrupt void Timer_A1(void){ y=y+1; if(y<10) { CCR1=sintable[y]; } else { y=0; CCR1=sintable[y]; }}#pragma vector=PORT1_VECTOR__interrupt void PORT1(void){ y=3; //for(i=100;i>0;i--); CCR1=sintable[y]; P1IFG&=~0x10;}
最多设置5个标签!
#include<msp430g2553.h>
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
char sintable[10]={100,78,70,78,100,
126,148,156,148,126};
char y=0;
unsigned int i;
char flag=0;
void main()
{
WDTCTL=WDTPW+WDTHOLD;
BCSCTL1=CALBC1_16MHZ;
DCOCTL=CALDCO_16MHZ;
P1IE|=BIT4; //P1.4触发
P1IES&=~0x10; //上升沿触发
P1IFG&=~0x10;
P1DIR=0x04; // P1.2输出
P1SEL=0x04;
P1OUT=0; //先输出低
//ta1 congigure
//ta0configure
TACTL=TASSEL1+TACLR;
CCR0=157;
CCR1=sintable[y];
CCTL1=OUTMOD_3; //CCTL1|=CCIE;
CCTL0=CCIE;
TACTL|=MC_1;
_EINT();
while(1)
{
if(flag==1)
{
flag=0;
TACTL|=MC_1;
}
}
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A1(void)
{
y=y+1;
if(y<10)
{
CCR1=sintable[y];
}
else
{
y=0;
CCR1=sintable[y];
}
}
#pragma vector=PORT1_VECTOR
__interrupt void PORT1(void)
{
y=3;
//for(i=100;i>0;i--);
CCR1=sintable[y];
P1IFG&=~0x10;
}
一周热门 更多>