开门狗没开,m0516应该工作了,按键按下后电路开始工作,ad开始升高,奇怪之处就是仅仅改变x的值就工作异常了.
main(void)
{
uint32_t k=3690,uc=0,back=0xff,ks=0xff,x=0;
Un_Lock_Reg();
PWRCON |= XTL12M_EN;
while((CLKSTATUS & XTL12M_STB) == 0); //Wait until 12M clock is stable.
CLKSEL0 = (CLKSEL0 & (~HCLK)) | HCLK_12M; //Set external crystal as the system clock
if(ADC_CLK_Source==0x00000004 )
{
PLLCON |= PLL_SEL;
PLL_Enable();
/* Wait until PLL is stable. */
while((CLKSTATUS & PLL_STB) == 0);
}
Timer0_Init();
/* Reset ADC */
set_ADC_RST;
clr_ADC_RST;
/* ADC engine clock enable */
set_ADEN_CLK;
if (ADC_CLK_Source==0x00000000 )
{
ADCClkSource_ex12MHZ;
}
else if(ADC_CLK_Source==0x00000004 )
{
ADCClkSource_PLL;
}
else if(ADC_CLK_Source==0x00000008 )
{
ADCClkSource_int22MHZ;
}
/* Set ADC divisor */
CLKDIV=ADC_CLOCK_DIVIDER;
/* ADC enable */
set_ADEN;
set_CALEN; //Self Calibration Enable
while(!(ADCALR&CALDONE));
/* Single-Cycle scan mode */
setAD_SIGSCAN;
/* Single end input */
clr_DIFFEN;
/* Set the ADC channel */
set_CHEN0;
set_CHEN1;
set_CHEN2;
set_CHEN3;
set_CHEN4;
set_CHEN5;
set_CHEN6;
set_CHEN7;
/* Configure P1.0,P1.1 as analog input pin */
set_ADC0_channel;
set_ADC1_channel;
set_ADC2_channel;
set_ADC3_channel;
set_ADC4_channel;
set_ADC5_channel;
set_ADC6_channel;
set_ADC7_channel;
/* Disable P1.0, P1.1 digital input path */
P1_OFFD |= OFFD0;
P1_OFFD |= OFFD1;
P1_OFFD |= OFFD2;
P1_OFFD |= OFFD3;
P1_OFFD |= OFFD4;
P1_OFFD |= OFFD5;
P1_OFFD |= OFFD6;
P1_OFFD |= OFFD7;
/* Configure P1.0,P1.1 as input mode */
P10_InputOnly;
P11_InputOnly;
P12_InputOnly;
P13_InputOnly;
P14_InputOnly;
P15_InputOnly;
P16_InputOnly;
P17_InputOnly;
/*ÅäÖóÉÊä³öģʽ*/
P2_PMD=0x5555;
/* Clear the A/D interrupt flags for safe */
set_ADF;
KG=1;
CD=1;
TMR0_Delay1ms(50);
FD=0;
TMR0_Delay1ms(50);
FD=1;
while(1)
{
/***************************************************/
uc=1000; |