On Fri, 14 Nov 1997 11:43:27 +0100 =?ISO-8859-1?Q?Thomas_M=F8rch?= writes: ... >Is >there >any logical explanation of this behaviour? ... >The >program i'm using is as follows: ... >start bsf STATUS,RP0 > clrf PORTB This won't work. RP0 must be clear to access PORTB, as it is in page 0. > > movlw 00H > movwf TRISB ; Set port b as outputs > bsf TRISB,7 ; set pin rb7 as input > bcf OPTION_REG,7 ; make internal pull-up on portb; > You don't clear RP0 here. So what your bsf/bcf below is doing, is changing the LED pins from input to output, ouputting the random data in the PORTB register (which your program never touches) leftover from power-on. >l001 call Delay > bsf PORTB,3 ; set portb pins high > bcf PORTB,2 Even if you do clear RP0, doing bsf/bcf on PORTB is not very reliable. If you have heavy DC loads (LEDs with no resistors?) or capacitance on the output pins, doing a bsf/bcf on a port may corrupt the other bits in the port. The LED on port pin 3 may not stay as you expect it, due to the second bit operation reading the entire port. Do this instead: movlw b'00001000' ;B3 high, rest low. movwf PORTB This assumes the other pins of PORTB are inputs, or can stay at 0 all the time. If the other pins are outputting something that needs to be independent of turning the LEDs on and off, keep a copy of the state for the other pins in RAM, and change the LED bits: bsf shadowB,3 ;LED 3 on bcf shadowB,2 ;LED 3 off movfw shadowB movwf PORTB ;Update port B. Everytime you want to send something via PORTB, update the shadowB RAM first, then copy it out. The result will be correct even if the pins are overloaded.