此帖出自嵌入式系统论坛
最新回复
我自己写了一个,找问题给分
#include "MSP430x22x4.h"
#define MAXSTEP 1000-1 // clk 1mHz /1k freq required=1000 step
#define DUTYCYCLE10 100 //dutycycle 10
#define DUTYCYCLE30 300 //dutycycle 30
#define DUTYCYCLE50 500 //dutycycle 50
#define DUTYCYCLE70 700 //dutycycle 70
#define DUTYCYCLE90 900 //dutycycle 90
#define STATUS1 0xC //input combination
#define STATUS2 0xA
#define STATUS3 0x8
#define STATUS4 0x6
#define STATUS5 0x4
#define ENABLE1 0xC //interrupt enable setting
#define ENABLE2 0xA
#define ENABLE3 0x8
#define ENABLE4 0x6
#define ENABLE5 0x4
unsigned int dutycyle = DUTYCYCLE10;
unsigned int start = DUTYCYCLE10;
unsigned int end = DUTYCYCLE30;
void init_port1(void)
{
P1DIR = 0x1; //P1.0 ouput
P1SEL = 0x1; //timer A output P1.0
P1IE = 0xE; //Enable interrupt
P1IFG = 0x0; //Clear flag
// POR input status detection in order to set Interrupt edge
switch(P1IN&0xOE)
{
case STATUS1: //Input P1.1, P1.2 and P1.3 STATUS
start = DUTYCYCLE90; //set starting dutycle
end = DUTYCYCLE10; //set ending dutycle
P1IES = ENABLE1; //reset interrupt ENABLE
break;
case STATUS2:
start = DUTYCYCLE70; //set starting dutycle
end = DUTYCYCLE30; //set ending dutycle
P1IES = ENABLE2; //reset interrupt ENABLE
break;
case STATUS3:
start = DUTYCYCLE50; //set starting dutycle
end = DUTYCYCLE50; //set ending dutycle
P1IES = ENABLE3;//reset interrupt ENABLE
break;
case STATUS4:
start = DUTYCYCLE30; //set starting dutycle
end = DUTYCYCLE70; //set ending dutycle
P1IES = ENABLE4; //reset interrupt ENABLE
break;
case STATUS5:
start = DUTYCYCLE10; //set starting dutycle
end = DUTYCYCLE90; //set ending dutycle
P1IES = ENABLE5; //reset interrupt ENABLE
break;
default:
start = DUTYCYCLE90; //set starting dutycle
end = DUTYCYCLE10; //set ending dutycle
P1IES = ENABLE1; //reset interrupt ENABLE
break;
}
}
void main (void)
{
WDTCTL = WDTPW + WDTHOLD; //Stop watch dog
BCSCTL1 = CALBC1_1MHZ; //(0x10FF)è?¨DCO??1MHZ
DCOCTL = CALDCO_1MHZ
init_port1();
TACTL = TASSEL1 + TACLR; // SMCLK, clear
TACTL = MC_1+CNTL_0+TACLGRP_0; //up,16 bits
TACCTL0 = CCIE; //timer seting
TACCTL1 = OUTMOD_7+CLLD_1; //mode 7
TACCR0 = MAXSTEP; //PWM freq
TACCR1 = DUTYCYCLE10; //duty cycle
_EINT();
LPM0;
}
#pragma vector=TIMERA0_VECTOR
__interrupt void TimerA0_ISR(void)
{
if (end>=start)
{
if(dutycyle>=start)&(dutycyle=end)&(dutycyle
详情
回复
发表于 2008-12-21 07:06
| ||
|
||
此帖出自嵌入式系统论坛
| ||
|
||
EEWorld Datasheet 技术支持