strange word varable array results
Hi Guys
i been looking at this for a while and i cant see why i am getting the results i am
put simply i have an array of 6 words , which are cleared at the start
i copy a byte into lowbyte of word0 and a byte into highbyte of word0
the word0 result is as expect , and shows correctly on the terminal (84dec)
the word0 is also shown as high and low byte , which is also correct
to test the other word varables i copy the word0 to , word1,2,3,4,5
i then display the word 0-5 on the terminal as well as the high and low bytes of each word
problem i am seeing is that
word1 ,word3, word5 have the correct word value ,
however when showing the the high and lowbytes of that same word , in the same line the high byte and low byte is reversed
got me stumped
this is debug code as i have been seeing this same error on both the terminal and a graphics display
any advise
cheers
sheldon
[CODE]
if RXpayload_Code = 3 then ' RXpayload Code 3 variables for indexing
Gate_Firm_Rev[z] = 0 ' clear selected varable
Gate_Hard_Rev[z] = 0
Gate_Firm_Rev.lowbyte [z] = RX_payload[1] ' Indexed Gate Firmware revison lowbyte
Gate_Firm_Rev.highbyte[z] = RX_payload[2] ' Indexed Gate Firmware revison highbyte
Gate_Hard_Rev.lowbyte[z] = RX_payload[3] ' indexed gate hardware revision lowbyte
Gate_Hard_Rev.highbyte[z] = RX_payload[4] ' indexed gate hardware revision highbyte
HSEROUT ["z = ",dec z , " GateID_word[z] = ",dec GateID_word[z] ," Gate_Firm_Rev[z] = ",DEC Gate_Firm_Rev[z],13,10,10,10] 'debug
Gate_Firm_Rev[1] = Gate_Firm_Rev[0]
Gate_Firm_Rev[2] = Gate_Firm_Rev[0]
Gate_Firm_Rev[3] = Gate_Firm_Rev[0]
Gate_Firm_Rev[4] = Gate_Firm_Rev[0]
Gate_Firm_Rev[5] = Gate_Firm_Rev[0]
HSEROUT [" 0. GateID_word[0] = ",dec GateID_word[0] ," Gate_Firm_Rev[0] = ",DEC Gate_Firm_Rev[0]," Gate_Firm_Rev.highbyte[0] = ",DEC Gate_Firm_Rev.highbyte[0] ," Gate_Firm_Rev.lowbyte{0} = ",DEC Gate_Firm_Rev.lowbyte[0] ,13,10,10,10 ] 'debug
HSEROUT [" 1. GateID_word[1] = ",dec GateID_word[1] ," Gate_Firm_Rev[1] = ",DEC Gate_Firm_Rev[1]," Gate_Firm_Rev.highbyte[1] = ",DEC Gate_Firm_Rev.highbyte[1] ," Gate_Firm_Rev.lowbyte{1} = ",DEC Gate_Firm_Rev.lowbyte[1] ,13,10,10,10 ] 'debug
HSEROUT [" 2. GateID_word[2] = ",dec GateID_word[2] ," Gate_Firm_Rev[2] = ",DEC Gate_Firm_Rev[2]," Gate_Firm_Rev.highbyte[2] = ",DEC Gate_Firm_Rev.highbyte[2] ," Gate_Firm_Rev.lowbyte{2} = ",DEC Gate_Firm_Rev.lowbyte[2] ,13,10,10,10 ] 'debug
HSEROUT [" 3. GateID_word[3] = ",dec GateID_word[3] ," Gate_Firm_Rev[3] = ",DEC Gate_Firm_Rev[3]," Gate_Firm_Rev.highbyte[3] = ",DEC Gate_Firm_Rev.highbyte[3] ," Gate_Firm_Rev.lowbyte{3} = ",DEC Gate_Firm_Rev.lowbyte[3] ,13,10,10,10 ] 'debug
HSEROUT [" 4. GateID_word[4] = ",dec GateID_word[4] ," Gate_Firm_Rev[4] = ",DEC Gate_Firm_Rev[4]," Gate_Firm_Rev.highbyte[4] = ",DEC Gate_Firm_Rev.highbyte[4] ," Gate_Firm_Rev.lowbyte{4} = ",DEC Gate_Firm_Rev.lowbyte[4] ,13,10,10,10 ] 'debug
HSEROUT [" 5. GateID_word[5] = ",dec GateID_word[5] ," Gate_Firm_Rev[5] = ",DEC Gate_Firm_Rev[5]," Gate_Firm_Rev.highbyte[5] = ",DEC Gate_Firm_Rev.highbyte[5] ," Gate_Firm_Rev.lowbyte{5} = ",DEC Gate_Firm_Rev.lowbyte[5] ,13,10,10,10 ] 'debug
endif
/CODE]
Code:
z = 0 GateID_word[z] = 10 Gate_Firm_Rev[z] = 84
0. GateID_word[0] = 10 Gate_Firm_Rev[0] = 84 Gate_Firm_Rev.highbyte[0] = 0 Gate_Firm_Rev.lowbyte{0} = 84
1. GateID_word[1] = 0 Gate_Firm_Rev[1] = 84 Gate_Firm_Rev.highbyte[1] = 84 Gate_Firm_Rev.lowbyte{1} = 0
2. GateID_word[2] = 0 Gate_Firm_Rev[2] = 84 Gate_Firm_Rev.highbyte[2] = 0 Gate_Firm_Rev.lowbyte{2} = 84
3. GateID_word[3] = 0 Gate_Firm_Rev[3] = 84 Gate_Firm_Rev.highbyte[3] = 84 Gate_Firm_Rev.lowbyte{3} = 0
4. GateID_word[4] = 0 Gate_Firm_Rev[4] = 84 Gate_Firm_Rev.highbyte[4] = 0 Gate_Firm_Rev.lowbyte{4} = 84
5. GateID_word[5] = 0 Gate_Firm_Rev[5] = 84 Gate_Firm_Rev.highbyte[5] = 84 Gate_Firm_Rev.lowbyte{5} = 0
Re: strange word varable array results
never struck that before looks like var[].highbyte and var[].lowbyte upsets things
;pic18f45k20
Code:
#CONFIG
CONFIG FOSC = INTIO67
CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG PWRT = OFF
CONFIG BOREN = SBORDIS
CONFIG BORV = 18
CONFIG WDTEN = ON
CONFIG WDTPS = 512
CONFIG CCP2MX = PORTC
CONFIG PBADEN = OFF
CONFIG LPT1OSC = OFF
CONFIG HFOFST = ON
CONFIG MCLRE = ON
CONFIG STVREN = ON
CONFIG LVP = OFF
CONFIG XINST = OFF
CONFIG DEBUG = OFF
CONFIG CP0 = OFF
CONFIG CP1 = OFF
CONFIG CP2 = OFF
CONFIG CP3 = OFF
CONFIG CPB = OFF
CONFIG CPD = OFF
CONFIG WRT0 = OFF
CONFIG WRT1 = OFF
CONFIG WRT2 = OFF
CONFIG WRT3 = OFF
CONFIG WRTC = OFF
CONFIG WRTB = OFF
CONFIG WRTD = OFF
CONFIG EBTR0 = OFF
CONFIG EBTR1 = OFF
CONFIG EBTR2 = OFF
CONFIG EBTR3 = OFF
CONFIG EBTRB = OFF
#ENDCONFIG
define OSC 64
osccon=$70 '64 mhz
OSCTUNE.6=1
pause 2000
Serout2 PORTb.7,84,["ready",13,10]
Gate_Firm_Rev var word[6]
Gate_Hard_Rev var word[6]
GateID_word var word[6]
z var byte
x var word
RX_payload var byte[4]
RX_payload[1] =84
RX_payload[2] =0
RX_payload[3] =0
RX_payload[4] =0
GateID_word[0] =10
z=0
Gate_Firm_Rev[z] = 0 ' clear selected varable
Gate_Hard_Rev[z] = 0
Gate_Firm_Rev.lowbyte [z] = RX_payload[1] ' Indexed Gate Firmware revison lowbyte
Gate_Firm_Rev.highbyte[z] = RX_payload[2] ' Indexed Gate Firmware revison highbyte
Gate_Hard_Rev.lowbyte[z] = RX_payload[3] ' indexed gate hardware revision lowbyte
Gate_Hard_Rev.highbyte[z] = RX_payload[4] ' indexed gate hardware revision highbyte
Serout2 PORTb.7,84, ["z = ",dec z , " GateID_word[z] = ",dec GateID_word[z] ," Gate_Firm_Rev[z] = ",DEC Gate_Firm_Rev[z],13,10,10,10] 'debug
x= Gate_Firm_Rev[0]
Gate_Firm_Rev[1] = x
Gate_Firm_Rev[2] = x
Gate_Firm_Rev[3] = x
Gate_Firm_Rev[4] = x
Gate_Firm_Rev[5] = x
Serout2 PORTb.7,84, [" 0. GateID_word[0] = ",dec GateID_word[0] ," Gate_Firm_Rev[0] = ",DEC Gate_Firm_Rev[0]," Gate_Firm_Rev.highbyte[0] = ",DEC Gate_Firm_Rev.highbyte[0] ," Gate_Firm_Rev.lowbyte{0} = ",DEC Gate_Firm_Rev.lowbyte[0] ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" 1. GateID_word[1] = ",dec GateID_word[1] ," Gate_Firm_Rev[1] = ",DEC Gate_Firm_Rev[1]," Gate_Firm_Rev.highbyte[1] = ",DEC Gate_Firm_Rev.highbyte[1] ," Gate_Firm_Rev.lowbyte{1} = ",DEC Gate_Firm_Rev.lowbyte[1] ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" 2. GateID_word[2] = ",dec GateID_word[2] ," Gate_Firm_Rev[2] = ",DEC Gate_Firm_Rev[2]," Gate_Firm_Rev.highbyte[2] = ",DEC Gate_Firm_Rev.highbyte[2] ," Gate_Firm_Rev.lowbyte{2} = ",DEC Gate_Firm_Rev.lowbyte[2] ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" 3. GateID_word[3] = ",dec GateID_word[3] ," Gate_Firm_Rev[3] = ",DEC Gate_Firm_Rev[3]," Gate_Firm_Rev.highbyte[3] = ",DEC Gate_Firm_Rev.highbyte[3] ," Gate_Firm_Rev.lowbyte{3} = ",DEC Gate_Firm_Rev.lowbyte[3] ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" 4. GateID_word[4] = ",dec GateID_word[4] ," Gate_Firm_Rev[4] = ",DEC Gate_Firm_Rev[4]," Gate_Firm_Rev.highbyte[4] = ",DEC Gate_Firm_Rev.highbyte[4] ," Gate_Firm_Rev.lowbyte{4} = ",DEC Gate_Firm_Rev.lowbyte[4] ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" 5. GateID_word[5] = ",dec GateID_word[5] ," Gate_Firm_Rev[5] = ",DEC Gate_Firm_Rev[5]," Gate_Firm_Rev.highbyte[5] = ",DEC Gate_Firm_Rev.highbyte[5] ," Gate_Firm_Rev.lowbyte{5} = ",DEC Gate_Firm_Rev.lowbyte[5] ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" Gate_Firm_Rev.highbyte[5] = ",DEC Gate_Firm_Rev[0]/256 ," Gate_Firm_Rev.lowbyte{5} = ",DEC Gate_Firm_Rev[0]//256 ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" Gate_Firm_Rev.highbyte[5] = ",DEC Gate_Firm_Rev[1]/256 ," Gate_Firm_Rev.lowbyte{5} = ",DEC Gate_Firm_Rev[1]//256 ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" Gate_Firm_Rev.highbyte[5] = ",DEC Gate_Firm_Rev[2]/256 ," Gate_Firm_Rev.lowbyte{5} = ",DEC Gate_Firm_Rev[2]//256 ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" Gate_Firm_Rev.highbyte[5] = ",DEC Gate_Firm_Rev[3]/256 ," Gate_Firm_Rev.lowbyte{5} = ",DEC Gate_Firm_Rev[3]//256 ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" Gate_Firm_Rev.highbyte[5] = ",DEC Gate_Firm_Rev[4]/256 ," Gate_Firm_Rev.lowbyte{5} = ",DEC Gate_Firm_Rev[4]//256 ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" Gate_Firm_Rev.highbyte[5] = ",DEC Gate_Firm_Rev[5]/256 ," Gate_Firm_Rev.lowbyte{5} = ",DEC Gate_Firm_Rev[5]//256 ,13,10,10,10 ] 'debug
result
Quote:
ready
z = 0 GateID_word[z] = 10 Gate_Firm_Rev[z] = 84
0. GateID_word[0] = 10 Gate_Firm_Rev[0] = 84 Gate_Firm_Rev.highbyte[0] = 0 Gate_Firm_Rev.lowbyte{0} = 84
1. GateID_word[1] = 0 Gate_Firm_Rev[1] = 84 Gate_Firm_Rev.highbyte[1] = 84 Gate_Firm_Rev.lowbyte{1} = 0
2. GateID_word[2] = 16367 Gate_Firm_Rev[2] = 84 Gate_Firm_Rev.highbyte[2] = 0 Gate_Firm_Rev.lowbyte{2} = 84
3. GateID_word[3] = 0 Gate_Firm_Rev[3] = 84 Gate_Firm_Rev.highbyte[3] = 84 Gate_Firm_Rev.lowbyte{3} = 0
4. GateID_word[4] = 63744 Gate_Firm_Rev[4] = 84 Gate_Firm_Rev.highbyte[4] = 0 Gate_Firm_Rev.lowbyte{4} = 84
5. GateID_word[5] = 49026 Gate_Firm_Rev[5] = 84 Gate_Firm_Rev.highbyte[5] = 84 Gate_Firm_Rev.lowbyte{5} = 0
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 84
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 84
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 84
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 84
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 84
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 84
Re: strange word varable array results
using this bit
x= Gate_Firm_Rev[0]
Gate_Firm_Rev[1] = x +1
Gate_Firm_Rev[2] = x +2
Gate_Firm_Rev[3] = x +3
Gate_Firm_Rev[4] = x +4
Gate_Firm_Rev[5] = x +5
changes the output more disturbingly to this
z = 0 GateID_word[z] = 10 Gate_Firm_Rev[z] = 84
0. GateID_word[0] = 10 Gate_Firm_Rev[0] = 84 Gate_Firm_Rev.highbyte[0] = 0 Gate_Firm_Rev.lowbyte{0} = 84
1. GateID_word[1] = 8479 Gate_Firm_Rev[1] = 85 Gate_Firm_Rev.highbyte[1] = 85 Gate_Firm_Rev.lowbyte{1} = 0
2. GateID_word[2] = 16367 Gate_Firm_Rev[2] = 86 Gate_Firm_Rev.highbyte[2] = 0 Gate_Firm_Rev.lowbyte{2} = 85
3. GateID_word[3] = 65281 Gate_Firm_Rev[3] = 87 Gate_Firm_Rev.highbyte[3] = 86 Gate_Firm_Rev.lowbyte{3} = 0
4. GateID_word[4] = 63744 Gate_Firm_Rev[4] = 88 Gate_Firm_Rev.highbyte[4] = 0 Gate_Firm_Rev.lowbyte{4} = 86
5. GateID_word[5] = 32640 Gate_Firm_Rev[5] = 89 Gate_Firm_Rev.highbyte[5] = 87 Gate_Firm_Rev.lowbyte{5} = 0
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 84
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 85
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 86
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 87
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 88
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 89
the indexing is corrupted
Re: strange word varable array results
its the first i seen of this problem , and i have alot of indexed bytes but this is the first of indexed words where i have noticed it when doing bad things highbyte and lowbyte are reveresed and only on words of 1,3,5, they are fine for word 0,2,4,
Re: strange word varable array results
same result when using byte1, byte0 in place of highbyte and lowbyte on indexed words
Re: strange word varable array results
its not corruption its just an unexpected way of array referencing the bytes are not!!! reversed at all look more closely at post #3
it appears that single byte extraction of word arrays causes the array indexing to become as byte sized therefore
to extract a byte from a word array element using .highbyte/.lowbyte (.byte0/.byte1) you need to multiply the element index x 2
i think its best avoided but it does work
eg
var[0] = var[0].byte0/var[0].byte1
var[1] = var[2].byte0/var[2].byte1
var[2] = var[4].byte0/var[4].byte1
x= Gate_Firm_Rev[0]
Gate_Firm_Rev[1] = x +1
Gate_Firm_Rev[2] = x +2
Gate_Firm_Rev[3] = x +3
Gate_Firm_Rev[4] = x +4
Gate_Firm_Rev[5] = x +5
Serout2 PORTb.7,84, [" 0. GateID_word[0] = ",dec GateID_word[0] ," Gate_Firm_Rev[0] = ",DEC Gate_Firm_Rev[0]," Gate_Firm_Rev.highbyte[0] = ",DEC Gate_Firm_Rev.BYTE1[0] ," Gate_Firm_Rev.lowbyte{0} = ",DEC Gate_Firm_Rev.BYTE0[0] ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" 1. GateID_word[1] = ",dec GateID_word[1] ," Gate_Firm_Rev[1] = ",DEC Gate_Firm_Rev[1]," Gate_Firm_Rev.highbyte[1] = ",DEC Gate_Firm_Rev.BYTE1[2] ," Gate_Firm_Rev.lowbyte{1} = ",DEC Gate_Firm_Rev.BYTE0[2] ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" 2. GateID_word[2] = ",dec GateID_word[2] ," Gate_Firm_Rev[2] = ",DEC Gate_Firm_Rev[2]," Gate_Firm_Rev.highbyte[2] = ",DEC Gate_Firm_Rev.BYTE1[4] ," Gate_Firm_Rev.lowbyte{2} = ",DEC Gate_Firm_Rev.BYTE0[4] ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" 3. GateID_word[3] = ",dec GateID_word[3] ," Gate_Firm_Rev[3] = ",DEC Gate_Firm_Rev[3]," Gate_Firm_Rev.highbyte[3] = ",DEC Gate_Firm_Rev.BYTE1[6] ," Gate_Firm_Rev.lowbyte{3} = ",DEC Gate_Firm_Rev.BYTE0[6] ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" 4. GateID_word[4] = ",dec GateID_word[4] ," Gate_Firm_Rev[4] = ",DEC Gate_Firm_Rev[4]," Gate_Firm_Rev.highbyte[4] = ",DEC Gate_Firm_Rev.BYTE1[8] ," Gate_Firm_Rev.lowbyte{4} = ",DEC Gate_Firm_Rev.BYTE0[8] ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" 5. GateID_word[5] = ",dec GateID_word[5] ," Gate_Firm_Rev[5] = ",DEC Gate_Firm_Rev[5]," Gate_Firm_Rev.highbyte[5] = ",DEC Gate_Firm_Rev.BYTE1[10] ," Gate_Firm_Rev.lowbyte{5} = ",DEC Gate_Firm_Rev.BYTE0[10] ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" Gate_Firm_Rev.highbyte[5] = ",DEC Gate_Firm_Rev[0]/256 ," Gate_Firm_Rev.lowbyte{5} = ",DEC Gate_Firm_Rev[0]//256 ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" Gate_Firm_Rev.highbyte[5] = ",DEC Gate_Firm_Rev[1]/256 ," Gate_Firm_Rev.lowbyte{5} = ",DEC Gate_Firm_Rev[1]//256 ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" Gate_Firm_Rev.highbyte[5] = ",DEC Gate_Firm_Rev[2]/256 ," Gate_Firm_Rev.lowbyte{5} = ",DEC Gate_Firm_Rev[2]//256 ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" Gate_Firm_Rev.highbyte[5] = ",DEC Gate_Firm_Rev[3]/256 ," Gate_Firm_Rev.lowbyte{5} = ",DEC Gate_Firm_Rev[3]//256 ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" Gate_Firm_Rev.highbyte[5] = ",DEC Gate_Firm_Rev[4]/256 ," Gate_Firm_Rev.lowbyte{5} = ",DEC Gate_Firm_Rev[4]//256 ,13,10,10,10 ] 'debug
Serout2 PORTb.7,84, [" Gate_Firm_Rev.highbyte[5] = ",DEC Gate_Firm_Rev[5]/256 ," Gate_Firm_Rev.lowbyte{5} = ",DEC Gate_Firm_Rev[5]//256 ,13,10,10,10 ] 'debug
output
ready
z = 0 GateID_word[z] = 10 Gate_Firm_Rev[z] = 84
0. GateID_word[0] = 10 Gate_Firm_Rev[0] = 84 Gate_Firm_Rev.highbyte[0] = 0 Gate_Firm_Rev.lowbyte{0} = 84
1. GateID_word[1] = 8511 Gate_Firm_Rev[1] = 85 Gate_Firm_Rev.highbyte[1] = 0 Gate_Firm_Rev.lowbyte{1} = 85
2. GateID_word[2] = 16367 Gate_Firm_Rev[2] = 86 Gate_Firm_Rev.highbyte[2] = 0 Gate_Firm_Rev.lowbyte{2} = 86
3. GateID_word[3] = 65281 Gate_Firm_Rev[3] = 87 Gate_Firm_Rev.highbyte[3] = 0 Gate_Firm_Rev.lowbyte{3} = 87
4. GateID_word[4] = 63752 Gate_Firm_Rev[4] = 88 Gate_Firm_Rev.highbyte[4] = 0 Gate_Firm_Rev.lowbyte{4} = 88
5. GateID_word[5] = 49026 Gate_Firm_Rev[5] = 89 Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 89
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 84
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 85
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 86
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 87
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 88
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 89
Re: strange word varable array results
is this a bug for 3.07 ?
and why only for indexed words of 1,3,5 and not 0,2,4 ?
Re: strange word varable array results
YOUR not picking up on what i.m saying
Quote:
is this a bug for 3.07 ?
no
Quote:
and why only for indexed words of 1,3,5 and not 0,2,4 ?
WRONG it is wrong for any index but 0
look at post#3 output
0. GateID_word[0] = 10 Gate_Firm_Rev[0] = 84 Gate_Firm_Rev.highbyte[0] = 0 Gate_Firm_Rev.lowbyte{0} = 84
1. GateID_word[1] = 8479 Gate_Firm_Rev[1] = 85 Gate_Firm_Rev.highbyte[1] = 85 Gate_Firm_Rev.lowbyte{1} = 0
2. GateID_word[2] = 16367 Gate_Firm_Rev[2] = 86 Gate_Firm_Rev.highbyte[2] = 0 Gate_Firm_Rev.lowbyte{2} = 85
3. GateID_word[3] = 65281 Gate_Firm_Rev[3] = 87 Gate_Firm_Rev.highbyte[3] = 86 Gate_Firm_Rev.lowbyte{3} = 0
4. GateID_word[4] = 63744 Gate_Firm_Rev[4] = 88 Gate_Firm_Rev.highbyte[4] = 0 Gate_Firm_Rev.lowbyte{4} = 86
5. GateID_word[5] = 32640 Gate_Firm_Rev[5] = 89 Gate_Firm_Rev.highbyte[5] = 87 Gate_Firm_Rev.lowbyte{5} = 0
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 84
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 85
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 86
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 87
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 88
Gate_Firm_Rev.highbyte[5] = 0 Gate_Firm_Rev.lowbyte{5} = 89
Re: strange word varable array results
found this in the pbp3 book
Quote:
One more note about array variables. The modifiers associated with scalar
variables can't be used with array variables:
stored[1].BYTE0 = 0 'ERROR
"if all else fails"
Re: strange word varable array results
I remember having had something like that with a Pic 18 chip, some years ago ...
Melanie ( or Darrel ??? ) kindly explained me that ... the thread must still be on the Forum.
as a result ... I only used odd locations ...
- and it worked fine !!! -
Alain
Re: strange word varable array results
Hi,
On top of turning to the manual, whenever it comes to bits, bytes, words and arrays you should reference Melaines excellent writeup on the subject. For this particullar topic, look at section 5.
/Henrik.
Re: strange word varable array results
thanks guys ,
i lost a lot a time finding out the hardway ,
fortunatly the the indexed arrays i have so far are byte only
except for 2 which are word , and only this one had used the myvarable.highbyte to try get data , which need to be changed
looking at Melanie example ( thanks for the link hendrick )
5. How can I reference a BYTE in a WORD ARRAY?
As can be previously seen, all the bits in an array are stored sequentially in memory. It follows that the BYTES in a WORD ARRAY also follow sequentially. This means we can easily extract any BYTE we want to out of a WORD Array in a similar manner. Consider again…
MyWordArray var WORD [25]
There are actually 50 Bytes in this array (0-49). The first byte (0) being the LOWBYTE of MywordArray(0), and the last byte (49) being the HIGHBYTE of MyWordArray(24). Using a similar manner to Bit access, we can access all fifty Bytes of this Word array like so…
MyWordArray.Lowbyte(MyVar)
Where MyVar is in the range 0-49 for my previously defined example Array of 25 Words.
This is really handy, because we can use this method of loading or unloading Word Arrays from EEPROM for example very easily.
Note that HIGHBYTE cannot be used in this instance, because it cannot access the LowByte of the first array element… ie..
MyWordArray.HighByte(0)=MywordArray.LowByte(1)
all the way to…
MyWordArray.HighByte(48)=MywordArray.LowByte(49)
More dangerously, MyWordArray.HighByte(49) will actually perform an unauthorised access on an unknown byte OUTSIDE the MyWordArray structure.
Melanie
Re: strange word varable array results
so for me getting the data into the word index array
myword_tmp.lowbyte = byte0
myword_tmp.highbyte = byte1
myword_index(X) = myword_tmp
--------------
getting is out
for x = 0 to 5 ' index var 6 words
hserout [" highbyte = " myword_index.lowbyte[X*2 +1] , "lowbyte = " , myword_index.lowbyte[X*2 ] ,13,10]
next x
Re: strange word varable array results
for what is worth I think my way is more readable
hserout [" highbyte = " myword_index.[X*2 ].highbyte , "lowbyte = " , myword_index.[X*2 ].lowbyte ,13,10]
Re: strange word varable array results
simple byte swap , but what have i missed getting rubbish o0n the word variable
Code:
SDC_buffer[250] = GateID_word.lowbyte[T*2+1] 'indexed highbyte ' copy the varables to tmp varable
SDC_buffer[251] = GateID_word.lowbyte[T*2] 'indexed lowbyte
SDC_buffer[252] = Gate_CH_V_Num[T]
SDC_buffer[253] = Gate_RX_Sens_Trig[T]
SDC_buffer[254] = Gate_Prod_Bat_Lvl[T]
GateID_word[T] = GateID_word[T+1] ' copy index varables to neighbors next index
Gate_CH_V_Num[T] = Gate_CH_V_Num[T+1]
Gate_RX_Sens_Trig[T] = Gate_RX_Sens_Trig[T+1]
Gate_Prod_Bat_Lvl[T] = Gate_Prod_Bat_Lvl[T+1]
GateID_word.lowbyte[(T*2+1)+1] = SDC_buffer[250] ' indexed highbyte +1 ' copy temp varables to next index
GateID_word.lowbyte[(T*2) +1] = SDC_buffer[251] ' indexed lowbyte +1
Gate_CH_V_Num[T+1] = SDC_buffer[252]
Gate_RX_Sens_Trig[T+1] = SDC_buffer[253]
Gate_Prod_Bat_Lvl[T+1] = SDC_buffer[254]
Re: strange word varable array results
i could make it easy by copy to word temp and back but i should not have to
Re: strange word varable array results
What version of PBP you use?
Re: strange word varable array results
i changed to use a tmp word but it looks like it should work , index variable word to bytes and back
3.07.1
Re: strange word varable array results
If you are using PIC18F, updating to 3.08 may solve you problem.
I had similar problem, and it was bug in PBP. Bug was fixed in PBP3.08.
http://www.pbp3.com/download.html
So give it a try...
Re: strange word varable array results
Code:
GateID_word.lowbyte[(T*2+1)+1] = SDC_buffer[250] ' indexed highbyte +1 ' copy temp varables to next index
GateID_word.lowbyte[(T*2) +1] = SDC_buffer[251] ' indexed lowbyte +1
should be
Code:
GateID_word.lowbyte[(T*2+1)+2] = SDC_buffer[250] ' indexed highbyte +1 ' copy temp varables to next index
GateID_word.lowbyte[(T*2) +2] = SDC_buffer[251] ' indexed lowbyte +1
Re: strange word varable array results
yep thanks richard could not see it