//*****************************************************************************
// * main.c
// ******************************************************************************
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
PMM_unlockLPM5();
CS_init();
IO_Init();
Timer_Init();
Ad_init();
while(1)
{
// ADC12_B_startConversion(ADC12_B_BASE, ADC12_B_MEMORY_0, ADC12_B_SINGLECHANNEL);
//LPM0, ADC12_A_ISR will force exit
__bis_SR_register(LPM0_bits + GIE);
//for Debugger
__no_operation();
GPIO_setOutputLowOnPin(GPIO_PORT_P2,GPIO_PIN0);
GPIO_setOutputHighOnPin(GPIO_PORT_P2,GPIO_PIN0);
}
return 0;
}
//*****************************************************************************
// * main.c
// ******************************************************************************
void CS_init()
{
// Set PJ.4 and PJ.5 as Secondary Module Function Input, LFXT.
/* Initializes Clock System DCO = 8MHz */
CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_3);
CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2);
CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2 );
CS_initClockSignal(CS_ACLK, CS_VLOCLK_SELECT, CS_CLOCK_DIVIDER_1);
}
//*****************************************************************************
// * main.c
// ******************************************************************************
void Ad_init(void)
{
ADC12_B_initParam param1 = {0};
ADC12_B_configureMemoryParam param = {0};
GPIO_setAsPeripheralModuleFunctionOutputPin(
GPIO_PORT_P3,
GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3,
GPIO_TERNARY_MODULE_FUNCTION
);
// param1.sampleHoldSignalSourceSelect=ADC12_B_SAMPLEHOLDSOURCE_SC;
param1.sampleHoldSignalSourceSelect=ADC12_B_SAMPLEHOLDSOURCE_1;
param1.clockSourceSelect=ADC12_B_CLOCKSOURCE_MCLK;
param1.clockSourceDivider=ADC12_B_CLOCKDIVIDER_1;
param1.clockSourcePredivider=ADC12_B_CLOCKPREDIVIDER__1;
param1.internalChannelMap=ADC12_B_NOINTCH;
ADC12_B_init(ADC12_B_BASE,¶m1);
ADC12_B_setupSamplingTimer(ADC12_B_BASE,
ADC12_B_CYCLEHOLD_64_CYCLES,
ADC12_B_CYCLEHOLD_4_CYCLES,
ADC12_B_MULTIPLESAMPLESENABLE);
param.memoryBufferControlIndex = ADC12_B_MEMORY_0;
param.inputSourceSelect = ADC12_B_INPUT_A12;
param.refVoltageSourceSelect = ADC12_B_VREFPOS_AVCC_VREFNEG_VSS;
param.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
param.windowComparatorSelect = ADC12_B_WINDOW_COMPARATOR_DISABLE;
param.differentialModeSelect = ADC12_B_DIFFERENTIAL_MODE_DISABLE;
ADC12_B_configureMemory(ADC12_B_BASE ,¶m);
ADC12_B_clearInterrupt(ADC12_B_BASE,ADC12IFG0,0);
ADC12_B_enableInterrupt(ADC12_B_BASE, ADC12IE0,0,0);
ADC12_B_enable(ADC12_B_BASE);
}
//*****************************************************************************
// * main.c
// ******************************************************************************
void Timer_Init(void)
{
/*
Timer_A_initUpModeParam htim = {0};
htim.clockSource = TIMER_A_CLOCKSOURCE_SMCLK; //
// htim.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_2; //
htim.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_32; //
htim.timerPeriod = TIMER_PERIOD - 1; //
htim.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_ENABLE; //
// htim.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE; //
htim.captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_DISABLE;
// htim.timerClear = TIMER_A_DO_CLEAR; //
htim.timerClear = TIMER_A_SKIP_CLEAR; //
htim.startTimer = false; //
Timer_A_initUpMode(TIMER_A0_BASE, &htim);
*/
/*
Timer_A_initContinuousModeParam initContParam = {0};
Timer_A_initUpModeParam Param={0};
initContParam.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;
initContParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
initContParam.timerInterruptEnable_TAIE=TIMER_A_TAIE_INTERRUPT_ENABLE;
initContParam.timerClear=TIMER_A_DO_CLEAR;
initContParam.startTimer = true;
Timer_A_initContinuousMode(TIMER_A1_BASE, &initContParam);
*/
/*
//Start timer in continuous mode sourced by SMCLK
Timer_A_initContinuousModeParam initContParam = {0};
initContParam.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;
initContParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
initContParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE;
initContParam.timerClear = TIMER_A_DO_CLEAR;
initContParam.startTimer = false;
Timer_A_initContinuousMode(TIMER_A1_BASE, &initContParam);
//Initiaze compare mode
Timer_A_clearCaptureCompareInterrupt(TIMER_A1_BASE,
TIMER_A_CAPTURECOMPARE_REGISTER_0
);
*/
/*
Timer_A_initCompareModeParam initCompParam = {0};
initCompParam.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;
initCompParam.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE;
// initCompParam.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE;
initCompParam.compareOutputMode = TIMER_A_OUTPUTMODE_TOGGLE;
// initCompParam.compareOutputMode = TIMER_A_OUTPUTMODE_SET_RESET;
initCompParam.compareValue = 10;
Timer_A_initCompareMode(TIMER_A0_BASE, &initCompParam);
*/
Timer_A_outputPWMParam htim1 = {0};
htim1.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;
htim1.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_32;
htim1.timerPeriod = TIMER_PERIOD - 1;
htim1.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;
htim1.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET;
htim1.dutyCycle = TIMER_PERIOD / 2 ;
Timer_A_outputPWM(TIMER_A0_BASE, &htim1);
// Timer_A_startCounter( TIMER_A0_BASE, TIMER_A_UP_MODE );
}
//*****************************************************************************
// * main.c
// ******************************************************************************
void IO_Init(void)
{
GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);
GPIO_setAsOutputPin(GPIO_PORT_P2,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);
GPIO_setAsOutputPin(GPIO_PORT_P3,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);
GPIO_setAsOutputPin(GPIO_PORT_P4,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);
// GPIO_setOutputLowOnPin(GPIO_PORT_P1,GPIO_PIN0);
GPIO_setOutputHighOnPin(GPIO_PORT_P1,GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);
GPIO_setOutputHighOnPin(GPIO_PORT_P2,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);
GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);
GPIO_setOutputHighOnPin(GPIO_PORT_P4,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);
// GPIO_setAsInputPin(GPIO_PORT_P1,GPIO_PIN0);
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1,GPIO_PIN0,GPIO_PRIMARY_MODULE_FUNCTION);
}
刚才代码贴错了
//*****************************************************************************
// * main.c
// ******************************************************************************
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
PMM_unlockLPM5();
CS_init();
IO_Init();
Timer_Init();
Ad_init();
while(1)
{
// ADC12_B_startConversion(ADC12_B_BASE, ADC12_B_MEMORY_0, ADC12_B_SINGLECHANNEL);
//LPM0, ADC12_A_ISR will force exit
__bis_SR_register(LPM0_bits + GIE);
//for Debugger
__no_operation();
GPIO_setOutputLowOnPin(GPIO_PORT_P2,GPIO_PIN0);
GPIO_setOutputHighOnPin(GPIO_PORT_P2,GPIO_PIN0);
}
return 0;
}
//*****************************************************************************
// * main.c
// ******************************************************************************
void CS_init()
{
// Set PJ.4 and PJ.5 as Secondary Module Function Input, LFXT.
/* Initializes Clock System DCO = 8MHz */
CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_3);
CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2);
CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2 );
CS_initClockSignal(CS_ACLK, CS_VLOCLK_SELECT, CS_CLOCK_DIVIDER_1);
}
//*****************************************************************************
// * main.c
// ******************************************************************************
void Ad_init(void)
{
ADC12_B_initParam param1 = {0};
ADC12_B_configureMemoryParam param = {0};
GPIO_setAsPeripheralModuleFunctionOutputPin(
GPIO_PORT_P3,
GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3,
GPIO_TERNARY_MODULE_FUNCTION
);
// param1.sampleHoldSignalSourceSelect=ADC12_B_SAMPLEHOLDSOURCE_SC;
param1.sampleHoldSignalSourceSelect=ADC12_B_SAMPLEHOLDSOURCE_1;
param1.clockSourceSelect=ADC12_B_CLOCKSOURCE_MCLK;
param1.clockSourceDivider=ADC12_B_CLOCKDIVIDER_1;
param1.clockSourcePredivider=ADC12_B_CLOCKPREDIVIDER__1;
param1.internalChannelMap=ADC12_B_NOINTCH;
ADC12_B_init(ADC12_B_BASE,¶m1);
ADC12_B_setupSamplingTimer(ADC12_B_BASE,
ADC12_B_CYCLEHOLD_64_CYCLES,
ADC12_B_CYCLEHOLD_4_CYCLES,
ADC12_B_MULTIPLESAMPLESENABLE);
param.memoryBufferControlIndex = ADC12_B_MEMORY_0;
param.inputSourceSelect = ADC12_B_INPUT_A12;
param.refVoltageSourceSelect = ADC12_B_VREFPOS_AVCC_VREFNEG_VSS;
param.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
param.windowComparatorSelect = ADC12_B_WINDOW_COMPARATOR_DISABLE;
param.differentialModeSelect = ADC12_B_DIFFERENTIAL_MODE_DISABLE;
ADC12_B_configureMemory(ADC12_B_BASE ,¶m);
ADC12_B_clearInterrupt(ADC12_B_BASE,ADC12IFG0,0);
ADC12_B_enableInterrupt(ADC12_B_BASE, ADC12IE0,0,0);
ADC12_B_enable(ADC12_B_BASE);
}
//*****************************************************************************
// * main.c
// ******************************************************************************
void Timer_Init(void)
{
/*
Timer_A_initUpModeParam htim = {0};
htim.clockSource = TIMER_A_CLOCKSOURCE_SMCLK; //
// htim.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_2; //
htim.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_32; //
htim.timerPeriod = TIMER_PERIOD - 1; //
htim.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_ENABLE; //
// htim.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE; //
htim.captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_DISABLE;
// htim.timerClear = TIMER_A_DO_CLEAR; //
htim.timerClear = TIMER_A_SKIP_CLEAR; //
htim.startTimer = false; //
Timer_A_initUpMode(TIMER_A0_BASE, &htim);
*/
/*
Timer_A_initContinuousModeParam initContParam = {0};
Timer_A_initUpModeParam Param={0};
initContParam.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;
initContParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
initContParam.timerInterruptEnable_TAIE=TIMER_A_TAIE_INTERRUPT_ENABLE;
initContParam.timerClear=TIMER_A_DO_CLEAR;
initContParam.startTimer = true;
Timer_A_initContinuousMode(TIMER_A1_BASE, &initContParam);
*/
/*
//Start timer in continuous mode sourced by SMCLK
Timer_A_initContinuousModeParam initContParam = {0};
initContParam.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;
initContParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
initContParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE;
initContParam.timerClear = TIMER_A_DO_CLEAR;
initContParam.startTimer = false;
Timer_A_initContinuousMode(TIMER_A1_BASE, &initContParam);
//Initiaze compare mode
Timer_A_clearCaptureCompareInterrupt(TIMER_A1_BASE,
TIMER_A_CAPTURECOMPARE_REGISTER_0
);
*/
/*
Timer_A_initCompareModeParam initCompParam = {0};
initCompParam.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;
initCompParam.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE;
// initCompParam.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE;
initCompParam.compareOutputMode = TIMER_A_OUTPUTMODE_TOGGLE;
// initCompParam.compareOutputMode = TIMER_A_OUTPUTMODE_SET_RESET;
initCompParam.compareValue = 10;
Timer_A_initCompareMode(TIMER_A0_BASE, &initCompParam);
*/
Timer_A_outputPWMParam htim1 = {0};
htim1.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;
htim1.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_32;
htim1.timerPeriod = TIMER_PERIOD - 1;
htim1.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;
htim1.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET;
htim1.dutyCycle = TIMER_PERIOD / 2 ;
Timer_A_outputPWM(TIMER_A0_BASE, &htim1);
// Timer_A_startCounter( TIMER_A0_BASE, TIMER_A_UP_MODE );
}
//*****************************************************************************
// * main.c
// ******************************************************************************
void IO_Init(void)
{
GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);
GPIO_setAsOutputPin(GPIO_PORT_P2,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);
GPIO_setAsOutputPin(GPIO_PORT_P3,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);
GPIO_setAsOutputPin(GPIO_PORT_P4,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);
// GPIO_setOutputLowOnPin(GPIO_PORT_P1,GPIO_PIN0);
GPIO_setOutputHighOnPin(GPIO_PORT_P1,GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);
GPIO_setOutputHighOnPin(GPIO_PORT_P2,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);
GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);
GPIO_setOutputHighOnPin(GPIO_PORT_P4,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);
// GPIO_setAsInputPin(GPIO_PORT_P1,GPIO_PIN0);
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1,GPIO_PIN0,GPIO_PRIMARY_MODULE_FUNCTION);
}
刚才代码贴错了
举报