有哪位仁兄用过这种类型的单片机啊?我编的ADC1的程序老是采集到的值为oxffff;ADC0的程序正常! 最好推荐些参考程序! 下面是我的程序: #include "C8051F060.h" #include <stdio.h> #include <intrins.h> #define SYSCLK 24000000 unsigned int result1=0; unsigned int result2=0; unsigned int result0=0; unsigned int result =0; void ADC_Init(void); //void ADC1_Init(void); void DAC0_Init(void); void Timer4_ISR(void); void Timer4_Init(unsigned long counts); void SYSCLK_Init(void); void Delay_ms(unsigned int count); void ADC0_Cover(void); void ADC1_Cover(void); void SYSCLK_Init(void); void PORT_Init(void); void Init_Device(void); void Uart0_Init(void); void main (void) { xdata unsigned char a[4]; int i,j; unsigned char y[2][20]={"DianYa:
","DianLiu:
"}; unsigned char *p; WDTCN = 0xde; WDTCN = 0xad; Init_Device(); while(1) { //Delay_ms(250); //Delay_ms(250); //Delay_ms(250); // Delay_ms(250); ADC1_Cover(); Timer4_Init(6400); EA =1; P2=0x16; ADC0_Cover(); result=((result0/91)*0.5)*2700; a[0] = result>>8; a[1] = result&0x00ff; P2=0x17; ADC0_Cover(); result=result0*240*250; a[2] = result>>8; a[3] = result&0x00ff; i=0; for (j = 0; j < 2; j++) { unsigned char i = 0; p=y[j]; while(*p) { SBUF0 = *p++; while(!TI0); // 等特数据传送 TI0 = 0; // 清除数据传送标志 } TI0 = 0; SBUF0 = a[i++]; while(!TI0); TI0 = 0; SBUF0 = a[i++]; while(!TI0); } } } void Init_Device(void) { SYSCLK_Init(); PORT_Init(); ADC_Init(); //ADC1_Init(); DAC0_Init(); Uart0_Init(); } void PORT_Init (void) { char data SFRPAGE_SAVE = SFRPAGE; SFRPAGE = 0x0F; XBR0 = 0x04; XBR2 = 0x40; P0MDOUT = 0x01; P2MDOUT = 0xFF; SFRPAGE = SFRPAGE_SAVE; } void Delay_ms( unsigned int count) //延时函数 { unsigned char i,j; for(i=0;i<count;i++) { for(j=0;j<250;j++) _nop_(); } } void ADC_Init() { char data SFRPAGE_SAVE = SFRPAGE; SFRPAGE = 0x00; AMX0SL=0x00; REF0CN=0x03; ADC0CF=0x00; ADC0CN=0xc0; SFRPAGE = 0x01; REF1CN=0x03; ADC1CF=0x00; ADC1CN=0xc0; SFRPAGE = SFRPAGE_SAVE; } //void ADC1_Init() //{ // char data SFRPAGE_SAVE = SFRPAGE; //SFRPAGE = 0x00; //AMX0SL=0x00; // SFRPAGE = 0x01; // AMX0SL = 0x00; //REF1CN=0x03; //ADC1CF=0x00; //ADC1CN=0x80; //SFRPAGE = SFRPAGE_SAVE; //} void ADC1_Cover (void) { char data SFRPAGE_SAVE = SFRPAGE; SFRPAGE = 0x01; Delay_ms(2); AD1INT = 0; //SFRPAGE = 0x00; AD1BUSY = 1; //Delay_ms(2); //SFRPAGE = 0x01; while (!AD1INT); result1 = ADC1H; result2 = ADC1L; SFRPAGE = SFRPAGE_SAVE; }
void ADC0_Cover (void) { unsigned int data temp; char data SFRPAGE_SAVE = SFRPAGE; SFRPAGE = 0x00; Delay_ms(2); AD0INT = 0; AD0BUSY = 1; while (!AD0INT); temp = ADC0H; temp = temp*256 + ADC0L; result0 = temp; SFRPAGE = SFRPAGE_SAVE; } void DAC0_Init(void) { char data SFRPAGE_SAVE = SFRPAGE; SFRPAGE = 0x02; REF2CN = 0x03; SFRPAGE = 0x00; DAC0CN = 0x84; SFRPAGE = SFRPAGE_SAVE; } void Timer4_Init (unsigned long counts) { char data SFRPAGE_SAVE = SFRPAGE; SFRPAGE = 0x02; TMR4CN&=~0x04; RCAP4H = (65536-SYSCLK/counts)/256; RCAP4L = (65536-SYSCLK/counts)&256; TMR4CF = 0x08; TMR4CN = 0x04; EIE2 |= 0x04; SFRPAGE = SFRPAGE_SAVE; } void Timer4_ISR (void) interrupt 16 using 3 { char data SFRPAGE_SAVE = SFRPAGE; SFRPAGE = 0x02; TMR4CN &=~0x80; SFRPAGE = 0x00; DAC0L=result2; DAC0H=result1; SFRPAGE = SFRPAGE_SAVE; } void SYSCLK_Init(void) { int i; char data SFRPAGE_SAVE = SFRPAGE; SFRPAGE = CONFIG_PAGE; OSCXCN = 0x67; for (i=0; i<256;i++) ; while (!(OSCXCN&0x80)); RSTSRC = 0x04; CLKSEL = 0x01; OSCICN = 0x00; SFRPAGE = SFRPAGE_SAVE; } void Uart0_Init(void) { char data SFRPAGE_SAVE = SFRPAGE; SFRPAGE = UART0_PAGE; SCON0 = 0x50; SFRPAGE = 0x00; SSTA0 = 0x10; TMOD = 0x20; TCON = 0x40; CKCON = 0x10; PCON |= 0x80; TH1 = 0xf3; TL1 = TH1; SFRPAGE = SFRPAGE_SAVE; } |