大红鹰娱乐官网风格切换切换到宽版
  • 5200阅读
  • 3回复

[求助]R8C1B R5F211B4 ADC問題 [复制链接]

上一主题 下一主题
离线jxchen
 

只看楼主 倒序阅读 使用道具 楼主  发表于: 2014-04-25
我現在有問題,設定 AN8為 ADC INPUT讀取值都是"0",不曉得問題在哪邊,能否請各位幫忙看看,我將程序貼上,與線路圖

/***********************************************************************/
/*                                                                     */
/*  FILE        :R8C1B4.c                                              */
/*  DATE        :Wed, Feb 19, 2014                                     */
/*  DESCRIPTION :main program file.                                    */
/*  CPU GROUP   :1B                                                    */
/*                                                                     */
/*  This file is generated by Renesas Project Generator (Ver.4.19).    */
/*  NOTE:THIS IS A TYPICAL EXAMPLE.                                    */
/***********************************************************************/

#include "sfr_r81B.h"

void main(void);
void InitIoPort(void);
void InitSysClk(void) ;
void InitADC(void);

#pragma SBDATA Count
volatile unsigned char Count;
volatile unsigned char Thz,TLz;
unsigned int ADC_Result[1];


#pragma SBDATA sym_data
  struct sym_data
  {
     char bit0:1;
    char bit1:1;
    char bit2:1;
    char bit3:1;
    char bit4:1;
    char bit5:1;
    char bit6:1;
    char bit7:1;
}sym_data;






void main(void)
{
       asm("FCLR I");                           /* Interrupt disable */
         prc0=1;                                  /* Protect ClK Reg off */
         InitSysClk();
     prc0=0;                                  /* Protect ClK Reg on */
     InitIoPort();  
     InitADC();
        
        
    //     asm("FSET I");                           /* Interrupt Enable */
          while (1)
         {
        
            adst = 1;                                                                 //adc start convert
            while (ir_adic==0);                      
            ADC_Result[1]=ad;
            ir_adic = 0;
            asm("nop");
            asm("nop");
            adst = 0;        
      }
}      
/****************************************/
void InitIoPort(void)
{
      
    Pd1&=~0x01;

}
void InitSysClk(void)
{
   /****************************************/
   /*          CPU Clock Setting       */
   /****************************************/
   /* Note: Include asm("nop")for oscillator's stabilization period after clock setting is done. */
        // 8 mz No  division
    cm05=1;cm02=0;cm14=0;ocd0=0;ocd1=0;hra00=1;hra01=1;/* High speed on-chip oscillator selected(cm0 bit 2 and 5, cm1 bit 4, ocd bit 0 and 1)  (hra01 = 1 使用高速時鐘),(cm05 =1 主時鐘停止)*/
    ocd2=1;                                  /* High speed on-chip oscillator selected(ocd bit 2) ( ocd2 = 1;  使用晶片內時鐘)*/
    cm16=0;cm17=0;cm06=0;                    /* No division selected(cm0 bit 6,cm1 bit 6 and 7)   ( cm17 = 0;  cm06 = 0;) //使用CM16和CM17設定的分頻比*/
}    



/****************************************/
/*         ADC Setting                    */
/****************************************/
    /* When using the repeat mode, use the undivided XIN clock as the CPU clock */
    /* Note:For 8-bit resolution, when conversion finished, read AD result at AD register(00C0H). */
    /* Note:For 10-bit resolution, when conversion finished, read AD result at AD register(00C0H,00C1H). */
    /* Set AN8 pin to input port direction */
    
//use singal mode,10bit    mode,anglog input of P1.0(AN8)
//use 8mhz
void InitADC(void)
{
    unsigned int i;
//    vcut=1;adgsel0=1;ch0=0;ch1=0;ch2=1;      /* Port P1 group: AN8 is selected(adcon0 bit 0-3) *
//    md=0;                                    /* One-shot mode selected(adcon0 bit 3) */
//    cks1=0; cks0=1;                          /* f2 selected(adcon1 bit 4 and adcon0 bit 7) */
//    bits=1;                                  /* 10-bit mode selected(adcon1 bit 3) */
//    smp=0;                                   /* Without sample and hold selected(adcon2 bit 0) */
//    adst=0;                                  /* A/D conversion stop(adcon0 bit 6) */
//    for (i=0;i<50000;i++);                     //for let verf voltage,so need to delay
//    adic=0x00;                               /* Set interrupt priority level 0(adic) */    
    

//AD setting
    ch0=0;ch1=0;ch2=1;                /* Port P1 group: AN8 is selected(adcon0 bit 0-3) */
    vcut=1;adgsel0=1;                      
    md=0;                                    //One-shot mode selected(adcon0 bit 3)
    cks1=1; cks0=0;                          //f1 selected(adcon1 bit 2 and adcon0 bit 7)
    bits=1;                                  //10-bit mode selected(adcon1 bit 1)
    smp=1;                                   //With sample and hold selected(adcon2 bit 0)
    adcap = 0;
        adst=0;
        for (i=0;i<100;i++)             //for let verf voltage,so need to delay
        {
          _NOP();
        }

    adic = 0;                /* Set interrupt priority level 0(adic) */

    ir_adic=0;
}    
离线foss

只看该作者 沙发  发表于: 2014-04-27
1.检查一下ADC_IN是否有电压? 调一下R2看看
2. ADC的参考电压是否选择?
介于牛A与牛C之间
离线lpmine

只看该作者 板凳  发表于: 2014-05-13
有把P4。2脚设定为AD的参考电压输入脚功能吗?
你不知,我知时,你问,我答!
离线jxchen

只看该作者 地板  发表于: 2014-05-18
有把P4。2脚设定为AD的参考电压输入脚功能吗?
vcut=1;我有把它設定為 "1"
博聚网