Checksum


Closed Thread
Results 1 to 3 of 3

Thread: Checksum

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    I haven't looked at this properly, but just giving it a quick glance, I think you need to zero the variable CHECKSUM before starting the FOR/NEXT loop.

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Thanks I noticed that one later but have left it out so I can call my routine with the packet start byte value pre-loaded into checksum now.

    So I call the routine after loading checksum with either $AA or $87 (My 12 byte packet start byte) I then run the routine on the array and store the checksum in the last byte making twelve in all.

    My main program - onfigs now looks like this. The checksum is commented out at present during some other testing.

    Code:
    'Main Program Start
    
    Commloop: 					'Start of Communications Loop
    
    	HSERIN [WAIT($87), STR BCMDATA\11]	'Wait for packet start $87 then Receive 11 bytes into array BCMDATA
    	
    	
    	'CheckSum = $87				'Load Checksum with packet start byte value
    	'Gosub CalcSum				'Gosub CalcSum to Calculate Checksum 
    
    	HSEROUT [$87,str BCMDATA\11]		'Transmit 12 bytes inc packet start byte $87
    	
    	
    	HSERIN [WAIT($AA), STR BCMDATA\11]	'Wait for packet start $AA then Receive 11 bytes into array BCMDATA           	
    	'CheckSum = $AA				'Load Checksum with packet start byte value
    	'Gosub CalcSum				'Gosub CalcSum to Calculate Checksum 
    
    	HSEROUT [$AA,str BCMDATA\11]		'Transmit 12 bytes inc packet start byte $AA
    
    
    'Data txd/rxd test outputs known values below to check transmission & reception
    	
    	Pause 32				'Pause for 16ms
    	HSEROUT [$AA,$10,$00,$00,$00,$20,$40,$61,$10,$01,$00,$74]		'Transmit 12 bytes 
    	pause 32                'Pause for 16ms
    	HSEROUT [$87,$40,$58,$15,$6E,$10,$01,$32,$2F,$2F,$04,$39]		'Transmit 12 bytes 
    	pause 32                'Pause for 16ms
    
    	goto CommlooP			'Goto Loop      
        
    CalcSum:					'Calculate Packet CheckSum Routine
    	
    	For Count1 = 0 to 10			'For Count1 = 0 to 10 (Start 11 byte loop)
    	CheckSum = CheckSum + BCMDATA[Count1]	'Add Bytes
    	Next Count1				'Repeat until 11 bytes added
    	CheckSum = NOT CheckSum			'Not CheckSum
    	CheckSum = CheckSum + 1			'Add 1 to CheckSum
    	BCMDATA[11] = CheckSum AND $7F 		'AND result
    	Return					'Return

Similar Threads

  1. NMEA CheckSum Routine
    By Tom Gonser in forum Code Examples
    Replies: 2
    Last Post: - 6th June 2015, 22:24
  2. Can PBP & 16f88 really do 9600,8,E,1
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 38
    Last Post: - 7th November 2010, 12:12
  3. 4 Bytes one button press
    By Dennis in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th January 2010, 22:36
  4. Creating Checksum in PBP
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 16th March 2005, 04:49
  5. Checksum problem!
    By atomski in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd November 2004, 07:21

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts