Jump to content


Photo

If Then Else If Using 16f886 Or 16f917


2 replies to this topic

#1 peter_pvk

peter_pvk

    Newbrie

  • Members
  • 2 posts

Posted 12 December 2009 - 08:54 PM

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

#2 Dave

Dave

    Super Maniac

  • Administrators
  • PipPipPipPipPip
  • 2,091 posts
  • Gender:Male
  • Location:UK
  • Interests:How things work, Electronics, Software, Cycling.

Posted 12 December 2009 - 09:20 PM

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

#3 peter_pvk

peter_pvk

    Newbrie

  • Members
  • 2 posts

Posted 12 December 2009 - 10:18 PM

I knew it was going to be simple... and sure enough...

I'm going to learn to read Real Soon Now.

Thanks,
Peter



Reply to this topic



  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users