18f24k20 & portb.1 (rb1)


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2009
    Posts
    10

    Default 18f24k20 & portb.1 (rb1)

    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.

    Code:
    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

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    RB1 is also AN10.
    You need to disable the analog functions on the pins you want to use as digital.

    ANSEL and ANSELH
    <br>
    DT

  3. #3
    Join Date
    Mar 2009
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    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.

  4. #4
    Join Date
    Mar 2009
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    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

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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.
    DT

Similar Threads

  1. solar tracker controller
    By CIRE in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 15th November 2016, 15:16
  2. reducing shiftout clock freq and PS2/PC interfacing ....
    By wireless magic in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 26th February 2008, 20:15
  3. angular speed and gyrometer
    By fefenin in forum mel PIC BASIC
    Replies: 25
    Last Post: - 26th March 2007, 21:04
  4. Rb1 Problem On A 16f819..
    By Calco in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th April 2004, 15:09
  5. Interupt for RB1 & RB2
    By itmsoil in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 15th March 2004, 16:11

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts