#include <GLOBAL.h>
#include <stdlib.h>
#include <stdbool.h>
#include <msp430x21x2.h>
#define PulseOneDirIn P2DIR &= ~BIT2//---'A'
#define PulseTwoDinIn P2DIR &= ~BIT1//---'B'
#define PulseThrDinIn P2DIR &= ~BIT0//---'C'
extern void PwmInit(void);
extern void PwmConn(unsigned int *DataDptr,unsigned int TimesliceFg);
extern void CommInit(long baud);
extern void ComConn(unsigned int *DataDptr,unsigned int TimesliceFg);
extern void LedConn(unsigned int *DataDptr,unsigned int TimesliceFg);
extern void MotoCon(unsigned int *DataDptr,unsigned int TimesliceFg);
extern void SetDcoConn(void);
extern void MotoInit(void);
extern void AutoRun(void);
extern void MotoRun(void);
extern void MotoDrv(void);
extern void AclkInit(void);
extern char TaPwmInit(unsigned char Clk,unsigned char Div,char Mode1,unsigned char Mode2);
extern void SinLowInt(unsigned char InitMode);
extern void SinHigInt(unsigned char InitMode);
extern void ChkInit(void);
extern void ChkPick(unsigned int *DataDptr,unsigned int TimesliceFg);
void InitRTC(void)
{
WDTCTL = WDTPW + WDTHOLD; // 禁止看门狗
if (CALBC1_16MHZ ==0xFF || CALDCO_16MHZ == 0xFF)
{
SetDcoConn();
}
DCOCTL = 0;
BCSCTL1 = CALBC1_16MHZ;
DCOCTL = CALDCO_16MHZ;
BCSCTL2 |= SELM_0 + DIVM_0;//---MCLK=16M
WDTCTL=WDT_ADLY_16;//-----工作于定时状态
IE1|=WDTIE;//--------------使能看门狗定时中断
}
int main(void)
{
_DINT();
InitRTC();
ChkInit();
CommInit(9600);
PwmInit();
SpeedData=3000;
_EINT();
for(;;)
{
LedConn((unsigned int *)&HigSpeed,0x0001);
ChkPick((unsigned int *)&HigSpeed,0x0002);
}
}
//-----中断间隔0.016
#pragma vector=WDT_VECTOR
__interrupt void WDT_Delay(void)
{
HigSpeed=0xffff;
if(MotoErrTime!=0)
{
MotoTime--;
}
if(MotoStrTime!=0)
{
MotoStrTime--;
}
else if(MotoStrTime==1)
{
MotoSt=0;
SpeedData=2500;
}
else
{
MotoSt=0;
AutoRunEn=0;
SpeedData=2500;
MotoStrTime=125;
}
}
|