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


Closed Thread
Results 1 to 39 of 39

Hybrid View

  1. #1

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

    I have an 16f88 project which needs to communicate with an rs485 bus.

    The bus is fixed and I can't change the protocols so I need to be able to rxd & txd via the usart 9600,8,E,1 data.

    Can hserout/hserin or serin/out really do 8 data bits & an even parity bit?

    11 bits in all inc a start & stop bit.

    I know the pic usart can do 9 bit data transmission but it is not 100% clear I can do what I need in PBP without poking registers and driving the usart directly.

    Can someone give me a definitive answer? Any useful links would be great as well. I'm happy with the electronics side of this project, it's the pbp serial commands which are confusing me.

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


    Did you find this post helpful? Yes | No

    Default

    Have you read the manual entry for HSERIN? It has DEFINES for 8 bits + parity and for odd or even parity.

    EDIT: My print manual lists DEFINE HSER_BITS 9 (Use 8 bits + parity) for both HSerIn and HSerIn2 but, it is omitted in the online manual at MELabs
    Last edited by dhouston; - 8th October 2009 at 17:54.

  3. #3
    Join Date
    Jun 2005
    Location
    Up the bush, Western Plains, NSW Au
    Posts
    216


    Did you find this post helpful? Yes | No

    Default

    I have very successfully used an 'F88 at 9600. Used a 20MHz crystal and used debug / debugin rather than the normal serout stuff. No probs at all (so far)
    Peter Moritz.
    Up the bush, Western Plains,
    New South Wales,
    Australia.

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


    Did you find this post helpful? Yes | No

    Default

    µeLabs Support tells me the online version of the manual is out of date. So you should be able to do what you need with...
    Code:
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 9600
    DEFINE HSER_EVEN 1
    DEFINE HSER_BITS 9

  5. #5


    Did you find this post helpful? Yes | No

    Default Will this work?

    My first 16f88 code is here. Microstudio says it compiles correctly. I now need to try and load it into the pic!!

    It should recieve 12 bytes of 9600,8,E,1 data via Usart RX the then squirt it out the other side via Usart TX.

    Any glaring errors or ommisions?

    Code:
    '-------------------------------------
    ' PBP Fake BCM CODE 21/10/09 V.04
    '-------------------------------------
    
    @ DEVICE PIC16F88,INTRC_OSC_NOCLKOUT
    @ DEVICE PIC16F88,PROTECT_OFF
    @ DEVICE PIC16F88,WDT_OFF
    @ DEVICE PIC16F88,PWRT_ON
    @ DEVICE PIC16F88,MCLR_OFF
    @ 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 
    DEFINE HSER_BAUD  9600
    DEFINE HSER_BITS 9
    DEFINE HSER_EVEN 1
    DEFINE HSER_CLROERR 1 ; Clear overflow automatically
    
    OSCCON=%01111000 '8 Mhz
    ANSEL = 0 'ALL DIGITAL
    CMCON = 7 'COMPARATORS OFF
    INTCON = 0 ;Disable interrupts
    TRISB = %00000100 ;RB2(RX) as input, others to Output
    TRISA = %11111111 ;SET PORTA AS INPUTS
    
    PORTB.4 = 1
    DATAIN VAR BYTE[12]
    loop 
    HSERIN [str DATAIN\12]
    HSEROUT [str DATAIN\12] 
    goto looP
    END

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


    Did you find this post helpful? Yes | No

    Default

    loop should be loop:

    And you have omitted
    Code:
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    Last edited by dhouston; - 22nd October 2009 at 11:17.

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Dave

    Thanks for that!

    However I saw this earlier post which seems to imply the defines you mention are not required??

    http://www.picbasic.co.uk/forum/show...=hserin+parity

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


    Did you find this post helpful? Yes | No

    Default

    Ahhh! I should have looked at RXSTA & TXSTA in the datasheet. The PBP docs are a bit too cryptic at times.

  9. #9


    Did you find this post helpful? Yes | No

    Default

    Thanks I've made some changes to my code and it is working sort of.

    Code:
    '-------------------------------------
    ' PBP Fake BCM CODE 21/10/09 V.04
    '-------------------------------------
    
    @ DEVICE PIC16F88,INTRC_OSC_NOCLKOUT
    @ DEVICE PIC16F88,PROTECT_OFF
    @ DEVICE PIC16F88,WDT_OFF
    @ DEVICE PIC16F88,PWRT_ON
    @ DEVICE PIC16F88,MCLR_OFF
    @ 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 
    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
    
    OSCCON=%01111000 		'8 Mhz
    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
    
    DATAIN VAR BYTE[12]		'Define DATAIN as a byte array (12 Bytes)  
    
    loop: 				'Start of Communications Loop
    HSERIN [str DATAIN\12]		'Receive 12 bytes into array DATAIN
    HSEROUT [str DATAIN\12]		'Transmit 12 bytes from array DATAIN
    goto looP			'Goto Loop
    
    END
    Now what I want to do is use a qualifier so that the Hserin waits until $AA is received before it starts filling the array. I also want the $AA in the array though? Possible?

    So it should receive twelve bytes in all like this.

    0xAA,0x10,0x00,0x00,0x00,0x20,0x40,0x61,0x10,0x01, 0x00,0x74

    Does this look right?

    Code:
    loop: 				'Start of Communications Loop
    HSERIN [WAIT($AA), str DATAIN\12]		'Receive 12 bytes into array DATAIN  
    HSEROUT [str DATAIN\12]		'Transmit 12 bytes from array DATAIN
    goto looP			'Goto Loop
    I read that a delay may be required after the last send in the HSEROUT section or it may not transmit the last byte correctly?

  10. #10


    Did you find this post helpful? Yes | No

    Default

    Thanks for those comments.

    Any idea why this line won't compile?

    Code:
    HSERIN [WAIT($AA), str DATAIN\11]		'Receive 11 bytes into array DATAIN
    I want it to wait until a $AA appears before filling the array.

    I've tried square brackets, round brackets no $ etc etc!!!!!

    I get two errors bad expression and expected ]

  11. #11
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    That compiles for me (but micro code studio forces the capitalization of STR). However, since you are using asci, try adding quotes on your $AA

    Code:
    HSERIN [WAIT("$AA"), STR DATAIN\11]		'Receive 11 bytes into array DATAIN
    Last edited by ScaleRobotics; - 23rd October 2009 at 15:21.
    http://www.scalerobotics.com

  12. #12


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scalerobotics View Post
    Try adding quotes on your $AA

    Code:
    HSERIN [WAIT("$AA"), STR DATAIN\11]		'Receive 11 bytes into array DATAIN
    Tried that still get error expected ], tried sqaure brackets same result + syntax error

  13. #13
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by retepsnikrep View Post
    Tried that still get error expected ], tried sqaure brackets same result + syntax error
    I will get the same error, but only if I do not define DATAIN array before the wait line.
    http://www.scalerobotics.com

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


    Did you find this post helpful? Yes | No

    Default

    I don't see what is causing the syntax error.

    There is a sample program that shows various inputs using SerIn here...I believe HSerIn uses the same syntax.

    Also, lose the quote marks - you are waiting for $AA (i.e. 0xaa, a hex byte, binary %10101010) not ascii AA which would be "AA" without the $.
    Last edited by dhouston; - 23rd October 2009 at 16:00.

  15. #15


    Did you find this post helpful? Yes | No

    Default

    Nope still no joy won't compile.

    Just to clear up any confusion I'm waiting for a byte value to appear on the usart ($87) not an ascii string. I then want to gather the following data into the array. It's 9600 8,E,1 (24 bytes total in the packet inc the $87 start byte)

    This compiles

    Code:
    HSERIN [WAIT ($87)]		'Wait for byte $87 (135 Dec)
    
    as does this
    
    HSERIN [WAIT (135)]		'Wait for byte $87 (135 Dec)
    Looks like I will have to wait for the identifier then use another HSERIN command to get the following bytes. Problem is there is no break in the data and it follows on immdiately after the $87 if received. I hope it doesnt miss the start of the second byte

    I'll try this it compiles corectly.
    Code:
    HSERIN [WAIT ($87)]		'Wait for packet start Byte $87  
    HSERIN [STR BCMDATA\23]		'Receive following 23 bytes into array BCMDATA

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