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

    My complete code is here. Sadly I have now deleted the troublesome line and replaced it with two lines. I am using PBP 2.50 and PM

    Code:
    '-------------------------------------
    ' PBP BCM CODE 22/10/09 V.04 8mhz
    '-------------------------------------
    
    @ DEVICE PIC16F88,INTRC_OSC_NOCLKOUT
    @ DEVICE PIC16F88,PROTECT_OFF
    @ DEVICE PIC16F88,WDT_OFF
    @ 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[12]		'Define BCMAADATA as a byte array (12 Bytes) 
    Count1 VAR BYTE			'Define Count1 as a byte variable (Used in For/Next Loops)
    CheckSum VAR BYTE		'Define CheckSum as a byte variable
     
    
    Commloop: 				'Start of Communications Loop
    
        HSERIN [WAIT ($87)]		'Wait for Packet start Byte $87   
    	HSERIN [STR BCMDATA\11]		'Receive 11 bytes into array BCMDATA
    
    	'Gosub CalcSum			'Gosub CalcSum to Calculate Checksum 
    
        Hserout [$87]               'Transmit Packet start Byte $87
    	HSEROUT [str BCMDATA\11]	'Transmit 11 bytes from array BCMDATA
    	           	
        HSERIN [WAIT ($AA)]		'Wait for Packet start Byte $AA   
    	HSERIN [STR BCMDATA\11]		'Receive 11 bytes into array BCMDATA
    
    	'Gosub CalcSum			'Gosub CalcSum to Calculate Checksum 
    
        Hserout [$AA]               'Transmit Packet start Byte $AA
    	HSEROUT [str BCMDATA\11]	'Transmit 11 bytes from array BCMDATA   
    	
    	
    	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
    	CheckSum = 0				'Clear CheckSum Variable
    	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[12] = CheckSum AND $7F 		'AND result
    	Return					'Return 	
    
    
    END
    However i have just tried this.

    Code:
     HSERIN [WAIT($87), str BCMDATA\11]		'Receive 12 bytes into array DATAIN
    And it compiles correctly, might have been me with a typo!!!!! Arrggh. I let you know. Thanks for the help so far. This program is just proof of concept at the moment I know the "gosub" is not called at the moment. I'm trying to get the hserin/out working first.

    Anything with my configs or program that would stop a pickit2 icsp working I can't get that to work for love or money, but the chip works fine in a standalone programmer. I've checked the circuit and pickit2 voltages and it all looks fine. Just can't find device 99% of the time.

  2. #2
    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 retepsnikrep View Post
    Anything with my configs or program that would stop a pickit2 icsp working I can't get that to work for love or money, but the chip works fine in a standalone programmer. I've checked the circuit and pickit2 voltages and it all looks fine. Just can't find device 99% of the time.
    Do you have capacitors across VDD and VSS??
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Code:
    HSEROUT [$AA,str BCMDATA\11]
    will be slightly faster.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by dhouston View Post
    Code:
    HSEROUT [$AA,str BCMDATA\11]
    will be slightly faster.

    Thanks that's helpful. I'm pretty clued up with picaxe basic but am now trying to move over and the syntax for PBP is quite a bit different.

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


    Did you find this post helpful? Yes | No

    Default

    The schematic looks OK to me.
    Does the PicKit work with other chips?
    Do you have a regular breadboard to put the chip in and try the PicKit from there?
    Dave
    Always wear safety glasses while programming.

  6. #6


    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

  7. #7
    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.

  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.

  9. #9


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Do you have capacitors across VDD and VSS??
    My board is pretty standard with the ICSP pins and a 10k pullup on MCLR pin.

    It is powered by a 7805 100ma reg from a 12v bench psu. 1000uf on each side of reg + 0.1uf on vdd/vss pins of 16f88. I tried adding extra cap 10uf tantalum across vdd/vss no change. Are my 1000uf a bit big?

    Tried powering it from a 9v battery via reg. No apparent change.

    Connections checked on board using pickit2 software and it is supplying the correct voltages inc 12v on MCLR under trouble shooting mode.

    The chip does work in the board when programmed off board and is communicating as per my current software.

    Once every few trys it will communicate briefly but always reports errors or can't find device.

    Once the chip is running in the board I can't communicate with it. If I insert it blank into the board I can communicate initially but it does not program sucessfully and then I loose comms and have to erase it in my other programmer and program it with that!

    The board looks like this.

    http://www.solarvan.co.uk/bcm/fakebcm004.jpg

    My untidy schematic here.

    http://www.solarvan.co.uk/bcm/BATTSC..._INTERFACE.jpg

    I appreciate the help thanks.

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