这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 企业专区 » Renesas » RL78 AD采样功能模块

共2条 1/1 1 跳转至

RL78 AD采样功能模块

助工
2012-09-10 00:00:20     打赏

今天先上传部分代码吧,实在是时间紧,没来得及仔细编辑一下
#define SINGLE_MODE 0x00
#define SCAN_MODE   0x40
#define AD_MAX_VALUE 0xff
#define AD_MIN_VALUE 0x00

enum chanel_select
{
    SINGLE_ADCH0, SINGLE_ADCH1, SINGLE_ADCH2, SINGLE_ADCH3, SINGLE_ADCH4, SINGLE_ADCH5,
    SINGLE_ADCH6, SINGLE_ADCH7, SINGLE_ADCH8, SINGLE_ADCH9, SINGLE_ADCH10,SINGLE_ADCH11,
    SINGLE_ADCH12,SINGLE_ADCH13,SINGLE_ADCH14,SINGLE_ADCH16 = 16, SINGLE_ADCH17, SINGLE_ADCH18,
    SINGLE_ADCH19,SINGLE_ADCH20,SINGLE_ADCH21,SINGLE_ADCH22,SINGLE_ADCH23,SINGLE_ADCH24,
    SINGLE_ADCH25,SINGLE_ADCH26,ADTEMPERSENSOR0 = 128, ADTEMPERSENSOR1
}

enum convert_mode_select
{
    SOFT_TRIG_SEQUENTIAL_MODE,
    SOFT_TRIG_ONE_SHOT_MODE,
    HARD_TRIG_NO_WAIT_SEQUENTIAL_MODE = 4,
    HARD_TRIG_NO_WAIT_ONE_SHOT_MODE,
    HARD_TRIG_WAIT_SEQUENTIAL_MODE,
    HARD_TRIG_WAIT_ONE_SHOT_MODE
}

enum freq_select
{
    FCLK_64,FCLK_32,FCLK_16,FCLK_8,FCLK_6,FCLK_5,FCLK_4,FCLK_2
}
int Set_AD_Mode(enum chanel_select chanel,int chanel_mode,enum freq_select freq_ad,enum convert_mode_select convert_mode)
{  
    ADM0 |= chanel_mode;

    if((chanel_mode == 15)||((chanel_mode > 26)&&(chanel_mode <128)))||(chanel_mode > 129))
    {
        return ERROR;
    }
    else
    {
        ADS = chanel;
    }

    if(freq_ad > 8)
    {
        return ERROR;
    }
    else
    {
        ADM0 |= (freq_ad<<3);
    }
   
    ADM1 |= convert_mode;
}

int Init_AD_Converter()
{  
    ADCEN = 1; /* supply AD clock */
    ADMK = 1; /* disable INTAD interrupt */
    ADIF = 0; /* clear INTAD interrupt flag */

    /* Set INTAD priority as level 3*/
    ADPR1 = 1;
    ADPR0 = 1;

    PM2 = 0x01;/*set ANI0 pin as analog input to convert*/
   
    Set_AD_Mode(SINGLE_ADCH0, SINGLE_MODE ,FCLK_64 ,SOFT_TRIG_SEQUENTIAL_MODE);
   
    /*Set INTAD. If not, covertion result will not be saved in ADCR register*/
    ADRCK = 0;
    ADUL = AD_MAX_VALUE;
    ADLL = AD_MIN_VALUE;
   
}




关键词: 采样     功能模块     SINGLE     chanel    

菜鸟
2013-09-02 22:00:54     打赏
2楼

嗯嗯看看学习一下子



共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]