HELP! Serial input between Pic and PC (urgent)


Closed Thread
Results 1 to 35 of 35

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Project instructions:
    1. Read the Data Sheet.
    2. Read the PIC Basic manual.
    3. Read this forum.
    4. Use FIRE extinguisher.

    5. Post question stating:
    A. Every thing you tried
    B. Post Your CODE.
    C. Post schematic if applicable.

    Back to the topic....
    Quote Originally Posted by cmyew View Post
    Now i still try to troubleshooting for the code and my hardware. Hopefully it can be working one day.
    What problems are you still having?
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Nov 2007
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Hi Dave,

    1. The attachment is my circuit diagram, pls comment to me if there are something wrong.
    Thanks

    2. Source Code:
    '################################################# #########
    Define OSC 10
    include "Modedefs.bas"
    ADCON1 = 7

    TRISA = %010000 'RA4 as serial input, RA3 as serial output
    TRISB = 0 'PortB used to ON the LED

    CHAR var byte

    PORTB = 0

    Main:

    SERIN PORTA.3,T9600,CHAR

    PORTB = CHAR

    SEROUT PORTA.3,T9600,[CHAR,10] 'I used hyperterminal to received the data
    'that sent to pic

    GOTO MAIN
    ############################################

    3. I was try to change the value of OSC but still get the same result. For Example: when i sent "1" from hyperterminal to pic but the result that returned to hyperterminal is " ' " then the result on LED is "11111010". I was checked the ASCII table, the result is not same with the data i sent.
    Attached Images Attached Images  

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Hi guys,

    I'm a new guy where pics are concern, but i'm more experienced with my other hobbys.

    Since i dont have anyone that i can learn with i have to teach my self and learn with my mistakes and experiments.

    For each hobby i have i also participate in the related forums.

    I try to share my experience and try to give my knowledge with the new guys as i remember myself some time before asking for it or came across a dead end as the new guys do now.

    Sure for me can be obvious some issue but it can be a hard step for a new guy to go through.

    And i know how fustrating can be when hitting a dead end and not having a little help to get arround it. I know some people that leave their hobbys for that.

    This is the point of the foruns. For people to share information and experiences. To help the other guy regardless of the question.

    Me for example i use datasheet but because i'm a new guy in pic world there are many thing i dont undestand in them !

    I've been helped many times here and i believe that if it wasnt for the guys here i wouldnt be able to continue with my learning curve and getting stuck with a flat line !

    Sorry for the long post...just wanted to share my humble opinion

    .

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


    Did you find this post helpful? Yes | No

    Default

    The first thing that I see is you have SERIN and SEROUT on the same pin.
    Code:
    SERIN PORTA.3,
    
    SEROUT PORTA.3,
    I have never tried A4 for serial
    http://www.picbasic.co.uk/forum/showthread.php?t=562
    You may have to use another pin.

    Right now do not worry about TRISA. The SERIN/SEROUT takes care of that.
    Dave
    Always wear safety glasses while programming.

  5. #5
    sinoteq's Avatar
    sinoteq Guest


    Did you find this post helpful? Yes | No

    Default

    If you just want the short answer.....

    I think you may have made a misstake with the pins
    PORTA.3 is Data PIC>>>>PC (serout in pbp)
    PORTA.4 is Data PC>>>>PIC (serin in pbp)
    using PORTA.4 as an input is not a problem at all, if you want to use it as output you need a pull-up resistor to make it work.
    Change is your sw and it might work better.

    If you want a longer answer......
    Yes datasheet can be really strange to read and understand, this we all have to accept. Training and experience will make it easier and even simple. This is fact.

    Now to a different thing, making electronics with PIC inside is not that different from sport, training makes a difference and not all people have the same skills. It is easy to wish for a cool electronic gadget but much harder to make it. I am not writing this to put someone down, no I am writing this to explain how to get there and that is One Small Step at the Time. Don't expect to write a missileguiding SW the first day but eventually you will.

    So I want to make a thing that can turn on and off LED from a PC, how would I do that?

    A, Make a plan, with a good plan you will save much time later. Figure out what you want the circuit to do and what hardware you will need. You can always make the plan better later but you honestly need a plan before you start.

    B, Test the hardware. Here is the best thing the undervalued Flash a LED program most usefull. Time spent verifying the hardware you will get back 1000 times later because when you see strange things you can rule out HW problems. If you can't flash a led you can not expect anything else to work ever....

    C, If you want to connect to a PC do not start with a SERIN problem. Start with a SEROUT so you can see that you can send data to the PC. Even if you will not use it later?? YES!! Because it is easier to recieve data with a PC compared with a PIC, if you can send data to the PC it is more likely that the other way is working also. I almost always include a line early in the program to send SEROUT......... " PIC STARTED " so when I see this is hyperterminal I understand that the PIC is happy. It is also a great way of troubleshooting later because you can always send serial data to the PC to display arrays and other variables. When you can see the data on the PC you have proof that Baud and Mode are correct and you also know you are using the correct serial port on the PC.

    D, Make sure you know where the PIC is in your progam before you do a Serin. Like other people said before use a start char to start the Serin function for example ":" or "X" or any other you want to use, just make sure you use one.... so do a serout first in your code
    Serout............"PIC waiting for data" followed by a SERIN ........... that has a start char. Now you are sure that the PIC is waiting for char from the PC, now use the PC to send 2 char (start char + data char). After the Serin line I would put a new Serout line that has Serout.......... "Data recieved",#Data_Char Now I can see that the PIC moved forward in the program and what data was recieved. Please remember that ASCII and dec numbers can be confusing so double check or force the data to be in DEC fromat using the # function. IF you are not using a start char you are not sure that the data char is correct, serin will take any data and you will be in the land of trouble.

    This is one small step at the time, the key to R&D and the best way to make progress. Later when you have everything working you can remove lines in the code that you are not using and the code becomes smaller and cleaner.

    The good thing with PIC is that they are small computers, they do exactly what you tell them, the bad thing with them is they are small computers, they do exactly what you tell them. You can not expect the PIC to be forgiving in anyway, there are no help files incuded just the data sheet written by nerds for nerds.

    To make the a circuit that turns on a LED is a very good project but it is not a simple project, it will take time, skill and patience but eventually you will get it to work.

    Define OSC 10
    include "Modedefs.bas"
    ADCON1 = 7

    TRISA = %010000 'RA4 as serial input, RA3 as serial output
    TRISB = 0 'PortB used to ON the LED

    CHAR var byte
    PORTA.3=1
    PORTB = 0
    SEROUT PORTA.3,T9600,[" PIC started",10,13] 'I used hyperterminal to received the data
    GOTO MAIN


    PC_IN:
    SEROUT PORTA.3,T9600,["Use : as start char",10,13] ' write :A in hyperteminal...
    SERIN PORTA.4,T9600,[":"],CHAR
    SEROUT PORTA.3,T9600,["Data from PC ",CHAR,10,13] '
    RETURN

    Main:
    GOSUB PC_IN

    GOTO MAIN




    GOTO MAIN

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default

    And after all that, I still cannot understand why you don't use the USART of the PIC? Are you going to use those pin to connect something else?

    Ioannis

  7. #7
    Join Date
    Nov 2007
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Hi sinoteq,

    Thanks for your advice, I will try this.

    Hi Ioannis,

    Yes, I was using the PORTC to do another function.

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default

    If you can reassign the port pins, I strongly suggest to do so. The gain is enormous in processing speed/power.

    Ioannis

Similar Threads

  1. Send binary file to pic over pc serial port
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 3rd May 2011, 13:47
  2. Replies: 11
    Last Post: - 12th July 2008, 02:36
  3. interfacing to the pc serial port
    By kelangfei in forum General
    Replies: 4
    Last Post: - 7th October 2007, 22:35
  4. High Speed Serial Comm PC - PIC and PIC - PIC
    By manumenzella in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 16th January 2007, 21:55
  5. Replies: 5
    Last Post: - 20th March 2006, 01:34

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