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.

Probably a dumb If Then Question....

Status
Not open for further replies.

GreyHairOldGuy

New Member
PIC 18F4320
I have a flag (and a symbol)
Dim fpbc as Bit
Symbol scol = PORTD.7

I am trying to execute the following:
If scol = 1 Then fpbc = 0

scol is definately 1 but fpbc won't change from 1 to 0

When I run it through the Oshonsoft simulator it doesn't change either.

You're going to tell me I'm doing something stupid.
Please do so, but tell me where I am going wrong.

I am setting a flag and changing a count to exit from a While/Wend routine.
Perhaps that is my problem? I need to abort the count some times and didn't
think it was right for me to just jump over the Wend as I might mess up the stack?

Tks in advance - Mike
 
Last edited:
Hi Mike! Welcome to ETO!

Just wondering, do you have

if scol = 1

or

if scol == 1 ?

What compiler are you using? For conditional statements, they often require a double '=' sign for a test.

Good luck!
Der Strom

P.S. It may also be helpful if you could post your full code either here or on www.pastebin.com
 
Last edited:
Program now works - Got rid of High/Low's and replaced with 1's or 0's

DerStrom & Ian:

Tks for your reply

All my flags are defined as bits. Some bits are pic I/O bits defined by Symbols.

I went through my whole program - sometimes I would say high (or low) xxxxx and sometimes I would say xxxxx = 1 (or 0)
I changed all my High (or low) xxxxx's to xxxxx = 1 (or 0) and had no more problem of my program missing "If xxxxx = 1 (or 0) Then ......"
Question: Is High xxxxx any better than xxxxx = 1 or is it simply if I use High xxxxx, then I should also use "If xxxxx = High Then ....." not "If xxxxx = 1 Then ....."

Usually my IF statements check for one or zero, so I thought I should also make all my settings the same and it worked. Is there anything else I should know about this stuff?

The comment that I should use == made me think there is probably a difference between logic and numeric compares, although I don't claim to completely understand this process yet.

One other thing I don't understand and maybe I should post it as a different question but am I correct in thinking I cannot jump out of a (IE I have to let the instruction finish normally) If .. Then / else / endif or a while / wend loop? To exit I should either set a flag or change the count?

Can you recomend a simple book/writeup etc that gives a little more explanation/some examples on this stuff?

Tks in advance

Mike
 
The deal with '=' or '==', in C, at least, is that '=' sets a bit or variable, whereas a '==' tests a bit or variable. I'm not sure if it is the same in oshonsoft basic or not.
 
In Oshonsoft, Vladimir uses TRUE , FALSE for bit evaluation and HIGH , LOW to assert a BIT.. You can use these keywords on anything other than a bit variable.

Code:
If PORTB.4 = TRUE then PORTB.1 = HIGH
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top