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