请各位帮帮我吧,我刚刚开始用C8051F410 的ADC和DAC,但是AD转换老出问题,采集不了外部电压,帮我看看ADC的配置以及时钟设置,谢谢了
//
#include "C8051F410.h"
#define SYSCLK 24500000 // SYSCLK频率(Hz)
// Peripheral specific initialization functions,
// Called from the Init_Device() function
void ADC_Init()
{
ADC0MX = 0x06;
ADC0CN = 0x80;
ADC0TK = 0xFB;
ADC0CF = ((SYSCLK/6000000)-1)<<3;
ADC0CF |= 0x00; // right-justify results
}
void DAC_Init()
{
IDA0CN = 0xF7;
}
void Voltage_Reference_Init()
{
REF0CN = 0x90;
}
void Port_IO_Init()
{
// P0.0 - Skipped, Push-Pull, Analog
// P0.1 - Unassigned, Push-Pull, Digital
// P0.2 - Unassigned, Push-Pull, Digital
// P0.3 - Unassigned, Push-Pull, Digital
// P0.4 - Unassigned, Push-Pull, Digital
// P0.5 - Unassigned, Push-Pull, Digital
// P0.6 - Skipped, Push-Pull, Analog
// P0.7 - Unassigned, Push-Pull, Digital
// P1.0 - Unassigned, Push-Pull, Digital
// P1.1 - Unassigned, Push-Pull, Digital
// P1.2 - Skipped, Push-Pull, Analog
// P1.3 - Unassigned, Push-Pull, Digital
// P1.4 - Unassigned, Push-Pull, Digital
// P1.5 - Unassigned, Push-Pull, Digital
// P1.6 - Unassigned, Push-Pull, Digital
// P1.7 - Unassigned, Push-Pull, Digital
// P2.0 - Unassigned, Push-Pull, Digital
// P2.1 - Unassigned, Push-Pull, Digital
// P2.2 - Unassigned, Push-Pull, Digital
// P2.3 - Unassigned, Push-Pull, Digital
// P2.4 - Unassigned, Push-Pull, Digital
// P2.5 - Unassigned, Push-Pull, Digital
// P2.6 - Unassigned, Push-Pull, Digital
// P2.7 - Unassigned, Push-Pull, Digital
P0MDIN = 0xBE;
P1MDIN = 0xFB;
P0MDOUT = 0xFF;
P1MDOUT = 0xFF;
P2MDOUT = 0xFF;
P0SKIP = 0x41;
P1SKIP = 0x04;
XBR1 = 0x40;
}
void Oscillator_Init()
{
OSCICN = 0x87; // configure internal oscillator for
// 24.5MHz
RSTSRC = 0x04; // enable missing clock detector
}
void Interrupts_Init()
{
EIE1 = 0x08;
IE = 0x80;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
ADC_Init();
DAC_Init();
Voltage_Reference_Init();
Port_IO_Init();
Oscillator_Init();
Interrupts_Init();
}
// Close WDT
// Call WDT_DISABLE() from the main program
void WDT_DISABLE(void)
{
EA=0;
PCA0MD = ~0x40 ;
EA=1;
}
void main(void)
{
// unsigned char i = 0;
WDT_DISABLE(); //关闭WDT;
Init_Device(); //主初始化;
while(1)
{
// for(i = 0;i < 32000;i++);
AD0BUSY = 1; //开AD
while(AD0BUSY); //等待AD转换结束
while(AD0INT)
{
IDA0L = ADC0L;
IDA0H = ADC0H;
AD0INT = 0;
}
}
}
急救呀!!!! |