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

2019-07-15 17:29发布

用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 */

}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
2条回答
864491892
1楼-- · 2019-07-15 23:25
 精彩回答 2  元偷偷看……
waterbaby2012
2楼-- · 2019-07-16 03:02
看一下你的主函数实现,单步运行测试就知道了

一周热门 更多>