PDA

View Full Version : Error: extra tokens on end of line



Jasonce65
- 21st January 2008, 16:28
After accidentally toggling the breakpoint feature or clicking something in Microcode studio, all of a sudden I get random error messages when compiling. Most of them are:

[201] ')' expected
[212] extra tokens on end of line
[300] too many errors

If I just start remming out lines, at some point, it will assemble properly. If I rem out one line and then un-rem another suspect line, it still complies OK. I've written other apps with IF...THENs this deep and had no problem. The code on most of the lines are identical except for the values.

This one really has me stumpped. About 6 months ago, I patched to MicroCode Studio 2.3.0.0 and the compiler is PICBASIC PRO 2.47. This is for 16F877A.

Is there a setting in MicroCode Studio that could have been changed that is causing this?

At one point I had this code working fine and then I added one IF-THEN to add a feature and then it wouldn't compile. I took the code out so it would be back to original and it still wouldn't compile.

I would appeciate any ideas as to what could cause this...

Here is the code...

CCP1CON = 0
CCP2CON = 0

adcon1 = 6

trise = 7
trisc = 191

porte = 0

trisa = 255
trisb = 0
trisd = 255

portEval var byte
portCval var byte
portCfinval var byte
stripBit var bit
portDval var byte
portAval var byte
IdNumber var byte
OutVal var byte

DEFIne HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
define HSER_SPBRG 25

BtVar var byte


portb = 0

START:

stripbit = portc.0 'this strips off the first 6 bits of port C
portcfinval.0 = stripbit 'to use as inputs, while ignoring the RX and TX pins.
stripbit = portc.1
portcfinval.1 = stripbit
stripbit = portc.2
portcfinval.2 = stripbit
stripbit = portc.3
portcfinval.3 = stripbit
stripbit = portc.4
portcfinval.4 = stripbit
stripbit = portc.5
portcfinval.5 = stripbit

