Hello... scroll down... In a message dated 2/6/00 7:17:22 PM Pacific Standard Time, sseyedi@HYPERVR.COM writes: > Hello, > RE: PIC16F84 > I am still working on this piece of code and to me it fully makes sense. But > the thing wont work. None of the LEDs get lit with the input. I tried it on > the MLAB simulator and it seems to be doing what I want it to do! > > Anybody see the problem? (or maybe have code for reading a button (or a set > of), debounce them and light an LED accordingly, this might actually be more > faster?!). > > > ------ > #include "p16f84.inc" > > LIST P=16F84, R=DEC > > > ; Register Usage > CBLOCK 0x20 ; vars to use for the delay loop > LoopCntr1,LoopCntr2 > ENDC > > > __CONFIG _CP_OFF & _XT_OSC & _PWRTE_ON & _WDT_OFF > ; Note that the WatchDog Timer is OFF > ; ** the RC oscillator does not work for some reason with an rc > oscillator?!?! > ; the funny thing is that the xt works with it though! > > > ; Note: B0 : mommentarily on push button > ; B1 : lit at all times! > ; B2 : lit if button is being pushed > > > ORG 0 > GOTO Start > > ; DELAY SUBROUTINE > ; - creates a delay by doing (for) loops > Delay MOVLW 250 > MOVWF LoopCntr1 > Outer MOVLW 110 > MOVWF LoopCntr2 > Inner NOP > NOP > DECFSZ LoopCntr2,F > GOTO Inner > DECFSZ LoopCntr1,F > GOTO Outer > RETURN > > > ; MAIN PROGRAM > ; > Start > BSF STATUS,RP0 ; select bank 1 (need to go to bank 1 since > trisb is there!) > MOVLW 0x01 ; turn b0:input, b...:output > MOVWF TRISB ; apply it to trisb register > BCF STATUS,RP0 ; select bank 0 (come back!) > BSF PORTB,1 ; turn on led on B1 (and keep lit) > > > Loop > BTFSS PORTB,0 ; Is the Button Pressed? (if PORTB<0>=0 then > ... ) > GOTO ButtonPressed ; .... turn it on > BCF PORTB,2 ; (else:) Turn off LED B2 off > GOTO Loop You should flip those instructions around. The BTFSS will SKIP the next instruction if the bit tested comes out true. So, looking at your code, when PORTB0 = 1 then it will turn off the LED. Flip the GOTO and BCF instruction around. > > ButtonPressed ; Button Pressed, Turn LED on > BSF PORTB,2 > CALL Delay > GOTO Loop > > END ; end of program. > ------ > Regards, Tim Hamel > Thanks. > > +----------------------------+ > | Sep Seyedi [:{0)] | > +----------------------------+