#include "s5pc100.h"
#include "uart.h"
void hex2str(unsigned int l, unsigned int h, char *hex)
{
if (l < 10)
hex[0] = l + '0';
else
hex[0] = l - 10 + 'A';
if (h < 10)
hex[1] = h + '0';
else
hex[1] = h - 10 + 'A';
}
void int2hex(unsigned int val, char *str)
{
unsigned int a, b, c;
a = (val >> 16) & 0xFF;
b = (val >> 8) & 0xFF;
c = (val >> 0) & 0xFF;
hex2str(a & 0xF, (a >> 4) & 0x0F, str);
hex2str(b & 0xF, (b >> 4) & 0x0F, str + 2);
hex2str(c & 0xF, (c >> 4) & 0x0F, str + 4);
str[6] = '\0';
}
void delay(int ms)
{
int i;
while (ms--) {
i = 4000;
while (i--);
}
}
int main()
{
unsigned int val;
char str[16];
//使用12bit模式,AD转换预分频使能,65分频,读的时候开始使能转换
ADC.ADCCON = (1 << 16) | (1 << 14) | (65 << 6) | (1 << 1);
ADC.ADCTSC = 0x58;
ADC.ADCDLY = 0;
ADC.ADCCLRINT = 0;//清除中断
ADC.ADCMUX = 0;//选择端口0
ADC.ADCPNDCLR = 0;
val = ADC.ADCDAT0 & 0xFFF;//读取一次初值,开始启动转换
while (1) {
while (!(ADC.ADCCON & (1 << 15)));
val = ADC.ADCDAT0 & 0xFFF;
int2hex(val, str);
puts("current adc value is: 0x");
puts(str);
puts("\n");
delay(1000);
}
return 0;
}
源码下载:
点击打开链接
Cortex A8,ADC转换程序
最新推荐文章于 2022-12-30 18:36:57 发布