if porta <> portaval then
portaval = porta
hserout [#porte,"A",#porta,13,10] 'the code that the PC recieves has the ID code,
endif 'the port letter and port value

if portd <> portdval then
portdval = portd
hserout [#porte,"D",#portd,13,10]
endif


if (portcfinval <> portcval) then
portcval = portcfinval
hserout [#porte, "C", #portcfinval, 13,10]
endif

hserin ,100,start,[Idnumber]

porteval = porte 'here is the code that I added
if idnumber = porteval then 'port E is the ID code or the chip
HSERIn ,500,START,[Btvar] ' the chip only responds to serial
else 'commands that match the ID code
goto start 'this lets more than one chip operate in parrallel on
'one serial port
endif '

if btvar = 48 then
HSERIn ,1000,START,[btvar]
if btvar = 48 then outval.bit0 = 0 'turn on/off bit on port b with serial command from
if btvar = 49 then outval.bit0 = 1 'PC
portb = outval
goto start
endif
if btvar = 49 then
HSERIn ,1000,START,[Btvar]
if btvar = 48 then outval.bit1 = 0
if btvar = 49 then outval.bit1 = 1
portb = outval
goto start
endif
if btvar = 50 then
HSERIn ,1000,START,[Btvar]
if btvar = 48 then Outval.bit2 = 0
if btvar = 49 then outval.bit2 = 1
portb = outval
goto start
endif
if btvar = 51 then
HSERIn ,1000,START,[Btvar]
if btvar = 48 then outval.bit3 = 0
if btvar = 49 then outval.bit3 = 1
portb = outval
goto start
endif
if btvar = 52 then
HSERIn ,1000,START,[Btvar]
if btvar = 48 then outval.bit4 = 0
if btvar = 49 then outval.bit4 = 1
portb = outval
goto start
endif

if btvar = 53 then
HSERIn ,1000,START,[Btvar]
if btvar = 48 then outval.bit5 = 0
if btvar = 49 then outval.bit5 = 1
portb = outval
goto start
endif

if btvar = 54 then
HSERIn ,1000,START,[Btvar]
if btvar = 48 then outval.bit6 = 0
if btvar = 49 then outval.bit6 = 1
portb = outval
goto start
endif
if btvar = 55 then
HSERIn ,1000,START,[Btvar]
if btvar = 48 then outval.bit7 = 0
if btvar = 49 then outval.bit7 = 1
portb = outval
goto start
endif


goto start

Jasonce65
- 21st January 2008, 16:42
I figured it out on my own, just moments after sending out the post, naturally... I went into View, Compile and Program Options, Assembler tab and turned on "Use PMASM". I then compiled the program which it did with ZERO errors. Then I switched it back, turning "Use PMASM" off. Then I compiled it again and it said: "Success 882 Words Used."

Whatever that was about, I'm glad it is now working.

UPDATE: I changed a couple lines of code and the errors returned. I switched back and forth between using PMASM and not and the problem went away again. Does anyone have any idea what could be causing this? When the problem doesn't show up, it compiles and I can flash the chip and it works properly. Is there any advantage to just leaving it on "Use PMASM"? Is this a proble with the particular version of MicroCode Studio I'm using?

scarroll01
- 22nd January 2008, 14:47
Hello Jason, I'm not too sure about the Microcode problem, (I use PBP 2.44/MPLAB IDE), but there are problems with the code. For instance, unless you've left out some code, the first thing that leaps out:-

if porta <> portaval then

You haven't initialised "portaval" with a value to compare to PORTA, so it will ALWAYS contain zero. If that is your intent, use:-

if PORTA>0 then

This is better practise. (You can't be sure that "portaval" will contain zero.)

Also, it's better to put your variable declarations and constant definitions at the beginning of the program, before any executable code. That would make it much easier to read.

I could go on, but I would suggest that you start with something a little simpler until you have more experience.

... Steve.

skimask
- 22nd January 2008, 14:49
Hello Jason, I'm not too sure about the Microcode problem, (I use PBP 2.44/MPLAB IDE), but there are problems with the code. For instance, unless you've left out some code, the first thing that leaps out:-
... Steve.

You know the upgrade to 2.50a is only $25, solves a lot of problems.

scarroll01
- 22nd January 2008, 15:11
I've never got around to upgrading. I guess I will eventually.
What problems? (Besides the lack of floating-point support?)

... Steve

skimask
- 22nd January 2008, 16:29
I've never got around to upgrading. I guess I will eventually.
What problems? (Besides the lack of floating-point support?)

... Steve

Little stuff that gets on your nerves.
Check melabs for the list.

Jasonce65
- 23rd January 2008, 16:16
portAval gets a value assigned to it once it goes through the loop, so I can tell if the state of the port changes. So the first time through the loop, yes, portAval = 0, which it should. Also, the first time through the loop, the program spits out serially, the values of the input ports. This is fine for my use.

All the program really does is sense the input pin changes and when a port changes value it spits out a serial string reflecting an ID code for the chip (from port e), a letter telling which port changed, and the value -easy.

port e will have a set of DIP switches attached to it that will tell me which chip out of 8 is sending the code.

I could have assigned it a value earlier in the code, but for all intensive purposes, it would not serve any functionality. In my app, the ports are going to read 0 about 99.9% of the time at power-up.

However, I'm still occasionally experiencing the quirk where it when it compiles it saya 'tokens on end of line', etc. If I put it on PMASM setting, this doesn't happen... oh well. Once I get it to compile, and put it on the chip the code works great.

I may try giving meLabs a call, although at this point it's really just an annoyance problem and I have a working product going out the door, it did cost me several hours of development time and few select words being spoken. I went through another situation where I had three of the same 16F877A's and they all ran differently, so I was reliving that nightmare too. :)

Thanks everyone!
J.-

skimask
- 23rd January 2008, 17:04
I see your code, and I raise you...ok, never mind...
Seems a bit goofy in my mind, but give this a shot:
(yes there is a bunch of colons here, only so I can see more of it on the screen)


DEFINE HSER_RCSTA 90h 'ALWAYS capitalize DEFINEs
DEFINE HSER_TXSTA 20h
DEFINE HSER_SPBRG 25
ccp1con = 0 : ccp2con = 0 : adcon1 = 6 : trise = 7 : trisc = 191
porte = 0 : trisa = 255 : trisb = 0 : trisd = 255 : portEval var byte
portCval var byte : portCfinval var byte : stripBit var bit
portDval var byte : portAval var byte : IdNumber var byte
OutVal var byte : btvar var byte : oldbtvar var byte : portb = 0
START:
portcfinval = portc & $3f
if porta <> portaval then
portaval = porta : hserout [#porte,"A",#porta,13,10]
endif
if portd <> portdval then
portdval = portd : hserout [#porte,"D",#portd,13,10]
endif
if (portcfinval <> portcval) then
portcval = portcfinval : hserout [#porte, "C", #portcfinval, 13,10]
endif
hserin ,100,start,[Idnumber] : porteval = porte
if idnumber <> porteval then start
HSERIn ,500,START,[Btvar]
if ( btvar => 48 ) and ( btvar <= 55 ) then
oldbtvar = btvar - 48 : HSERIn, 1000 , START , [btvar]
if btvar <= 49 then outval.0[ oldbtvar ] = btvar.0
portb = outval : goto start
endif
goto start