Chinaunix首页 | 论坛 | 博客
  • 博客访问: 315128
  • 博文数量: 135
  • 博客积分: 867
  • 博客等级: 准尉
  • 技术积分: 865
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-15 14:50
文章分类

全部博文(135)

文章存档

2012年(135)

分类:

2012-09-19 11:39:52

原文地址:UBOOT ADC 驱动流程 作者:iibull

static inline
int xn_voltage_probe(struct xn_tool *tool)
{
    int adc_value = 0;
    int i = 0;

    printf("\nVoltage Probe:\n");

    gpio_set_pin(S3C_GPN5, S3C_GPN5_INP);
    gpio_pullup(S3C_GPN5, 0x2);
    
    
    if(gpio_get_value(S3C_GPN5) == 0)
        printf("EXTERNAL_POWER.......................................[YES]\n");
    else
        printf("EXTERNAL_POWER.......................................[NO]\n");

while(i++ < 10)

{    adc_value = get_adc_i(1);

    

    printf("BATTERY_VOLTAGE......................................[%u mv]\n",(unsigned int)(adc_value * VOLTAGE_FACTOR));

}

    wait_user_ack(tool);
    return 0;
}




static inline
int get_adc_i(int channel)
{
    volatile S3C2410_ADC * reg_adc = S3C2410_GetBase_ADC();

    reg_adc->ADCCON     = (1<<14) | (49<< 6) | (channel<<3);
    reg_adc->ADCDLY        = 40000;
    reg_adc->ADCCON     |= (1 << 0);

    while(reg_adc->ADCCON & 0x1);
    while (!(reg_adc->ADCCON & (1 << 15)));
    
    return (0x3ff & reg_adc->ADCDAT0);
}


阅读(435) | 评论(0) | 转发(0) |
0

上一篇:UBOOT 网口测试

下一篇:UBOOT 键盘防抖测试

给主人留下些什么吧!~~