Cortex A8,ADC转换程序

#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;
}
源码下载: 点击打开链接
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值