How to set pin to digital by default? PIC18F24J50


+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2016
    Posts
    33

    Default How to set pin to digital by default? PIC18F24J50

    Hello there,

    I have a PIC18F24J50 and I want to set pin 0 of port A to digital pin inorder to have a push button turn an led on and off.

    I have a C code that is working and sets pin 0 of port B to digital using

    Code:
    ANCON1bits.PCFG12 = 1;
    All the C code:

    Code:
    void main(void) {
     ANCON1bits.PCFG12 = 1;          //RB0
      TRISB=1;
      TRISC=0;
      RC0=0;
      do
      {
        if(RB0 == 0) 
        {
          __delay_ms(10); 
          if(RB0 == 0) 
          {
            RC0 = 1; 
            __delay_ms(10);
            RC0 = 0;
          }
        }
      }while(1);
    }
    I am trying to do the same but I get error regarding PCFG12 that it doesn't exist!


    All basic code:


    Code:
    PCFG12=1
    TRISC.0 = 0
    TRISB = 001111
    button1 VAR PORTB.0
       
    LED VAR PORTC.0   
    PortB = 0
    mainloop:
       If button1 = 0 Then 
          Low LED      
          Pause 600
       Else
          High LED    
          Pause 600
       Endif
       Goto mainloop

    I appreciate if you help me get i working in Basic! Thanks

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,253

    Default Re: How to set pin to digital by default? PIC18F24J50

    PCFG12 is bit 4 in ANCON1 so
    Code:
    ANCON1.4 = 1
    should do it, but that's for AN12 which is RB0 while you're talking about RA0 which is AN0 so
    Code:
    ANCON0.0 = 1
    /Henrik.

  3. #3
    Join Date
    May 2016
    Posts
    33

    Default Re: How to set pin to digital by default? PIC18F24J50

    ANCON1.4 = 1 worked thanks!

Similar Threads

  1. How to set ports to digital (ALLDIGITAL.PBP)
    By RayL113 in forum FAQ - Frequently Asked Questions
    Replies: 2
    Last Post: - 30th November 2013, 02:59
  2. SPI, SCK Pin set up
    By Hylan in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 3rd January 2012, 06:23
  3. How to set a pin high an keep it there?
    By ShortBus in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 1st October 2009, 16:01
  4. How do I get 18f452 pin 10 set as digital input?
    By jessey in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 26th May 2007, 18:32
  5. Replies: 2
    Last Post: - 14th April 2006, 09:42

Tags for this Thread

Posting Permissions

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