PDA

View Full Version : 18f24k20 & portb.1 (rb1)



bmagistro
- 8th March 2009, 18:26
Hello all,

Finally have a question that the search hasn't answered for me. I have a pic18f24k20 that reads 8 a/d lines and then based on the values of the a/d lines it controls 8 additional output pins that control other things in this case an optoisolator. My issues is this: portb.1 will not go high when in a check loop for say a/d channel. The code runs and says it goes high but the output does not. However if I type high portb.1 in the main program loop it will take it high accordingly. This is the only issue I am having at this time with the code. The block of code being referenced is shown below along with appropriate registers.

Thanks for the help in advance. Btw, great site.



OSCCON = %01010111 'configure oscillator settings
define OSC 4 'define oscillator as 4 Mhz

TRISA = %00101111
TRISB = %11111101
TRISC = %11000000

batcell1:
'PortB.2-AN8, PortB.1-RB1
adcon2 = %10110100
adcon0 = %00100001
Pauseus 50
adcon0.1 = 1
While ADCON0.1=1:Wend
adtmp.HighByte=ADRESH
adtmp.LowByte=ADRESL
rawad[0] = adtmp
adval[0] = rawad[0]

if adval[0] => turnon then
bypass[0] = 1
high PORTB.1
else
bypass[0] = 0
low PORTB.1
endif
return

Darrel Taylor
- 9th March 2009, 01:44
RB1 is also AN10.
You need to disable the analog functions on the pins you want to use as digital.

ANSEL and ANSELH
<br>

bmagistro
- 9th March 2009, 03:46
Thanks for the reply I will give that a try tomorrow. I am still confused as to why it works in the main program loop that calls that sub show above with out having those set. I will let you know if it works.

bmagistro
- 9th March 2009, 19:51
well what do you know...it works now. Many thanks. I guess I kinda missed the part about that changing when enabling A/D....oops

Darrel Taylor
- 9th March 2009, 20:01
If only Microchip would leave all that stuff turned OFF on power-up, things would be a lot easier.

And this forum would have a couple thousand fewer threads. :)

Glad you got it working.