Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

BCF, BSF instructions on PIC 18F

Status
Not open for further replies.

zristic

Junior Member level 3
Joined
Aug 29, 2004
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
249
bsf pic

I am not sure yet, but it seems that BCF and BSF instructions on Pic 18F series behave very odd when a PORT is set to input mode. For example, if you do this:
MOVLW 255
MOVWF TRISB
BCF PORTB, 0
BSF PORTB, 1

then it seems there is no effect when using those instructions. However, if you do this:

MOVLW 255
MOVWF TRISB
MOVLW 2
MOVWF PORTB

then the last insctruction does set PORTB properly.

I do not actually need to change PORTB when it is in input mode, I am just curious why BCF and BSF fail to do so, but MOVWF works OK.
 

pic bsf

In ANY PIC the bsf and bcf instructions affect the port pins only if they are defined as outputs. In your case, the first two instructions set the port pins as inputs, so the bsf, bcf have NO effect. Nor does the movwf.
I doubt the second section of code works properly, since the pins are still inputs. There must be something else that makes you think it works, including some short in H/W.
If you want to change the state of the pins, please make them outputs.

There is a difference in the PIC18 vs other PICs, however. The ports have latches, that will always get set, regardless of the pin direction. The pin will only output the state of the latch when it is an output. (LATB in your case). These do not explain in any way the effect you are descrinbing, though.

Therefore, my advice is make sure you are not seeing the effect of something else when you check the pin levels. It could be something in Hw, too.
 

bsf bcf

Thanks.
 

bcf bsf

Hi,

Just curious are you zoran ristic from the mikroelectronica group. The question seems to be newbie.!!!!

Regards

Sougata
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top