2019-03-24 10:22发布
834707939 发表于 2015-3-28 13:12 #include "msp430.h" typedef unsigned char uchar; typedef unsigned int uint; uchar flag; uchar table[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43, 44,45,46,47,48,49,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34, 33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11, 10,9,8,7,6,5,4,3,2,1,0};//呼吸的效果 void main(void) { uchar i; WDTCTL = WDTPW + WDTHOLD; // Stop WDT BCSCTL1 &= ~XT2OFF; //打开xt2晶振 do { IFG1 &= ~OFIFG; for(i = 0xff; i > 0; i--); } while((IFG1 & OFIFG)); //等待起振,消除晶体失败标志 BCSCTL2 |= SELM_2 + SELS; //mclk.smclk选择高频晶振 TACTL |= TASSEL_2 + ID_3 + MC_1; //计数时钟选测smclk,8分频,增计数模式 1mhz //TBCTL |= TBSSEL_2 + ID_3+ MC_1 ; TBCTL|= TBSSEL_2 + TBCLGRP_0 + ID_3 + MC_1 ; P4SEL|=BIT2; P4DIR|=BIT2; TBCCR0 = 50; // 50us de 周期 TBCCTL1 = OUTMOD_3+CLLD_0; // TBCCTL1 &= ~CAP; TACCR0 =5000; TACCTL0 = CCIE; // 开中断使能 _EINT(); // Enter LPM0 w/ interrupt // LPM0; //低功耗 while(1); //应该不会进入此句 } #pragma vector = TIMERA0_VECTOR __interrupt void timeA() { static uchar i = 0; flag++; P2DIR = 0XFF; P2OUT = 0XFF; if(flag == 4) //大概20 ms时 较为理想 { flag = 0; TBCCR1 = table; if(i > 100) { i = 0; P2DIR = 0XFF; P2OUT = 0X00; } } }这是我写的, 你看看行不行啊
最多设置5个标签!
你这是想干嘛呢?
贴一段代码让别人帮你看,又不说是什么MCU,也不说执行完是什么结果,有没有实现自己的目的。
程序是自己改的吧?反正我是看不懂你在做什么:
在TimeA的中断服务里修改TBCCR1的数值,那么你就需要确保两个定时器同时正常工作才有效果。
一周热门 更多>