4.28

来源:互联网 发布:新浪微博名人个性域名 编辑:程序博客网 时间:2024/06/05 08:54
#include "S3C2451_adc.h"


//#define ADCCON (*(volatile unsigned *)0x58000000)
//#define ADCTSC (*(volatile unsigned *)0x58000004)
//#define ADCDLY (*(volatile unsigned *)0x58000008)
//#define ADCDAT0 (*(volatile unsigned *)0x5800000c)
//#define ADCDAT1 (*(volatile unsigned *)0x58000010)
//#define ADCUPDN (*(volatile unsigned *)0x58000014)
//#define ADCMUX (*(volatile unsigned *)0x58000018)


// 使用查询方式读取A/D转换值
int read_adc(int resolution)
{
    // 使能预分频功能,设置A/D转换器的时钟 = PCLK/(65+1)
rADCCON = (1<<16)|(1 << 14) | (65 << 6) | (resolution << 3);


    // 清除位[2],设为普通转换模式,禁止read start
rADCCON &= ~((1<<2)|(1<<1));


    // 设置位[0]为1,启动A/D转换
rADCCON |= (1 << 0);


    // 当A/D转换真正开始时,位[0]会自动清0
    while (rADCCON & (1 << 0));


    // 检测位[15],当它为1时表示转换结束
    while (!(rADCCON &  (1 << 15)) );


    // 读取数据
    return (rADCDAT0 & 0xfff);
}
0 0