Sep, -----Original Message----- From: sep To: PICLIST@MITVMA.MIT.EDU Date: Monday, February 07, 2000 12:29 AM Subject: problem with code |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 Even the LED at RB1 (who is always 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! ??? Which is the source of clock in your micro?(Type and speed) | | | ; 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 | Assuming the micro is running with 4 MHz Xtal, the delay looks fine. | |; MAIN PROGRAM |; |Start | BSF STATUS,RP0 ; select bank 1 | 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>=0then ... ) | GOTO ButtonPressed ; .... turn it on | BCF PORTB,2 ; (else:) Turn off LED B2 off | GOTO Loop | |ButtonPressed ; Button Pressed, Turn LED on | BSF PORTB,2 | CALL Delay | GOTO Loop | | END ; end of program. |------ | |Thanks. | |+----------------------------+ || Sep Seyedi [:{0)] | |+----------------------------+ Are You setting correctly the programmer? An what about Your hardware? Is the input pin RB0 connected correctly to the pullup, and the swith to GND? Regards, S.-