微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > 用s12zvl32做AD模块一直不成功,求教各位大神啊

用s12zvl32做AD模块一直不成功,求教各位大神啊

时间:10-02 整理:3721RD 点击:
用s12zvl的AN7口做AD口,硬件接的是一个光度传感器,控制PT3脚的PWM占空比,一直没有成功。请教一下各位大神

#include <hidef.h> /* forEnableInterrupts macro */


#include "derivative.h" /* includeperipheral declarations */


typedef unsigned char bool;


#define ERR_OK           0;


#define ERR_NOTAVAIL    9U;


static volatile word RVL[1] __attribute__ ((aligned (4)));


static volatile bool OutFlg;


static word RatioStore;


char BLUE;


byte* i;




static void SetRatio(void)



{


  PWMDTY1 = (byte)(((0xFFUL * (dword)RatioStore) + 0x8000UL) >> 0x10U); /* Calculate new value according to the given ratio */


}


byte PWM_BLUE_SetRatio8(byte Ratio)


{


  RatioStore = (((word)Ratio << 8U) + 0x80U); /* Store new value of the ratio */


  SetRatio();                          /* Calculate and set up new appropriate values of theduty and period registers */


  return ERR_OK;                       /* OK */


}


void PWM_BLUE_Init(void)


{


    PWMCNT1 = 0x00;


    PWMDTY1 = 0x9F;


    PWMPER1 = 0xFF;


    PWMPRCLK = 0x00;


    PWMSCLA = 0x3B;


    PWMCLK = 0x02;


    PWME = 0x02U;


}


void ADC_Init(void)


{


    ADC0CTL=0x8800;


    ADC0TIM=0x07;


    ADC0FMT=0x00;


    ADC0CMD=0x00170000;


    ADC0STS=0X01;


    ADC0TIM=0X07;


    ADC0CONIE=0x01;


ADC0CONIF=0X01;


ADC0CROFF1=0x00;


ADC0EIF=0x06;


ADC0EIE=0xFC;


    ADC0IF=0xC0;


ADC0IE=0xC0;


}


byte ADC_GetValue8(byte *Values)


{


  if (!OutFlg){                       /* Is measured value(s) available? */


    return ERR_NOTAVAIL;               /* If no then error */


  }


    *Values = (byte)(RVL[0] >> 0x02U);   /* Storeconversion data to user buffer */


  return ERR_OK;                        /* OK */


}



void main(void) {


     PWM_BLUE_Init();


     ADC_Init();


  EnableInterrupts;


  /* includeyour code here */


//for(;;)


//{


    BLUE=ADC_GetValue8(i);



  PWM_BLUE_SetRatio8(BLUE);


//}


  for(;;) {


    __RESET_WATCHDOG();  /* feeds the dog */



  } /* loopforever */


  /* pleasemake sure that you never leave main */



}

请教一下各位大神啊!论坛里的大神们,求解啊,我被困扰好几天了

看一下你的主函数实现,单步运行测试就知道了

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top