Code for Send/Receive TTL/Comport Sample? - Page 2


Closed Thread
Page 2 of 2 FirstFirst 12
Results 41 to 53 of 53
  1. #41
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Code for Send/Receive TTL/Comport Sample?

    Are you using pbp3 ?
    What about config cpudiv = osc1_pll2

  2. #42
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Code for Send/Receive TTL/Comport Sample?

    Did you get what you expected?
    Can you flash 1 sec on 1 sec off to be sure

  3. #43
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Code for Send/Receive TTL/Comport Sample?

    pbp 2.6
    /2 with pll no divide
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  4. #44
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Code for Send/Receive TTL/Comport Sample?

    Charlie is right txsta = $24 is affecting the baud rate and is just wrong

  5. #45
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Code for Send/Receive TTL/Comport Sample?

    every thing ive read including the melabs samples say to use $20 for baud rates lower than 9600 and $24 for higher, I even used a online calculator and pluggedin my info and it said that. so if thats wrong what would you suggest?

    Ive tried 24 and 20
    Last edited by wdmagic; - 2nd July 2013 at 15:07.
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  6. #46
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Code for Send/Receive TTL/Comport Sample?

    Not absolutely sure chris.
    If you are going to load the spbrg regs manually then yes defnitely the brgh bit needs to be set or reset accordingly
    but i assume when using hserout pbp will make its own choice for brgh depending on osc and baud rate defines , if you change it afterwards then things go wrong

  7. #47
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Code for Send/Receive TTL/Comport Sample?

    'RCSTA = $90
    'TXSTA = $24
    removed these, still errors
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  8. #48
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Code for Send/Receive TTL/Comport Sample?

    Maybe its logic levels can u buffer the signals through some cmos gates
    try again with the internal osc
    get a cro
    whats the ground connection like
    i'm away till friday
    good luck

  9. #49
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Code for Send/Receive TTL/Comport Sample?

    OK I got it to work , not sure why but I had to change OSC fuse to ECIO and not ECPIO, so even though im useing a ttl OSC I cant use RA6

    heres the code that works, note fuse is set to ECIO(NO USB) and PLL is set to 20Mhz

    Code:
    Define OSC 20 
    define HSER_BAUD 9600
    DEFINE HSER_BITS 8
    DEFINE HSER_CLROERR 1
    RCSTA = $90
    TXSTA = $20
    TRISC = %10000000
    TRISD = 0
    
    start:  
    Hserout ["Hello World", 13, 10] 
    pause 1000
    goto start
    End
    NOTE: TXSTA = $20 ' must be 20, 24 doesnt work, even though online articles said so.
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  10. #50
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Code for Send/Receive TTL/Comport Sample?

    OK the Data from PIC to PC works fine, but from PC to PIC fails, heres code Im working with, NOTE that im am still using 9600 8N1 on the pc.

    Code:
    Define OSC 20	'USE ECIO, NOT ECPIO
    define HSER_BAUD 9600
    DEFINE HSER_BITS 8
    DEFINE HSER_CLROERR 1
    RCSTA = $90
    TXSTA = $20		'DO NOT USE $24
    TRISC = %10000000
    TRISD = 0
    
    MYBYTE VAR BYTE
    
    MAINLOOP:
    mybyte = 0
    Hserin [MYBYTE]
    LCDOUT $FE, 2
    LCDOUT $FE, $80
    LCDOUT "MYBYTE = ", DEC MYBYTE
    Hserout ["Received = ", mybyte, 13, 10]
    goto mainloop
    LCD display numbers from 130 - 137 based on what character is sent, only a few characters work, say d - l (lower case) and they dont corrospond to any numbering system i was hoping for ascii values
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  11. #51
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Code for Send/Receive TTL/Comport Sample?

    Quote Originally Posted by wdmagic View Post
    OK I got it to work , not sure why....... NOTE: TXSTA = $20 ' must be 20, 24 doesnt work, even though online articles said so.
    Chris, the define statements are shortcuts built into PBP that do several things, including setting RXSTA and TXSTA properly for the BAUD you have chosen - and other registers. You can set ALL the registers manually, OR you use the define statements, but don't do both. When you set them manually in the next two statements after having just DEFINEd them, you are potentially changing those registers to an incorrect value, for instance the wrong value of 24. If you actually read the datasheet, you will see when 24 is correct and when 20 is correct. Likely the information in "online articles" was taken out of context. It is possible to make either value work for some baud rates, but to do so you need the correct values in other registers, like it says in the datasheet.

    If you are starting to hear a recurring piece of advice in my comments, you are getting the message. One last time... read the datasheet. The device datasheet tells you how to set all the registers, the PBP manual tells you what the defines actually do.

  12. #52
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Code for Send/Receive TTL/Comport Sample?

    yes, I usually read the manual and datasheets, this is just got alot of new terminology I dont understand. i did finnaly get it to send and receive, works great for what I'm going to be doing right now, i've got it sending and receiving 8 bytes, thats more than what I need and I can change it to whatever is best. thanks for the help, I shoudl be able to use this code untill I understand more.

    Code:
    Define OSC 20	'USE ECIO, NOT ECPIO
    define HSER_BAUD 9600
    DEFINE HSER_BITS 8
    DEFINE HSER_CLROERR 1
    RCSTA = $90
    TXSTA = $20		'DO NOT USE $24
    TRISC = %10000000
    TRISD = 0
    
    Name Var Byte[8]
    REFRESH VAR BYTE
    
    Gain:
    FOr REFRESH = 0 to 8
    pause 10
    Name[REFRESH] = 0
    next REFRESH
    if REFRESH = 8 then REFRESH = 0
    
    HSERIN 5000,test,[STR Name\8] : Pause 250
    HSEROUT [STR Name, 13, 10]
    LCDOUT $FE, 2
    LCDOUT $FE, $80
    LCDOUT Name[0],Name[1],Name[2],Name[3],Name[4],Name[5],Name[6],Name[7]
    pause 250
    Goto Gain
    
    test:
    pause 100
    goto gain
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  13. #53
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Code for Send/Receive TTL/Comport Sample?

    The code will work as is, but be careful if you want to make changes - it still has the error I pointed out.

Similar Threads

  1. how to send and receive sms using vb?
    By shyhigh2002 in forum Off Topic
    Replies: 0
    Last Post: - 1st April 2009, 09:18
  2. please who can help me for sample code
    By jasem700 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd February 2009, 20:41
  3. How to build modem for only send and receive the msg
    By PoTeToJB in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 7th April 2006, 13:37
  4. send and receive data using pic 16f84a
    By PoTeToJB in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2006, 20:12
  5. send and receive data using pic 16f84a
    By PoTeToJB in forum Serial
    Replies: 1
    Last Post: - 25th February 2006, 14:47

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