Note: 使用 ADC 的同時若發現其他 PORT 的 input 值怪怪的也許是誤把那些 PORT 設成 analog input (參考 ADCON1)
ADCON0
ADCON1
ADCON2
Workflow 重要
Configure the A/D module:
Select VREF (ADCON1.VCFG0, ADCON1.VCFG1)
Select A/D port control(ADCON1.PCFG)
Select A/D input channel (ADCON0.CHS)
Select A/D conversion clock (ADCON2.ADCS)
Select A/D acquisition time (ADCON2.ACQT)
Turn on A/D module (ADCON0.ADON)
Select justified method (ADCON2.ADFM)
Configure A/D interrupt:
Clear ADIF bit
Set ADIE bit
Set GIE bit
Select IPEN bit
Configure ADIP bit
Start conversion, set ADCON0.GODONE bit
Wait for A/D acquisition&conversion complete (Wait for the A/D interrupt)
Read A/D Result registers (ADRESH:ADRESL).
For next conversion, clear ADIF for next interrupt, set GODONE again for next acquisition&convert. The A/D conversion time per bit is defined as TAD. A minimum wait of 2 TAD is required before the next acquisition starts.