您好,我使用的是 PIC24H 微处理器,我编写了一个简单的程序,该程序使用模拟输入从 POT 获取输入,然后将其设置为延迟的模值。它似乎确实设置了延迟,但从左到右的进展似乎是随机且不一致的。帮助会很棒!谢谢!
int main (void){
AD1CON1bits.ADON=0;
AD1CON1=0x00E0;
AD1CON1bits.AD12B=1;
AD1CON3=0x8000;
AD1CON2=0x8000;
AD1CHS0=0x0000;
AD1CON1bits.ADON=1;
int wtdState;
int delay;
int temp;
// Set Analog Input Pin
_CN2PUE=0;
_TRISA0=1;
_PCFG0=0;
//Set Digital Output Pins
_ODCB15=0;
_TRISB15=0;
_LATB15=0;
_ODCB14=0;
_TRISB14=0;
_LATB14=1;
while(1){
wtdState = _SWDTEN;
_SWDTEN=1;
AD1CON1bits.SAMP=1;
Nop();
while(!AD1CON1bits.DONE){}
_SWDTEN = wtdState;
temp = ADC1BUF0;
delay = temp%225+25;
__delay_ms(delay);
_LATB15=1;
__delay_ms(delay);
_LATB15=0;
}
}