Error


Closed Thread
Results 1 to 7 of 7

Thread: Error

  1. #1
    tekdavid's Avatar
    tekdavid Guest

    Question Error

    i am using picbasic and this should work but it dont can any one tell me were my error is in program fornext

    error fornext.bas,12: ':' or '=" expected (token 'var')
    error fornext.bas,13: variable expected (token 'i')
    error fornext.bas,17: next without maching for




    12: i VAR byte
    13: for i = 1 to 4
    14: high 0
    15: pause 1000
    16: low 0
    17: next i

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    The clue is the common denominator for lines 12, 13 and 17... it doesn't like your variable.

    I don't have PICBasic, only PICBasic Pro, however, whilst your code would be valid in PBP, in PBC I believe the variables are predefined... you must use them, although (and I stand to be corrected) you might be able to alias them... try this as a starter...

    for B0 = 1 to 4
    high 0
    pause 1000
    low 0
    next B0

    Consult the PBC manual for variables.

  3. #3
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189


    Did you find this post helpful? Yes | No

    Default

    You do have to use the pre-assigned variables as mentioned here or use this at the beginning:

    i symbol B0

    to assign your own name to the variable.

    Bart

  4. #4
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello tekdavid,

    TD>>12: i VAR byte
    13: for i = 1 to 4
    14: high 0
    15: pause 1000
    16: low 0
    17: next i<<

    I also question lines 14 and 16...

    Usually it is a High Porta.0 or Low Porta.0 or
    it may be High Portb.0 or Low portb.0

    Either way, It might be good to assign a port to it.

    Another problem... What do your lines BEFORE line 12 look like?
    Sometimes the compiler may flag line 12, but the problem is actually
    in line 10 or 11....

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    I think it's the illegal (undeclared) variable 'i' in this case Dwayne...

    High 0 and Low 0 are valid for addressing pin 0 of your PIC (note that which physical pin that pin 0 refers to is dependant of the PIC family - refer to the PICBasic manual for that).

  6. #6
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Melanie,

    Melanie>>High 0 and Low 0 are valid for addressing pin 0 of your PIC (note that which physical pin that pin 0 refers to is dependant of the PIC family - refer to the PICBasic manual for that).<<

    Gotcha...I wasn't sure which pic they were using...

    I always seem to get myself into trouble if I don't spell it out <smile>.. Thus I kinda do things the "long Hand" way...GPIO.0, Porta.0, or whatever. Its kinda like those headers at the beginning of your file, If it is already defined for your chip, it can save *ME* a lot of time trying to figure out why my compiler is burping at me.
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Thus I kinda do things the "long Hand" way...GPIO.0, Porta.0, or whatever.
    You really must try to avoid coding GPIO.0 or PortA.0 (or similar) in your programs... I'll tell you why... you have fifteen instances in a thousand lines of code where you refer to a particular pin... Firstly - just get ONE of those instances wrong and your code is screwed... but you'll never know it until that particular piece of code is executed. Secondly - you're laying out your PCB and you discover it's easier to place your components and lay your tracks if you swapped pins PortA.5 with PortB.6. You now spend half a day trying to find all the references to those pins in your program and worry about swapping them over.

    There is a better way...

    At the start of your program, right after you've done all your Config Fuse Defines, you have a section where each and every pin on your PIC is defined (aliased), and you ONLY use those aliases in your program... example - a snip out of a program that uses a PIC16F876...

    Code:
    	'
    	'	Hardware Defines
    	'	================
    		'
    		' 	LCD Display
    		'	-----------
    	Define LCD_DREG PORTC	' Port for LCD Data
    	Define LCD_DBIT 4	' Use upper 4 bits of Port
    	Define LCD_RSREG PORTC	' Port for RegisterSelect (RS) bit
    	Define LCD_RSBIT 3	' Port Pin for RS bit
    	Define LCD_EREG PORTC	' Port for Enable (E) bit
    	Define LCD_EBIT 0	' Port Pin for E bit
    	Define LCB_BITS 4	' Using 4-bit bus
    	Define LCD_LINES 2	' Using 2 line Display
    	Define LCD_COMMANDUS 2000
    				' Command Delay (uS)
    	Define LCD_DATAUS 50	' Data Delay (uS)
    	LCDBackLight var PORTC.1
    				' LCD Backlight PWM Pin
    	LCDContrast var PORTC.2	' LCD Contrast PWM Pin
    		'
    		'	Sensor Inputs
    		'	-------------
    	PressIN var PortA.0	' Pressure Transducer Input
    		'
    		'	Button (Internet) Inputs
    		'	------------------------
    	ButtonDown var PortB.0	' SW2/Button DN
    	ButtonUp var PortB.1	' SW1/Button UP
    	ButtonSet var PortB.2	' SW3/Button SET/RST
    	ButtonReserve var PortB.7
    				' SW4/Exclusive CPU Access Button
    		'
    		'	System Outputs
    		'	--------------
    	GreenLED var PortA.1	' Green LED
    	RedLED var PortA.2	' Red LED
    	Beeper var PortA.3 	' Piezo Sounder
    		'
    		'	Communications I2C Bus
    		'	----------------------
    	SCL var PortA.4		' I2CLock
    	SDA var PortA.5		' I2CData
    		'
    		'	Communications Inter-Processor (IP) Bus
    		'	---------------------------------------
    	IPAEnable var PortB.3	' IPENABLEA
    	IPBEnable var PortB.6	' IPENABLEB
    	IPClock var PortB.4	' IPCLOCK
    	IPData var PortB.5	' IPDATA
    Now, if I have to amend my program, and turn my Red LED on, rather than try to remember what pin my Red LED is connected to, I simply say...

    High RedLED

    and if I'm laying out my PCB and need to shuffle the pins about for convenience, there's just one section I need to look in to make changes globally in my program.

    And better still, if I need to port my program to a different PIC, again, just one section reassigns all the pins.

    Get in the habit of doing it this way - it will save you countless HOURS in the long term.

Similar Threads

  1. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  2. Optimizing DIV
    By skimask in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 22nd September 2008, 04:58
  3. pbp245 compliation error
    By Woodzy in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 25th July 2006, 05:59
  4. 16F88 Compile error
    By Toley00 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 2nd November 2005, 00:22
  5. Compiler/Assembler Error
    By LT_Pic in forum General
    Replies: 7
    Last Post: - 21st July 2005, 09:47

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts