PDA

View Full Version : VAR array compile issue



longpole001
- 29th March 2012, 09:58
Hi guys, thanks for help to date and ill try and return the favor as i learn more about the pic programming.

the following code will not compile when i use the variable T and loop , where if i expand the code out and assign a number in place of Varable T its very happy ,

It there away to do this without expanding out the code and not use fixed number in place of varable T

Regards

sheldon :friendly_wink:






'-------------- Low Address /High Address /Data / Inv Data bytes --------------
For T = 1 to 4
FOR Index = 7 TO 0 step -1 ' Loop for 8 bits data start at bit 7-0 and send
IF STDByte[T].0[Index] = 0 THEN ' Get polarity of each data bit to send
Space = Zero ' Pulse time = Burst (560us) + Zero (560us) = 1.12mS for a "0" data bit
ELSE
Space = One ' Pulse time = Burst (560us) + One (1680us) = 2.24mS for a "1" data bit
ENDIF

GPIO.0 = 0 ' Set Output low
pauseus Burst ' load the burst for 0.56ms
GPIO.0 = 1 ' Set Output high
pauseus space ' High for duration of either Zero or One value ,for each address/data b
Total[T] = Total[T] + space + burst ' store total time of string
NEXT Index ' Loop until 8 data-bits sent of DByte(X)
Next T

sayzer
- 29th March 2012, 10:31
Have a variable like


Temp VAR BYTE


Then swap the variables in your array.
Your new code will look like below.




'-------------- Low Address /High Address /Data / Inv Data bytes --------------
For T = 1 to 4

FOR Index = 7 TO 0 step -1 ' Loop for 8 bits data start at bit 7-0 and send

temp = STDByte[T]

IF temp.0[Index] = 0 THEN ' Get polarity of each data bit to send
Space = Zero ' Pulse time = Burst (560us) + Zero (560us) = 1.12mS for a "0" data bit
ELSE
Space = One ' Pulse time = Burst (560us) + One (1680us) = 2.24mS for a "1" data bit
ENDIF

STDByte[T] = temp

GPIO.0 = 0 ' Set Output low
pauseus Burst ' load the burst for 0.56ms
GPIO.0 = 1 ' Set Output high
pauseus space ' High for duration of either Zero or One value ,for each address/data b
Total[T] = Total[T] + space + burst ' store total time of string
NEXT Index ' Loop until 8 data-bits sent of DByte(X)

Next T

longpole001
- 29th March 2012, 13:42
thanks Sayzar , but i tried that before i posted , and just then , still get bad expression error and syntax error , using picbasic pro 5.0.0.0 , pbpx 3.0.4.1

is there something i am missing ??

Cheers

sheldon


temp = STDByte[T] - bad expression error
STDByte[T] = temp - syntax error

longpole001
- 29th March 2012, 13:47
i think i found the issue i forgot to define dbbyte var when i changed it over from dbyte1, cheers