Jump to content
Sign in to follow this  
peter_pvk

If Then Else If Using 16f886 Or 16f917

Recommended Posts

Greetings,

 

I'm trying to compile the code given below for the 16F886 or 16F917. With the 4 lines commented out as shown, the build completes and functions as expected.

 

If I uncomment the 4 lines, I get a message of "xxx.bas(7): error: general error"

 

1. What is a "general error" ?

 

2. How can I fix it?

 

Thanks,

Peter

 

 

............................

 

#pragma CLOCK_FREQ 4000000

 

sub main()

 

dim i as byte

dim v(70) as byte

 

if v(2) = 80 and v(3) = 82 then

for i = 5 to 58

v(i) = (call usart_rx())

next

' else if v(2) = 80 and v(4) = 71 then

' for i = 59 to 68

' v(i) = (call usart_rx())

' next

end if

 

loop1:

goto loop1

 

end sub

 

function usart_rx() as byte

 

if ( (rcsta.OERR = 1) ) then

rcsta.CREN = 0

rcsta.CREN = 1

usart_rx = 0x00

else

do while (pir1.RCIF = 0)

_asm nop

loop

usart_rx = rcreg

end if

 

end function

Share this post


Link to post
Share on other sites

Peter_pvk.

1. What is a "general error" ?

When the compiler finds an error in the code and it has no further breakdown of what the error might be. As time goes in the development of the compiler the more errors, where possible, get improved error messages.

 

 

2. How can I fix it?

 

Remove the space between else and if, ie "else if" becomes "elseif".

See below:

#pragma CLOCK_FREQ 4000000

sub main()

dim i as byte 
dim v(70) as byte 

if v(2) = 80 and v(3) = 82 then 
	for i = 5 to 58 
		v(i) = (call usart_rx())
	next
elseif v(2) = 80 and v(4) = 71 then 
	for i = 59 to 68 
		v(i) = (call usart_rx())
	next
end if

loop1:
goto loop1

end sub

function usart_rx() as byte

if ( (rcsta.OERR = 1) ) then 
	rcsta.CREN = 0
	rcsta.CREN = 1
	usart_rx = 0x00
else
	do while (pir1.RCIF = 0)
	_asm nop
	loop
	usart_rx = rcreg
end if

end function

Regards

Dave

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×