PDA

View Full Version : need help



pierre2030
- 26th March 2006, 07:04
-hi,i'm a newbie to PICbasic...
-the following is my code for my project. i wonder why i receive error warning every time i compiler it.
-this is the error warning 'ERROR:ELSE without a matching ENDIF'

-this is my code

'DECODE1

DEFINE HSER_RCSTA 90H
DEFINE HSER_TXSTA 24H
DEFINE HSER_BAUD 9600
DEFINE HSER_SPBRG 25
DEFINE HSER_CLROERR 1

MANCHESTERWORD VAR WORD
MYDATA VAR BIT
FLAG VAR BIT

TRISA=255
TRISC=0

'................................................. ..........................................

MAIN:


MYDATA=0
FLAG=0

TEST:
IF PORTA.0=1 Then
TESTING
Else
TEST



TESTING:
IF PORTA.0=0 Then
CHECKING
Else
TESTING

EndIF

CHECKING:
IF PORTA.4=0 Then
GoSub RX1
Else
GoSub RX0

EndIF


IF FLAG=1 Then
PORTC.0=1
EndIF

HSerout [MYDATA]

GoTo MAIN


RX1:

EDGE0:IF PORTA.0=0 Then EDGE0

DLY0:IF PORTA.0=0 Then DLY0

IF PORTA.4=1 Then
MYDATA=1

Else
FLAG=1
EndIF

Return



RX0:

EDGE1:IF PORTA.0=0 Then EDGE1

DLY1:IF PORTA.0=1 Then DLY1

IF PORTA.4=0 Then
MYDATA=0
Else
FLAG=1
EndIF


Return





-thank u

paul borgmeier
- 26th March 2006, 07:36
Pierre,

Welcome -

Read the manual for IF-THEN and then try what is below for your first IF-THEN statement.

IF PORTA.0=1 Then
goto TESTING
Else
goto TEST
Endif

You will need to update (fix) some of your other IF-THEN statements as well.

Good Luck,

Paul Borgmeier
Salt Lake City, Utah
USA

pierre2030
- 26th March 2006, 09:44
HI,paul borgmeier

-i finish reading the manual and found out that IF---THEN can operate in 2 manners.
-In one form,the THEN in an IF...THEN is essentially a GOTO. If the condition is true,the program will GOTO the label after the THEN.
-In the second form, IF...THEN can conditionally execute a group of statements following the THEN. The statements must be followed by an ELSE OR ENDIF to complete the structure.

-the message got worse when i add ENDIF in the first IF---THEN

TEST:
IF PORTA.0=1 Then
goto TESTING
Else
goto TEST
Endif

and become:

Error C:\CDLITE\THESIS\DECODE1.ASM 67:[231] Attempt to Redefine '_TEST'
Error C:\CDLITE\THESIS\DECODE1.ASM 70:[231] Attempt to Redefine '_TESTING'
Error C:\CDLITE\THESIS\DECODE1.ASM 77:[231] Attempt to Redefine '_TESTING'
Error C:\CDLITE\THESIS\DECODE1.ASM 80:[231] Attempt to Redefine '_CHECKING'

*** 4 Errors***

-what is meaning of those errors?
thank u very much

paul borgmeier
- 26th March 2006, 15:28
Look at the first If-Then you just fixed. How does it differ from your next If-Then? In the first, we added the goto statement to both conditions. Do the same for the second If-then and then your code will compile without errors.

TESTING:
IF PORTA.0=0 Then
goto CHECKING
Else
goto TESTING
EndIF

Good Luck,

Paul Borgmeier
Salt Lake City, Utah
USA

paul borgmeier
- 26th March 2006, 18:28
For clarification as to why your original format did not compile.

snip ... "If the condition is true,the program will GOTO the label after the THEN"

The LABEL needs to be on the same line as the THEN in order for it to be assumed a GOTO. If used in this manner it cannot have an ELSE associated with it.

EXAMPLES:


IF PORTA.0 = 1 THEN TESTING

and

If PORTA.0 = 1 THEN
GOTO TESTING
ENDIF

do the same thing (but the second form takes more program words)

Paul