请花三分钟帮我看看我的程序,谢谢!
我自己编的一个小程序,将AD转换后的数据采到片内XRAM,LED亮表示数据采集完成.但运行总是有问题,请各位大侠花点时间帮我看看,谢谢指教.谢谢!
#include <c8051f060.h>
sfr16 ADC0 = 0xBE;
#define SYSCLK 22118400
#define NUM_SAMPLES 100
sbit LED = P1^6;
void SYSCLK_Init (void);
void PORT_Init (void);
void ADC0_Init (void);
void EMIF_Init (void);
void SYSCLK_Init (void)
{
char old_SFRPAGE = SFRPAGE;
int i;
SFRPAGE = CONFIG_PAGE;
OSCXCN = 0x67;
for (i=0; i <5000; i++) ;
while (!(OSCXCN & 0x80)) ;
RSTSRC = 0x04;
CLKSEL = 0x01;
OSCICN = 0x00;
SFRPAGE = old_SFRPAGE;
}
void ADC0_Init (void)
{
char old_SFRPAGE = SFRPAGE;
int i;
SFRPAGE = ADC0_PAGE;
AMX0SL = 0x00;
REF0CN = 0x03;
for(i=0;i <10000;i++);
ADC0CF = (SYSCLK/25000000) < < 4;
ADC0CN = 0xC0;
SFRPAGE = old_SFRPAGE;
}
void EMIF_Init (void)
{
char SFRPAGE_SAVE = SFRPAGE;
SFRPAGE = EMI0_PAGE;
EMI0CF = 0x30;
EMI0TC = 0x45;
SFRPAGE = CONFIG_PAGE;
P4MDOUT |= 0xFF;
P5MDOUT |= 0xFF;
P6MDOUT |= 0xFF;
P7MDOUT |= 0xFF;
SFRPAGE = SFRPAGE_SAVE;
}
void PORT_Init (void)
{
char old_SFRPAGE = SFRPAGE;
SFRPAGE = CONFIG_PAGE;
XBR2 = 0x40;
P1MDOUT |= 0x40;
SFRPAGE = old_SFRPAGE;
}
void main (void)
{
unsigned int xdata write_address0 = 0;
unsigned int xdata write_address1 = 1;
int i;
WDTCN = 0xde;
WDTCN = 0xad;
SYSCLK_Init ();
PORT_Init ();
EMIF_Init ();
ADC0_Init ();
LED =0 ;
SFRPAGE = ADC0_PAGE;
for(i=0;i <100;i++)
{
AD0INT=0;
AD0BUSY=1;
while(AD0INT==0);
if(AD0INT==1)
{
write_address0 = ADC0L;
write_address1 = ADC0H;
write_address0++;
write_address1++;
AD0INT=0;
}
}
LED =1;
while(1);
[解决办法]
unsigned int xdata write_address0 = 0;
unsigned int xdata write_address1 = 1;
不知道你的这两个是什么用意,呵呵
后面使用像是指针,但是却以变量在定义
请好好看一下C语言里的指针相关的章节