button - Simple PIC16F684 Input/Output -
i'm having trouble should simple piece of code. objective turn led on while button being pressed. in case input logic go low when press button. led connected portc.2 , button connected portc.0. here code:
dim test bit main: trisc = %00000001 ansel = %00000000 portc= 0 cmcon0=0 testbutton: test = portc.0 if test = 0 portc = %00000100 goto testbutton end if portc = %00000000 end.
the problem pic outputs high no matter input is. far have used multimeter verify input indeed changing 5v 0v when button pressed, have tried using different input pin, , have tried using different pic. suspect since input being read low pic may not initialized i'm not entirely sure.
thanks insight might able give me
the datasheet of 16f684 states on page 42 :
the ansel , cmcon0 registers must initialized configure analog channel digital input. pins configured analog inputs read ‘0’.
these registers initialized in code. ansel initialized 0, analog input deactivated. yet, the cmcon0 register should initialized xxxxx111 or 07h. see example 4.3 on page 42. last 3 bits of cmcon0 correspond mode of operation of comparators , choosing 111 turns them off. see page 60.
don't forget add goto testbutton
if want led light again button released. may intentional though : it's !
Comments
Post a Comment