Shop OBEX P1 Docs P2 Docs Learn Events
Byte array usage — Parallax Forums

Byte array usage

RsadeikaRsadeika Posts: 3,839
edited 2007-07-17 20:10 in General Discussion
I guess I need an explanation as to the correct way of using an array which will be called as a bank. I set up 'genuse var byte (6)' which contains temp3, when I try to compile, it complains with an error of "ERROR 5 byte parameter expected 'temp3' ". Now I am not sure what the error is trying to tell me. Anybody have any ideas as it pertains to the program below? It is in the get_sircs SUB.

Thanks

Ray

'===========================================================================
' CR1.SXB
'

·DEVICE SX52,OSCHS2
·FREQ 50_000_000
'''''''''
' IO Pins
'''''''''
rx1 pin re.0 input
tx1 pin re.1 output
IRpin pin re.7 input
LED1 pin re.6 output
'''''''''''
' Constants
'''''''''''
'''''''''''
' Variables
'''''''''''
'x var byte··· 'This used in the TX1_Byte SUB
············· 'could be general use·
temp1 var byte (4)·· 'This used in the TX1_Byte SUB,
···················· 'could be somewhere else?
temp1W var word
genuse var byte (6)
x var genuse(0)
temp2 var genuse(1)···
temp3 var genuse(2)
temp4 var genuse(3)
cmdCode var genuse(4)··· 'Used in the sircs routine
devCode var genuse(5)
'RAM 262 bytes for data (variables)
'Global variables 17 bytes
'Variables in arrays 223 bytes
'==========
' INTERRUPT
'==========

'============
PROGRAM Start
'============
'''''''''''''''''''''''''
' Subroutine Declarations
'''''''''''''''''''''''''
TX1_Byte sub 1,4
get_ir_pulse sub 0
get_sircs sub 0
processIR sub 0
tempDB sub 0
''''''''''''''
' Program Code
''''''''''''''
Start:
' This initializes the Create and puts it into Safe mode
·· TX1_Byte 128,131
'This will be the main loop
Main:
·· processIR
·· goto Main

'The end of the code section
end
''''''''''''''''''''''''''''''
' Subroutine and Function Code
''''''''''''''''''''''''''''''
processIR:
·· get_sircs
·· if cmdCode = 16 then tempDB·· 'Ch+
·· if cmdCode = 17 then tempDB·· 'Ch-
·· if cmdCode = 18 then tempDB·· 'Vol+
·· if cmdCode = 19 then tempDB·· 'Vol-
·· if cmdCode = 21 then tempDB·· 'Power
·· cmdCode = 0
return
tempDB:
·· high LED1
·· pause 2000
·· low LED1
return
' Use: TX1_Byte bytevalue or TX1_Byte bytevalue, bytevalue ...
'
TX1_Byte:
'Fills the array with PARAM values
·· temp1(0) = __PARAM1
·· temp1(1) = __PARAM2
·· temp1(2) = __PARAM3
·· temp1(3) = __PARAM4
·· temp2 = __PARAMCNT··· 'Get the PARAMCNT
·· do while temp2 > 0···· 'Is the PARAMCNT greater than 0···
···· serout tx1, T57600, temp1(x)
···· dec temp2······· 'Reduce the PARAMCNT value by 1
···· inc x··· 'Will it increment the array to the next element
·· loop
return
'''''''''''''''''
get_ir_pulse:
·· bank genuse·· '<<<<<<<<
·· pulsin IRpin, 0, temp4
return temp4

'========================
get_sircs:
·· bank genuse······· '<<<<<<<<
·· do
····· temp2 = get_ir_pulse
·· loop until temp2 > 216
·· cmdCode = 0
·· for temp3 = 0 to 6··············· '*****Compiler error******
····· cmdCode = cmdCode >> 1
····· temp2 = get_ir_pulse
····· if temp2 > 108 then
········ cmdCode.6 = 1
····· endif
·· next
·· devCode = 0
·· for temp3 = 0 to 4
····· devCode = devCode >> 1
····· temp2 = get_ir_pulse
····· if temp2 > 108 then
········ devCode.4 = 1
····· endif
·· next
·· bank 0
return

'''''''''''
' User Data
'''''''''''

Comments

  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-07-17 18:18
    I think the compiler is telling you that the index to a FOR... NEXT loop needs to be a standard, non-array declared byte variable.

    - Sparks
  • RsadeikaRsadeika Posts: 3,839
    edited 2007-07-17 18:40
    Yes, I just confirmed that, it needs to be a standard, non-array declared byte variable. Now, I have to keep that in mind as I use the other commands.

    Ray
  • JonnyMacJonnyMac Posts: 9,215
    edited 2007-07-17 20:10
    SX/B defaults to bank zero for simple variables and control structures that use variable should use globals (not arrays). You could of course rewrite the GET_SIRCS code in assembly; this would give you the power to use variables in BANKs 1 and higher. You're probably wondering why other commands seem to tolerate output to an array element; the reason is that, internally, SX/B uses globals (__PARAM1 - __PARAM4) and then transfers to your desired [noparse][[/noparse]array] variable.
Sign In or Register to comment.