Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

why doesn't this work?

Status
Not open for further replies.

stevecrozz

New Member
Code:
CLEAR
TRISB = %00000000
TRISA = %00000000
	time 		var 	word
	counter 	var 	byte
	count2 		var 	byte

INLOOP:
	FOR counter = 0 TO 7
		Pause 10000
	NEXT counter
	Pause 4375
	time = time + 1
	FOR count2 = 0 TO 9 
		IF time.count2 = 1 THEN HIGH count2
		ELSE
			LOW count2
		ENDIF
	NEXT count2

GOTO INLOOP

End
I get these errors:
ERROR Line 15: Bad variable modifier: .count2.
ERROR: ELSE: Mismatched block nesting.
ERROR: ENDIF: Mismatched block nesting.
BUILD FAILED: Thu Oct 23 11:23:21 2003
I'm just learning so any help would be greatly appreciated[/code]
 

Exo

Active Member
time.count2 doesn't work because the instruction
Variable.bit
requires a constant for 'bit'
 

Eclipsed

New Member
Also I don't believe HIGH or LOW commands will work on an entire byte(count2) only on individual bits.
 

ivancho

New Member
A couple of Ideas here.
I believe that modifiers can only be used with a byte variable.

Counter VAR BYTE all the bits can be address as: Counter.0, Counter.1, Counter.2, Counter.3......Counter.7

If you were to define Timer VAR WORD then you might have to declare BYTE variables that are inside that word. For example:
Code:
Timer Var WORD
Counter VAR Timer.Byte0
Count2 VAR Timer.Byte1
Now Counter and Count2 are the Low and High byte of the Timer variable respectively.
Now you can address the variables bit as Counter.0, Counter.1...etc

All these according to the manual.... I have never really had a chance to use something like this.

You also have one error on yout IF ...THEN statement. By putting the whole thing in one line PBP thinks that is not going to have an ELSE and therefore will not need a ENDIF. Also the HIGH and LOW statements are to make a PIN HIGH or LOW, not to make a variable 1 or 0.To fix all that do something like:
Code:
      IF time.count2 = 1 THEN 
          Count2 = 1 
      ELSE 
          Count2 = 0
      ENDIF

Also remember that you Timer variable will overflow after 65535.

Good Luck

Ivancho
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top