PDA

View Full Version : Need to convert C to PBP



timmers
- 12th July 2012, 13:56
I am trying to write some code in PBPpro from an example in C.
I have got so far but am not familiar with C.
They give the packet structure and an example, but I cannot decipher what the code is doing before retrieving a value from a lookup table, and hopefully someone will be able to assist me here.

Any help greatly appreciated.

By the way, attachment is copyright Atomos Pty, Australia.




CHKSUM VAR LONG
VALUE VAR LONG
COMMAND VAR WORD
SIZE VAR WORD
TEMP_W VAR WORD
TEMP_B VAR BYTE
BUFFER VAR BYTE [21]

SEND: SIZE = $14
COMMAND = 0
VALUE = 1

BUFFER [1] = SIZE.BYTE1
BUFFER [2] = SIZE.BYTE0
BUFFER [3] = COMMAND.BYTE1
BUFFER [4] = COMMAND.BYTE0
BUFFER [5] = $FF
BUFFER [6] = $FF
BUFFER [7] = $FF
BUFFER [8] = $FF
BUFFER [9] = $FF
BUFFER [10] = $FF
BUFFER [11] = $FF
BUFFER [12] = $FF
BUFFER [13] = VALUE.BYTE3
BUFFER [14] = VALUE.BYTE2
BUFFER [15] = VALUE.BYTE1
BUFFER [16] = VALUE.BYTE0

SOMEVALUE = ' <insert converted C code here >
GOSUB LOOK_CHKSUM

BUFFER [17] = CHKSUM.BYTE3
BUFFER [18] = CHKSUM.BYTE2
BUFFER [19] = CHKSUM.BYTE1
BUFFER [20] = CHKSUM.BYTE0


FOR TEMP_W = 1 TO SIZE
TEMP_B = BUFFER [TEMP_W]
HSEROUT [TEMP_B]
NEXT
GOTO MAIN_LOOP


LOOK_CHKSUM:
LOOKUP2 SOMEVALUE,_
[$0000, $1021, $2042, etc ], CHKSUM
RETURN

timmers
- 12th July 2012, 13:58
Dohh... Here is the attachment.

scrwld
- 4th August 2012, 04:29
hi timmers, you example is for calculate cyclic redundancy check (CRC16). look here two example one using Vb6 the another one with PBP. i use both

http://www.picbasic.co.uk/forum/showthread.php?t=16735

here explain how to that:

http://en.wikipedia.org/wiki/Computation_of_CRC

Archangel
- 6th August 2012, 06:47
I am still struggling to learn C myself so what I say here MAY BE TOTALLY INCORRECT.

const u16 crc_16_table[0x100]

const u16 = dataType , crc_16_table = varName, [0x100] = startMemLocation, & this can be put into program memory with PROGMEM command at least in arduino.
HTH