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.

Problem with IF, THEN, ELSE and END IF?

Status
Not open for further replies.

Izadysadr

New Member
define osc 4
Digit1 var byte
Digit2 var byte
TrisD = %11110000
TrisA = %01111111

Main:
if PortA.0 = 1 then Count1
else
count2
endif
goto main
END


Count2:
If digit1 > 10 then Deduct
PortD = digit2
Pause 250

Count1:
If Digit1 > 10 then ADd
PortD = Digit1
pause 250

Add:
Digit1 = Digit1 + 1
goto Count1

Is my code, I don't know why whenever i wanna compile it, it says "ELSE without a matching IF .... THEN"
what's wrong with my code?
I use pbp ver2.4
Thanks in advance
 
If you do if PortA.0 = 1 then Count1 then that is a completed if statement. You need to seperate it to make it work,
Code:
Main:
    if PortA.0 = 1 then 
        Count1
    else 
        count2
    endif 
    goto main 
END

You also need to remove the END statement or move it to the last line of your file as the compiler will stop compiling at the END statement.

Mike.
 
Last edited:
Define osc 4
Digit1 var byte
Digit2 var byte
TrisD = %11110000
TrisA = %11111110


Main:
if PortA.0 = 1 then
Count1
else
Count2
endif

goto main


Count2:
If digit1 > 10 then
Deduct
PortD = digit1
Pause 250
Endif

Count1:
If Digit1 > 10 then
Add
PortD = Digit1
pause 250
endif

Add:
Digit1 = Digit1 + 1
Goto Count1


Deduct:
Digit1 = Digit1 - 1
goto Count2

end

Thanks alot Mike, I changed my code to what u see above, my problem now is that it doesn't read my button and it always counts up. I'd really appreciate it if you could take another look. I really don't know what the problem is and have tried many things. thanks again.
 
If the "if" expression evaluates to "true" then you call/goto the specified label (not really sure the language you are using). However the code after the label has a "goto" to another label just BEFORE the original "if" statement. This means that you will never get to the code after the first line of the "true" branch.

Simply stepping through the code and pretending you are a computer would show this straight away.

Susan
 
what is code suppose to do? Is this just a up/down counter? How many buttons are there?
 
Status
Not open for further replies.

Latest threads

Back
Top