Simple TTL input pin coding.


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2016
    Location
    Plainfield, Illinois
    Posts
    73

    Default Simple TTL input pin coding.

    New to PIC basic - programming a 16F15324 - a substitute of the 16F616. I'm setting up pin 2 of the IC to be a simple 0 or 1 detector w 5V.

    It will not detect a 1 or a zero unless I make the pin a analog pin as shown below. I do not understand this as its a I/O pin = not analog.

    What am I not grasping here?

    port A is an input - C is an output

    please help... thanks




    #CONFIG
    __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_OFF
    __config _CONFIG2, _MCLRE_ON & _PWRTE_ON & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON
    __config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_ON & _WDTCWS_WDTCWS_6 & _WDTCCS_SC
    __config _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTSAF_OFF & _LVP_OFF
    __config _CONFIG5, _CP_ON
    #ENDCONFIG

    ANSELA = PORTA.5
    TRISC = %00000000

    LED VAR PORTC.3
    BNC1 VAR PORTA.5

    main:

    IF BNC1 = 1 THEN
    HIGH LED
    ENDIF

    goto main
    My dad never liked you...

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Simple TTL input pin coding.

    This should make it work

    TRISA.5 = 1 'make porta.5 input

    ANSELA.5 = 0' make porta.5 digital

    LED VAR LATC.3 ' Use lat for output and port for input

    It's really important to search and study the datasheet for answers. Read the datasheet starting at page 178 "Analog Control"

  3. #3
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Simple TTL input pin coding.

    pescador, "ANSELA = PORTA.5" != "TRISA.5 = 1 'make porta.5 input". You are setting your ANSELA SFR to either %00000000 or %00000001, depending on the state of PORTA.5. Neither will do what you want.
    Last edited by mpgmike; - 29th March 2022 at 12:39.

  4. #4
    Join Date
    Apr 2016
    Location
    Plainfield, Illinois
    Posts
    73


    Did you find this post helpful? Yes | No

    Default Re: Simple TTL input pin coding.

    Read the data sheet - love that answer.. First of all I wouldn't even think to look at the analog portion of the documentation since I'm not using analog inputs. The fact is the pins are defined as analog by default would have been good to know obviously. In any case - I got it to work using your code. Thank-you.
    My dad never liked you...

Similar Threads

  1. Using MCLR pin at Input
    By JakeMend in forum mel PIC BASIC
    Replies: 9
    Last Post: - 6th July 2017, 22:39
  2. Use any pin as tmr input?
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th October 2016, 20:50
  3. Mclr As Input Pin?
    By omid_juve in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th December 2007, 06:33
  4. Input pin help
    By Adrian in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd July 2007, 09:35
  5. TTL input - 3rd states possible?
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 31st March 2007, 16:04

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