Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

btfsc instruction

Status
Not open for further replies.

gregmcc

Member
I seem to having endless problems with this simple instruction.

If I have the following code:

movlw b'00000000'
btfsc W, 0
goto Intrusion
goto Main

According to the datasheet - btfsc: If bit is set then skip next instruction. On the above bit zero is clear so it should execute the next instruction. Why's it that my mode keeps jumping to Main :(
 
gregmcc said:
I seem to having endless problems with this simple instruction.

If I have the following code:

movlw b'00000000'
btfsc W, 0
goto Intrusion
goto Main

According to the datasheet - btfsc: If bit is set then skip next instruction. On the above bit zero is clear so it should execute the next instruction. Why's it that my mode keeps jumping to Main :(

You need to try reading the datasheet! - BTFSC can't be used on the W register, only on file registers - the only reason it assembles OK is that W is in the include file as a destination.
 
Thanks - that might explain why I was having trouble :)

I've done a search through the 16F62X datasheet and under the BTFSC instruction it doesn't mention anything about not using the W register. Unless of course I'm not reading it correctly, which by this stage anything is possible. <grin>
 
gregmcc said:
Thanks - that might explain why I was having trouble :)

I've done a search through the 16F62X datasheet and under the BTFSC instruction it doesn't mention anything about not using the W register. Unless of course I'm not reading it correctly, which by this stage anything is possible. <grin>

It's in a section for action only on file registers - W is defined in the include file as either 0 or 1 (can't remember which as you never need to know). So your line actually read:

btfsc 1, x

or

btfsc 0, x
 
To test bit 0 of W you can do the following,
Code:
     andlw  b'00000001'
     btfss  STATUS,Z
     goto   BitWasOne

To test a different or multiple bits just change the 0's to 1's.
The above does of course corrupt W.

Mike.
 
To test bit 0 of W you can do the following,

Code:
Code:
 andlw  b'00000001'
     btfss  STATUS,Z
     goto   BitWasOne
To test a different or multiple bits just change the 0's to 1's.
The above does of course corrupt W.

Mike.

Z: Zero bit
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
 

Attachments

  • andexample.GIF
    andexample.GIF
    4.7 KB · Views: 299
gregmcc said:
Thanks - I'll paste that right into my code :)

Or just copy W to a file register, and check that - this doesn't alter the W register.

Using ANDLW is really a 'non-PIC' method though, most processors don't have bit-wise instructions, and logical operations on the entire byte are the only way to test, or modify, individual bits. PIC's are designed for low level operations, and thus have bit-wise operators - you may as well use them?.

Code:
movlw b'00000000' 
movwf Temp
btfsc Temp, 0
goto Intrusion
goto Main
 
Pommie said:
To test bit 0 of W you can do the following,
Code:
     andlw  b'00000001'
     btfss  STATUS,Z
     goto   BitWasOne

To test a different or multiple bits just change the 0's to 1's.
The above does of course corrupt W.

Mike.
Above code is right???
plz guide me that
if W = 0000 0001 AND Litrel = 0000 0001 then Z = ???
 
Ayne said:
Above code is right???
plz guide me that
if W = 0000 0001 AND Litrel = 0000 0001 then Z = ???

0000 0001 AND 0000 0001 = 0000 0001
0000 0001 is not equal to 0
Therefore Zero flag = Not True = 0

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top