代码:
/*
* File: newmain.c
* Author: Administrator
*
* Created on May 29, 2024, 3:29 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <string.h>
#pragma config POSCMOD= XT
#pragma config OSCIOFNC= OFF
#pragma config FCKSM= CSDCMD
#pragma config FNOSC= FRCDIV
#pragma config IESO= ON
#pragma config WDTPS= PS32768
#pragma config FWPSA= PR128
#pragma config WINDIS= OFF
#pragma config FWDTEN= ON
#pragma config ICS= PGx2
#pragma config GWRP= OFF
#pragma config GCP= OFF
#pragma config JTAGEN= OFF
/*
*
*/
#define POT 5
#define AINPUTS 0XFFDF
void delay(void)
{
int i,j;
for(i=0;i<200;i++)
for(j=0;j<200;j++)
;
}
void initADC(int amask)
{
AD1PCFG=amask;
//AD1CON1=0X00E0;
AD1CON1=0X0000;
AD1CSSL=0;
AD1CON2=0;
AD1CON3=0X1F04;
AD1CON1bits.ADON=1;
}
int readADC(int ch)
{
AD1CHS=ch;
AD1CON1bits.SAMP=1;
///////////////////////////
TMR1=0;
//PORTA=1;
while(TMR1<100);
PORTA=2;
AD1CON1bits.SAMP=1;
<font color="#ff0000"> while(!AD1CON1bits.DONE);</font>
TMR1=0;
while(TMR1<200);
PORTA=4;
return ADC1BUF0;
}
void main(void)
{
int a;
initADC(AINPUTS);
TRISA=0xff00;
TRISE=0;
//TRISBbits.TRISB5=1;
T1CON=0X8020;
while(1)
{
a=readADC(POT);
a=(a>>2);
//PORTE=(unsigned char)(a);
}
}
红色的那句执行不过去。
芯片是pic24fj128ga010,环境是xc16.
请问高手,怎么回事?谢谢!
|