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.

Bit Testing Question ... why does'nt it work.

Status
Not open for further replies.

fenderman

Member
Hi,
I'm playing with a 16F628A to produce a test frequency for some other electronic equipment I'm building.
I needed an 'astable' type operation, so thought I'd try a PIC, (I only need a few Khz so well within its capability)

The first section of code does not work at all ... yet the data sheet indicates that both the MOVF instrunction and the ANDLW instruction conditions the 'Z' flag, what am I missing ?

The second section of code, using a direct bit test works perfectly ....

I just wondered why the first one does'nt work at all.
Test.asm is attached (Just for reference ... not executable)

(Sorry, not discovered how to include formatted code into a post yet ... any help would be appreciated)

Roy
 

Attachments

  • TEST.asm
    378 bytes · Views: 123
Last edited:
Your first bit of code doesn't work because you have the test the wrong way around.

Code:
		BTFSC	STATUS,Z
		GOTO	TURN_OFF
This will goto Turn_Off if the zero flag is set - I.E. the port was already zero.

To include code in your post put
Code:
 before and [/co[U][/U]de] after the relevant section.

Mike.
 
Cheers Mike,

Course it is !!!!

I feel a right plonker !!!!! .... should of spotted that one.

I'll give the code addition thing a try next time.

Roy
 
Greetings Roy,

Many of us get confused with those darned STATUS register condition test instructions. They're ok if you look at them carefully and 'think' about them but I've found the alternative pseudo assembler instructions much easier and more intuitive (though not everyone agrees). Please check them out in the Help file under "Topics", "MPASM Assembler", "Instruction Sets", and "14-bit Core" (second page). Some of my favorites are;

skpz (skip if zero)
skpnz (skip not zero)
skpc (skip if carry)
skpnc (skip not carry)
.....
bz (branch zero --> btfsc STATUS,Z plus goto xxxx)
bnz (branch not zero --> btfss STATUS,Z plus goto xxxx)
....

Have fun.

Regards, Mike
 
Status
Not open for further replies.

Latest threads

Back
Top