Code for Send/Receive TTL/Comport Sample?


Closed Thread
Results 1 to 40 of 53

Hybrid View

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

    not having good luck here, this is getting something but not sure what its doing. my "Char" decimal is anything from 062 to 640, its a bit random, and not sure whats up.
    I am sending a single character from the PC using its ascii code from 0 - 255, the pc sends corrosponding letter., ive tried multiple letters it dont matter. changing by 1 doesnt change the result, its weird. but heres my code if anyone sees anything off. oh and my pc is set up as 8N1 no parity@9600

    Code:
    INCLUDE "LCD_D.bas"
    
    define OSC 4                               ' PORTA is input
    define HSER_BAUD 9600
    DEFINE HSER_CLROERR 1
    RCSTA = $90
    TXSTA = $24
    TRISD = 0                               ' PORTD is output
    
    Char   var byte    ' character input
    
    Mainloop:
    hserin 5000, Timeout, [Char]
    
    LCDOUT $FE, 2
    LCDOUT $FE, $80
    LCDOUT "MY DATA = ", DEc Char
                 
    PAUSE 20                                ' Wait 20 ms
    GOTO mainloop                           ' Repeat
    
    Timeout:
    pause 10
    goto mainloop  
    END
    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..."

  2. #2
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

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

    Maybe this will help
    char var byte[2]
    hserin 5000, Timeout, [(WAIT "Start:"),Char]' one char
    hserin 5000, Timeout, [(WAIT "Start:"),str Char\2]' 2char or hserin 5000, Timeout, [(WAIT "Start:"),Char[0],char[1]]'
    LCDOUT "MY DATA = ", DEc Char or LCDOUT "MY DATA = ", DEc Char[0]," ", DEc Char[1]," "
    And send from PC:
    Dim ByteArray(4) as Array
    ByteArray(0)=10
    ByteArray(1)=20
    'send only one byte
    com1.Write("Start:")
    com1.Write(ByteArray,0,1)
    'send only two byte
    com1.Write("Start:")
    com1.Write(ByteArray,0,2)

  3. #3
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

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

    Does your hardware have an inverter like a MAX232?

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

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

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


    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

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

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