Can PBP & 16f88 really do 9600,8,E,1


Closed Thread
Results 1 to 39 of 39

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Progress

    I'm making good progress with my code thanks.

    I have a couple of questions about Arrays and the addressing of them with pbp.

    If I define an array thus.
    Code:
    BCMDATA VAR BYTE[11]		'Define BCMDATA as a byte array (11 Bytes)
    I get an array 11 bytes long and the address of the first byte is

    BCMDATA[0] and the last BCMDATA[10] ?

    Is that correct.

    Now onto for next loops.

    Code:
    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[10] = CheckSum AND $7F 		'AND result
    	Return					'Return
    In this code how many times does it complete?
    And on the first pass through the loop Count1 =0 does it not?
    And on the last pass through the loop Count1 = 9 or 10

    So if count1 = 9 it goes through the loop, if it = 10 it jumps over it?

    Just checking my understanding. Thanks

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Sounds like you are getting it.

    I would add
    Count1 = 0
    just before the for/next loop.
    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    I would add
    Count1 = 0
    just before the for/next loop.
    Why? Doesn't the command below do that?

    "For Count1 = 0 to 10"

  4. #4
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by retepsnikrep View Post
    Why? Doesn't the command below do that?

    "For Count1 = 0 to 10"
    He probably meant Checksum=0 before entering the loop.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by dhouston View Post
    He probably meant Checksum=0 before entering the loop.
    Yup. Sorry about that.
    Dave
    Always wear safety glasses while programming.

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Thanks for that. I have corrected my program.

    I do not load 'checksum' with 0 because I load it with one of the packet header characters $87 or $AA before I call the 'Calcsum' routine

    'Checksum' then already contains the first byte (header) of the packet when it enters, it then adds the content of the array 0-9 to the byte and does the checksum thing storing the result in position 10. So the packet is twelve bytes in all when sent out.

    $87 header + 10 data bytes from array + byte 11 from array which is calculated checksum (sum of previous 11 bytes inc header byte)

    I am collecting the checksum when reading in the data at the moment (and ignoring it) I will probably do the caluclation on it as well soon to make sure the incomming data is valid before I start messing about with it!!

    Thanks for all your help so far.

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Hmm, my checksum routine does not work and gives $ff as the last byte when using this data which I think is wrong.



    My code is here any thoughts?

    Code:
    '-------------------------------------
    ' PBP BCM CODE 25/10/09 V.15 8mhz
    '-------------------------------------
    
    @ DEVICE PIC16F88,INTRC_OSC_NOCLKOUT
    @ DEVICE PIC16F88,PROTECT_OFF
    @ DEVICE PIC16F88,WDT_ON
    @ DEVICE PIC16F88,PWRT_ON
    @ DEVICE PIC16F88,MCLR_ON
    @ DEVICE PIC16F88,BOD_OFF
    @ DEVICE PIC16F88,LVP_OFF
    @ DEVICE PIC16F88,CPD_OFF
    @ DEVICE PIC16F88,DEBUG_OFF
    @ DEVICE PIC16F88,CCPMX_OFF
    
    DEFINE OSC 8 			'Set oscilator speed to 8mHz 
    OSCCON=%01111000 		'8 Mhz
    
    'DEFINE OSC 4 			'Set oscilator speed to 4mHz  
    'OSCCON =%01100000		'4 Mhz
     
    DEFINE HSER_BAUD 9600		'Set Baud rate to 9600bps
    DEFINE HSER_BITS 9		'Set to 9 bit mode
    DEFINE HSER_EVEN 1		'Set Even Parity
    DEFINE HSER_CLROERR 1 		'Clear overflow error automatically
    
    ANSEL = 0 			'ALL DIGITAL
    CMCON = 7 			'COMPARATORS OFF
    INTCON = 0 			'Disable interrupts
    TRISB = %00000100 		'SET PORTB RB2(RX) as input, others to OUTPUT
    TRISA = %11111111 		'SET PORTA AS INPUTS
    
    'Variables
    
    BCMDATA VAR BYTE[11]		'Define BCMDATA as a byte array (11 Bytes) 
    Count1 VAR BYTE			'Define Count1 as a byte variable (Used in For/Next Loops)
    CheckSum VAR BYTE		'Define CheckSum as a byte variable
    Led1 VAR PORTB.0		'Define PortB.0 as Led1
    Led2 VAR PORTB.1		'Define PortB.1 as Led2
    
    'Constants
    
    
    '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
    	
        BCMDATA[2] = $15            'Load Soc Byte with $15 (19 Bars)
        BCMDATA[3] = $6F	        'Load Soc Byte with $6F (19 Bars)
    	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
    
    	goto CommlooP			'Goto Loop      
        
    CalcSum:					'Calculate Packet CheckSum Routine
    	
    	For Count1 = 0 to 9			'For Count1 = 0 to 9 (Start 10 byte loop)
    	CheckSum = CheckSum + BCMDATA[Count1]	'Add Bytes
    	Next Count1				'Repeat until 10 bytes added
    	CheckSum = NOT CheckSum			'Not CheckSum
    	CheckSum = CheckSum + 1			'Add 1 to CheckSum
    	BCMDATA[10] = CheckSum AND $7F 		'AND result
    	Return					'Return 	
    
    
    END
    My understanding of how the checksum is generated comes from this info.

    "Here's what I figured out so far: There are basically 10 data bytes per message. Before the first is the message type (AA or 87), and after the last is the checksum. You can compute it by adding the other 11 bytes, negating that (2's complement), then and'ing by 0x7f.
    It makes the entire message add to 0 when you and by 0x7f."


    And here is an known good sample.

    0x87,0x40,0x58,0x15,0x6E,0x10,0x01,0x32,0x2F,0x2F, 0x04,0x39

    Checksum byte is 0x39 at end.


    Ooppps I think I have been an idiot and included the AND part in my routine which should not be there and in fact is done by the receiving device to see if the result is 0!!!

  8. #8
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by retepsnikrep View Post
    If I define an array thus.
    Code:
    BCMDATA VAR BYTE[11]		'Define BCMDATA as a byte array (11 Bytes)
    I get an array 11 bytes long and the address of the first byte is

    BCMDATA[0] and the last BCMDATA[10] ?

    Is that correct.
    Correct.

    Quote Originally Posted by retepsnikrep View Post
    Now onto for next loops.
    Code:
    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[10] = CheckSum AND $7F 		'AND result
    	Return					'Return
    In this code how many times does it complete?
    And on the first pass through the loop Count1 =0 does it not?
    And on the last pass through the loop Count1 = 9 or 10

    So if count1 = 9 it goes through the loop, if it = 10 it jumps over it?
    It goes through the loop 11 times (0-10) with Count1=10 during the final pass. When it exits the loop, Count1=11. The loop counter is incremented and tested at the bottom of a For/Next loop. The test occurs at the top of a While/Wend loop.

    As written, your code writes a value to BCMDATA[10] in the loop and then overwrites BCMDATA[10] after exiting the loop. I suspect this is not what you want.

    While the following link is written for Visual Basic, I think all versions of Basic work the same way.
    Last edited by dhouston; - 25th October 2009 at 12:43.

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. PBP migration from 16F88 to 16F1827
    By RussMartin in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 21st June 2010, 18:14
  3. PBP, ASM and LST files
    By HenrikOlsson in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th January 2010, 13:43
  4. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  5. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30

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