MSP430G2553单片机一个用计时器输出PWM的程序
要求是按一下点亮灯,然后越来越亮,十次后越来越暗,循环此过程。我的问题是,我用定时器写的延时函数用来防抖,只要一用这个函数,不管怎么按按钮灯都不亮,只要不使用这个函数防抖...
要求是按一下点亮灯,然后越来越亮,十次后越来越暗,循环此过程。 我的问题是,我用定时器写的延时函数用来防抖,只要一用这个函数,不管怎么按按钮灯都不亮,只要不使用这个函数防抖,程序功能就能实现。真的不知道哪错了。。求大神指点,代码如下
#include "MSP430G2553.h"
void GPIO_Init(); //GPIO初始化函数
void Timer_A_Init();
void BCS_Init();
int key = 0;
unsigned int keydown = 0;
int main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
GPIO_Init();
BCS_Init();
TACTL |= MC_1 + TASSEL_2;
TACCTL1 = OUTMOD_7;
TACCR0 = 512 - 1;
_EINT();
while (1) {
if (key < 11) {
TACCR1 = 512/10*key ;
} else {
TACCR1 = 512 / 10 * (20 - key);
}
};
}
void GPIO_Init() //GPIO初始化函数
{
P1DIR |= BIT6; //设定P1.0,P1.6为输出
P1OUT |= BIT6; //设定P1.0的值
P1SEL |= BIT6;
P1REN |= BIT3; //启用内部上下拉电阻
P1OUT |= BIT3; //将电阻设为上拉
P1DIR &= ~BIT3; //P1.3设为输入(可省略)
P1IES |= BIT3; //P1.3设为下降沿中断
P1IE |= BIT3; //允许中断
}
#pragma vector = PORT1_VECTOR
__interrupt void PORT1_ISR(void) {
Timer_A_Init();
}
void Timer_A_Init() {
TA1CTL = TASSEL_2 + MC_1 + TACLR; //SMCLK、下降沿触发、定时器清零
TA1CCR0 = 10000; //10ms
TA1CCTL0 |= CCIE;
}
#pragma vector=TIMER1_A0_VECTOR
__interrupt void Timer_A0_ISR(void) {
if (((P1IN & BIT3)==0)&&key<20){
key++;
}
if (((P1IN & BIT3)==0)&&key>=20){
key = 0;
}
}
void BCS_Init() {
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
BCSCTL2 &= ~SELS;
} 展开
#include "MSP430G2553.h"
void GPIO_Init(); //GPIO初始化函数
void Timer_A_Init();
void BCS_Init();
int key = 0;
unsigned int keydown = 0;
int main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
GPIO_Init();
BCS_Init();
TACTL |= MC_1 + TASSEL_2;
TACCTL1 = OUTMOD_7;
TACCR0 = 512 - 1;
_EINT();
while (1) {
if (key < 11) {
TACCR1 = 512/10*key ;
} else {
TACCR1 = 512 / 10 * (20 - key);
}
};
}
void GPIO_Init() //GPIO初始化函数
{
P1DIR |= BIT6; //设定P1.0,P1.6为输出
P1OUT |= BIT6; //设定P1.0的值
P1SEL |= BIT6;
P1REN |= BIT3; //启用内部上下拉电阻
P1OUT |= BIT3; //将电阻设为上拉
P1DIR &= ~BIT3; //P1.3设为输入(可省略)
P1IES |= BIT3; //P1.3设为下降沿中断
P1IE |= BIT3; //允许中断
}
#pragma vector = PORT1_VECTOR
__interrupt void PORT1_ISR(void) {
Timer_A_Init();
}
void Timer_A_Init() {
TA1CTL = TASSEL_2 + MC_1 + TACLR; //SMCLK、下降沿触发、定时器清零
TA1CCR0 = 10000; //10ms
TA1CCTL0 |= CCIE;
}
#pragma vector=TIMER1_A0_VECTOR
__interrupt void Timer_A0_ISR(void) {
if (((P1IN & BIT3)==0)&&key<20){
key++;
}
if (((P1IN & BIT3)==0)&&key>=20){
key = 0;
}
}
void BCS_Init() {
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
BCSCTL2 &= ~SELS;
} 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏30(财富值+成长值)
推荐于2016-10-11
展开全部
Form formPreview = new Form();
public Leaf(string name) : base(name) { }
public override void Add(Component c)
{
Console.WriteLine("Cannot add to a leaf");
}
public override void Remove(Component c)
{
Console.WriteLine("Cannot remove to a leaf");
}
public override void Display(int depth)
{
Console.WriteLine(new string('-',depth)+name);
}
}
public Leaf(string name) : base(name) { }
public override void Add(Component c)
{
Console.WriteLine("Cannot add to a leaf");
}
public override void Remove(Component c)
{
Console.WriteLine("Cannot remove to a leaf");
}
public override void Display(int depth)
{
Console.WriteLine(new string('-',depth)+name);
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询