CC2530F256 ADC测试

#include <ioCC2530.h>

int h,l;

void init(void)
{
	CLKCONCMD	= 0x28; 		//System clock-source select:32MHz,Timer ticks output setting:250kHz
	while(CLKCONSTA & ~0x28);	//wait for CLKCONCMD selected
	
	PERCFG	= 	0x00;			//alternative 1 location
	P0SEL	= 	0x3c;			//P0_2:RX	P0_2:TX	P0_2:CT	P0_2:RT
	P2DIR	&=	~0xc0;			//set port 0 1st priority: USART 0 2nd priority: USART 1 3rd priority: Timer 1
	
	U0CSR	|=	0x80;			//usart mode select : UART mode
	U0GCR	|=	9;				
	U0BAUD	|=	59;				//set baud rate:19200
	UTX0IF	=	1;				//USART 0 TX interrupt flag : interrupt pending
	
	APCFG	|=	0x80;			//P0_7 analog I/O enable
	P0SEL	|=	0x80;			//P0_7 function select peripheral function
	P0DIR	&=	~0x80;			//p0_7 Input
}

void get_adc(void)
{
	ADCIF	=	0;				
	ADCCON3	=	(0x80 | 0x30 | 0x07);
	while(!ADCIF);
	h = ADCH;
	l = ADCL;
}

void delay(int n)
{
	int i, j;
	for(i = 0; i < n; i++)
		for(j = 0; j < n; j++);
}
void uart_send(int arg)
{
	int j;
	while(1)
	{
		j = arg % 10;
		arg /= 10;
		U0DBUF = j + 48;
		while(!UTX0IF);
		UTX0IF = 0;
		if(arg == 0)break;
	}
}
void main(void)
{
		init();
		while(1)
		{
			get_adc();
			uart_send(h);
			uart_send(l);
			U0DBUF = '\n';
			while(!UTX0IF);
			UTX0IF = 0;
			delay(300);
		}
}

  功能:实时将电压值捕获传输至UART。
test
  转动开发板上的蓝色旋钮可观察到电压变化。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值