本帖最后由 xianghou 于 2011-10-30 08:01 编辑
基于RL-RTX的ADC转换,结果通过串口发到电脑。
顺便说一下,新塘的数据手册写的真是烂到家了。翻了几遍了,愣是没找到VBG是多少
初始化代码
#include "NUC1xx.h"
#include "drvsys.h"
#include "drvgpio.h"
#include "drvuart.h"
#include "drvadc.h"
static void ClockInit( void )
{
UNLOCKREG();
DrvSYS_SetOscCtrl( E_SYS_XTL12M, ENABLE );
DrvSYS_SelectPLLSource( E_SYS_EXTERNAL_12M );
DrvSYS_Open(48000000);
DrvSYS_SelectSysTickSource( 3 );
}
static void UartInit( void )
{
STR_UART_T sParam;
sParam.u32BaudRate = 115200;
sParam.u8cDataBits = DRVUART_DATABITS_8;
sParam.u8cStopBits = DRVUART_STOPBITS_1;
sParam.u8cParity = DRVUART_PARITY_NONE;
sParam.u8cRxTriggerLevel = DRVUART_FIFO_1BYTES;
DrvSYS_SelectIPClockSource(E_SYS_UART_CLKSRC, INTERNAL_HCLK);
DrvUART_Open (UART_PORT0, &sParam);
DrvGPIO_InitFunction(E_FUNC_UART0_RX_TX);
}
static void ADCInit( void )
{
DrvADC_Open(ADC_SINGLE_END, ADC_SINGLE_CYCLE_OP, (1 << 1) | (1 << 7), EXTERNAL_12MHZ, 11); //Set adc parameter
DrvADC_ConfigADCChannel7( INTERNAL_BANDGAP );
DrvGPIO_InitFunction(E_FUNC_ADC1);
DrvADC_EnableSelfCalibration(); //start calibration
while(DrvADC_IsCalibrationDone() == 0);
}
void SystemInit( void )
{
ClockInit();
UartInit();
ADCInit();
}
/* 重定向PRINTF函数到串口1*/
int putchar(int __c)
{
if(DrvUART_Write(UART_PORT0, (unsigned char *)__c, 1))
return 1;
else
return 0;
}
主函数代码
#include "NUC1xx.h"
#include <rtl.h>
#include "drvgpio.h"
#include "bsp.h"
#include "drvuart.h"
#include "drvadc.h"
#include <stdio.h>
__task void ledtask( void )
{
for( ;; )
{
unsigned int i;
float j;
DrvADC_StartConvert(); //start first convert
os_dly_wait( 200 );
i = DrvADC_GetConversionData( 1 );
j = (float)i * 3.3 / 4095;
printf("The ADC Channel 1 Voltage:%1.3f V\n", j);
i = DrvADC_GetConversionData( 7 );
j = (float)i * 3.3 / 4095;
printf("The VBG Voltage:%1.3f V\n", j);
}
}
__task void taskinit( void )
{
os_tsk_create(ledtask, 1); //创建任务
os_tsk_delete_self(); //删除自己
for( ;; )
{
}
}
int main( void )
{
os_sys_init( taskinit ); //启动任务调度器
while( 1 )
{
}
}
|