Joined: 07 Dec 2004 Posts: 127 Location: Southampton, UK
Compiler bug with setup_adc_ports in v4.109
Posted: Tue Aug 03, 2010 8:52 am
Hi all,
I just thought I would show you something that seems to be a bug. I suppose it doesn't strictly count as a compiler bug as it is with one of the supplied functions, setup_adc_ports();
The problem is that on an 18F87J11 (80 pins and includes port H) I want to use H7 as an input but it was always reading zero despite having turned off all the additional pin functions. I was using:
setup_adc_ports(NO_ANALOGS);
Expecting this to set all ANx pins to be digital IO but it misses H7. Here is the listing of what it does including my interpretation:
Code:
Work = 0xff
.................... setup_adc_ports(NO_ANALOGS);
1945A: BSF FC0.4 - Set the ADSHR bit to 1 accessing ANCONX not ADCONX
1945C: MOVWF FC1 - Move 0xFF to ANCON0 setting all pins to digital IO
1945E: BCF FC0.4 - Clear the ADSHR bit to 0 accessing ADCONX not ANCONX
19460: BCF FC2.6 - Set -Vref = AVss
19462: BCF FC2.7 - Set +Vref = AVdd
19464: BSF FC0.4 - Set the ADSHR bit to 1 accessing ANCONX not ADCONX
19466: MOVF FC2,W - Move the ANCON1 register to work (ANCON1 = 0x00 on POR)
19468: ANDLW 80 - Work AND 0x80 (0x00)
1946A: IORLW 7F - Work OR 0x7f (0x7F)
1946C: MOVWF FC2 - Put the work register back into the ANCON1 register (Sets ANCON1 0x7F from POR leaving AN15 as analogue)
1946E: BCF FC0.4 - Clear the ADSHR bit to 0 accessing ADCONX not ANCONX
So ANCON1 gets set to 0x7f from the power up value of 0x00 which leaves pin H7 (AN15) as an analogue input (bit 7 is set to 0) rather than digital IO (bit 7 set to 1).
Please let me know if you think I have got this right. I have not looked into it any closer, I just wrote my own setup_a2d_ports function.
Cheers
Ed
mkuang
Joined: 14 Dec 2007 Posts: 257
Posted: Tue Aug 03, 2010 9:59 am
Looks like you are right.
EdWaugh
Joined: 07 Dec 2004 Posts: 127 Location: Southampton, UK
Posted: Tue Aug 03, 2010 10:04 am
Thanks!
I guess I should submit it as a proper bug report.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum