附上code
CODE是都沒修改
就是DEBUG 小白出問題後就不能了?!!?
附上CODE 是原廠修改的
我也有用原廠的測試
出來就是65535
也有量進BNC接頭那邊的電和AI0的電壓, 中間的OP是OK的
現在不知道問題在哪...???
// Includes
//--------------------------------------------------------------------------------------
#include <c8051f060.h> // SFR declarations
#include <stdio.h>
//-----------------------------------------------------------------------------
// 16-bit SFR Definitions for 'F06x
//-----------------------------------------------------------------------------
sfr16 RCAP2 = 0xCA; // Timer2 capture/reload
sfr16 RCAP3 = 0xCA; // Timer3 capture/reload
sfr16 TMR2 = 0xCC; // Timer2
sfr16 TMR3 = 0xCC; // Timer3
sfr16 ADC0 = 0xBE; // ADC0 Data
sfr16 ADC1 = 0xBE; // ADC1 Data
sfr16 DMA0DS = 0xDB; // DMA0 XRAM Address Pointer
sfr16 DMA0CT = 0xF9; // DMA0 Repeat Counter Limit
sfr16 DMA0DA = 0xD9; // DMA0 Address Beginning
sfr16 DMA0CS = 0xFB; // DMA0 Repeat Counter
//------------------------------------------------------------------------------------
// Global CONSTANTS
//------------------------------------------------------------------------------------
#define SYSCLK 22118400 // SYSCLK frequency in Hz
#define BAUDRATE 9600 // Baud Rate for UART0
// DMA INSTRUCTIONS
#define DMA0_END_OF_OP 0x00 // End-of-Operation
#define DMA0_END_OF_OP_C 0x80 // End-of-Operation + Continue
#define DMA0_GET_ADC0 0x10 // Retrieve ADC0 Data
#define DMA0_GET_ADC1 0x20 // Retrieve ADC1 Data
#define DMA0_GET_ADC01 0x30 // Retrieve ADC0 and ADC1 Data
#define DMA0_GET_DIFF 0x40 // Retrieve Differential Data
#define DMA0_GET_DIFF1 0x60 // Retrieve Differential and ADC1 Data
#define NUM_SAMPLES 1000 // Number of ADC sample to acquire (each sample 2 bytes)
#define XRAM_START_ADD 0x0000 // DMA0 XRAM Start address of ADC data log
#define SAMP_RATE 500000 // ADC sample rate in Hz
#define DDS_FREQ 25000000
sbit LED = P0^7; // LED: '1' = ON; '0' = OFF
sbit BUTTON = P3^7; // pushbutton on the target board
sbit RAM_CS = P4^5; // chip select bit is P4^4
sbit SCLK = P3^0;
sbit SDATA = P3^2;
sbit FSYNC = P3^4;
//------------------------------------------------------------------------------------
// Function PROTOTYPES
//------------------------------------------------------------------------------------
void SYSCLK_Init (void);
void UART0_Init (void);
void PORT_Init (void);
void ADC0_Init (void);
void ADC1_Init (void);
void DMA0_Init (void);
void Timer3_Init (int counts);
void EMIF_Init (void);
void SendData(void);
void Wait_MS(unsigned int ms);
void send_data(unsigned int sd);
//void set_current_frequency(unsigned long freq);
//-------------------------
// Global Variables
//-------------------------
unsigned char Conv_Complete = 0;
unsigned int xdata * data read_ptr;
float freq;
unsigned long freqcode;
//unsigned int dataword;
//------------------------------------------------------------------------------------
// MAIN Routine
//------------------------------------------------------------------------------------
void main (void)
{
WDTCN = 0xde; // disable watchdog timer
WDTCN = 0xad;
SYSCLK_Init (); // initialize SYSCLK
PORT_Init ();
EMIF_Init (); // Storing ADC samples in SRAM on the
// target board.
SFRPAGE = CONFIG_PAGE;
RAM_CS = 0; // assert SRAM chip select
UART0_Init (); // initialize UART0
Wait_MS(2000);
Wait_MS(2000);
freq = 50;
freq = freq / 25000.0;
freqcode = 0xffffffff * freq;
send_data(0xF800);
send_data(0x3300 | ((freqcode >>24) & 0xff));
send_data(0x2200 | ((freqcode >>16) & 0xff));
send_data(0x3100 | ((freqcode >> 8) & 0xff));
send_data(0x2000 | ((freqcode >> 0) & 0xff));
//send_data(0x3300);
//send_data(0x2202);
//send_data(0x319F);
//send_data(0x2016);
send_data(0xC000);
//*/
//set_current_frequency(20000);
ADC0_Init (); // configure ADC0 and ADC1 for differential
ADC1_Init (); // measurement.
Wait_MS(1000);
Wait_MS(1000);
DMA0_Init (); // Configure DMA to move NUM_SAMP samples.
SFRPAGE = UART0_PAGE;
Timer3_Init (SYSCLK/SAMP_RATE); // Init Timer3 for 100ksps sample rate
printf ("Data Acquisition in progress...\n");
SFRPAGE = DMA0_PAGE; // Switch to DMA0 Page
while (!(DMA0CN & 0x40)); // Wait for DMA to obtain and move ADC samples
// by polling DMA0INT bit.
SFRPAGE = LEGACY_PAGE;
printf ("Data Acquisition complete.\nPress P3.7 button when ready to receive file!\n");
while (BUTTON != 0); // Wait for user to press P3.7 on the TB.
SendData(); // Send data via the UART0.
while(1); // Done.
}
void send_data(unsigned int sd)
{
FSYNC = 0;
SDATA = 0x8000 & sd; SCLK = 0; sd = sd << 1; SCLK = 1;
SDATA = 0x8000 & sd; SCLK = 0; sd = sd << 1; SCLK = 1;
SDATA = 0x8000 & sd; SCLK = 0; sd = sd << 1; SCLK = 1;
SDATA = 0x8000 & sd; SCLK = 0; sd = sd << 1; SCLK = 1;
SDATA = 0x8000 & sd; SCLK = 0; sd = sd << 1; SCLK = 1;
SDATA = 0x8000 & sd; SCLK = 0; sd = sd << 1; SCLK = 1;
SDATA = 0x8000 & sd; SCLK = 0; sd = sd << 1; SCLK = 1;
SDATA = 0x8000 & sd; SCLK = 0; sd = sd << 1; SCLK = 1;
SDATA = 0x8000 & sd; SCLK = 0; sd = sd << 1; SCLK = 1;
SDATA = 0x8000 & sd; SCLK = 0; sd = sd << 1; SCLK = 1;
SDATA = 0x8000 & sd; SCLK = 0; sd = sd << 1; SCLK = 1;
SDATA = 0x8000 & sd; SCLK = 0; sd = sd << 1; SCLK = 1;
SDATA = 0x8000 & sd; SCLK = 0; sd = sd << 1; SCLK = 1;
SDATA = 0x8000 & sd; SCLK = 0; sd = sd << 1; SCLK = 1;
SDATA = 0x8000 & sd; SCLK = 0; sd = sd << 1; SCLK = 1;
SDATA = 0x8000 & sd; SCLK = 0; sd = sd << 1; SCLK = 1;
FSYNC = 1;
SDATA = 0x8000 & sd;//拖時間
}
//------------------------------------------------------------------------------------
// PORT_Init
//------------------------------------------------------------------------------------
//
// Configure the Crossbar and GPIO ports
//
void PORT_Init (void)
{
char old_SFRPAGE = SFRPAGE;
SFRPAGE = CONFIG_PAGE; // Switch to configuration page
XBR0 = 0x04; // Enable UART0 on crossbar
XBR1 = 0x00;
XBR2 = 0x40; // Enable crossbar and weak pull-ups
P0MDOUT |= 0xFF; // enable Port0 outputs as push-pull
P3MDOUT |= 0x15;
SFRPAGE = old_SFRPAGE; // restore SFRPAGE
FSYNC = 1;
SCLK = 1;
}
//-----------------------------------------------------------------------------
// UART0_Init
//-----------------------------------------------------------------------------
//
// Configure the UART0 using Timer1, for ?baudrate? and 8-N-1.
//
void UART0_Init (void)
{
char old_SFRPAGE = SFRPAGE;
SFRPAGE = UART0_PAGE; // Switch to UART0 page
SCON0 = 0x50; // SCON: mode 1, 8-bit UART, enable RX
SSTA0 = 0x10; // Timer 1 generates UART0 baud rate and
// UART0 baud rate divide by two disabled
SFRPAGE = TIMER01_PAGE; // Switch to Timer 0/1 page
TMOD = 0x20; // TMOD: timer 1, mode 2, 8-bit reload
TH1 = -(SYSCLK/BAUDRATE/16); // set Timer1 reload value for baudrate
TR1 = 1; // start Timer1
CKCON |= 0x10; // Timer1 uses SYSCLK as time base
PCON |= 0x80; // SMOD = 1
SFRPAGE = UART0_PAGE; // Switch to UART0 page
TI0 = 1; // Indicate TX ready
SFRPAGE = old_SFRPAGE; // restore SFRPAGE
}
//-----------------------------------------------------------------------------
// SYSCLK_Init
//-----------------------------------------------------------------------------
void SYSCLK_Init (void)
{
char old_SFRPAGE = SFRPAGE;
int i;
SFRPAGE = CONFIG_PAGE; // Switch to Configuration Page
OSCXCN = 0x67; // start external oscillator with
// 22.1184MHz crystal on TB
for (i=0; i <5000; i++) ; // XTLVLD blanking interval (>1ms)
while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle
RSTSRC = 0x04; // enable missing clock detector reset
CLKSEL = 0x01; // change to external crystal
OSCICN = 0x00; // disable internal oscillator
SFRPAGE = old_SFRPAGE; // restore SFRPAGE
}