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?

    I am at a loss here, I have researched over 30 online douments using HSERIN and for the most part they are all almost identicle. They all seem to be based on the MELABS HSERIN Sample, which is what mine is based off here. here is my code as it stands right now

    Code:
    '****************************************************************
    INCLUDE "LCD_D.bas"
    define OSC 4                               ' PORTA is input
    define HSER_BAUD 9600
    DEFINE HSER_CLROERR 1
    DEFINE HSER_EVEN 0
    DEFINE HSER_ODD 0
    RCSTA = $90
    TXSTA = $24
    TRISD = 0                               ' PORTD is output
    
    Char var byte[8]
    Hserout ["Hello World", 13, 10]
    
    Mainloop:
    hserin 5000, Timeout, [Char]
    LCDOUT $FE, 2
    LCDOUT $FE, $80
    LCDOUT "MY DATA = ", DEC Char
    GOTO mainloop                           ' Repeat
    
    Timeout:
    Hserout ["Hello World", 13, 10]
    goto mainloop  
    END
    Note that HSEROUT - I get no data on my pc... dont know why
    on HSERIN it sometimes changes the number but its rare and random. and the numbers may not be the same after reset.

    For right now, I just need to send a 16bit number to the PC and have the PC send a 16 bit number to the PIC, if this has to be done by sending the characters (2) from the PC to the PIC (i.e. AE ZT... etc...) for it to store each letter in its own byte and then the PIC can read 2 bytes together thats ok. sending from PIC to PC, im not sure what to expect right now
    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
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

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

    Hi,
    * Are you sure that the PIC is running at the desired frequency? You DEFINE OSC 4 but is it actually running at the 4MHz?
    * Have you doublechecked the schematic and circuit? Do you have the RX/TX pins wired properly?
    * I'm not 100% sure it's needed but I don't see any TRIS settings for the TX/RX pins, when in doubt do it, TX is output, RX is input.
    * I don't know which PIC you're using (which PIC are you using?) but are there by any chance any analog functions on the TX/RX pins?
    * What is LCD_D.bas?
    * Do you have a scope or logic analyzer you can use to verify that the PIC and/or PC is actually sending something and that the baudrate is correct?

    /Henrik.

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

  4. #4
    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, 10: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, 21: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, 14:37
  4. send and receive data using pic 16f84a
    By PoTeToJB in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2006, 21:12
  5. send and receive data using pic 16f84a
    By PoTeToJB in forum Serial
    Replies: 1
    Last Post: - 25th February 2006, 15: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