serial to PIC


Closed Thread
Results 1 to 23 of 23

Thread: serial to PIC

  1. #1
    Join Date
    Jul 2009
    Posts
    15

    Default serial to PIC

    I am picbasic pro user
    I made this program to send serial signal from PIC to PC

    define osc 4
    include "bs2defs.bas"

    key1 var porta.2

    findkey:
    if key1 = 0 then press1

    press1:
    SEROUT PORTa.0,N9600,["KINDOWS 1 "]
    goto findkey

    by this program if I make port a.2 = 0 the program send this [kindows] as a serial signal from port a.0.

    Now I need If I send serial signal from PC to PIC
    If I send this [k] from PC to PIC and then PIC make any port like RA1 high to active a relay.
    Please some one help me soon.

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


    Did you find this post helpful? Yes | No

    Default

    http://www.picbasic.co.uk/forum/showthread.php?t=561
    Not sure of the PIC you are using...but if it has analog on it the above should help.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jul 2009
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    So So but I can't find the answer on it

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


    Did you find this post helpful? Yes | No

    Default Tesla

    I misread your post before...
    Code:
     SERIN PORT?.?,N9600,[K],myVar
    IF myVar = 3 THEN gosomeplace or dosomething
    Send K and another value from the PC " K3 " for example.
    The PIC will wait for the "K". When the PIC receives a "K" the next character will be written to myVar.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Jul 2009
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Hi..
    thank u alot I lik [Always wear safety glasses while programming]

    I forget to tell u I am new in PICBASIC PRO now only 2 weeks. I think the code will be like this:
    define osc 4
    include "bs2defs.bas"

    wait:
    SERIN PORTa.1,N9600,["K3"],myVar
    IF myVar = 3 THEN out

    out:
    HIGH PORTb.7
    PAUSE 300
    LOW PORTb.7
    goto wait

    but I cant understand [myvar]. How I can decide it???
    Thank u in advance.

  6. #6
    Join Date
    Jul 2009
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    its not working

  7. #7
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Code:
    define osc 4
    include "bs2defs.bas"
    
    wait:
    
    SERIN PORTa.1,N9600,["K"],myVar
    
    IF myVar = 51 THEN out ' Ascii 51 = decimal 3 (When you type 3 myvar will be 51)
    
    goto Wait ' this line is esential otherwise any key will activate the function 
    
    out:
    
    HIGH PORTb.7
    
    PAUSE 300
    
    LOW PORTb.7
    
    goto wait

    This is the code that Dave suggested.

    From keyboard type K3 to activate portB.7 for 300 millisecs.


    Al.
    Last edited by aratti; - 11th July 2009 at 16:35.
    All progress began with an idea

  8. #8
    Join Date
    Jul 2009
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Now I am using windows hyper terminal to send serial signal. When I am sending [k] from it the terminal send it in ascii or in hex??
    I think send it in Ascii!!!

    so I have to send [k] or [k3]??

    and becuse I am new in PICBASIC PRO I can't understand how I can decide [myvar]
    Can u help ??

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


    Did you find this post helpful? Yes | No

    Default

    Read the post from Al very carefully. He has everything there you need.

    Not sure what you mean by deciding "myVar". It is just a variable
    to store a value. The serin command will write data to that
    variable and the if/then part checks to see what the value is.

    Oh, the safety glasses thing. It is not a joke.
    Dave
    Always wear safety glasses while programming.

  10. #10
    Join Date
    Jul 2009
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Do you think this code will working fine??

    define osc 4
    include "bs2defs.bas"

    wating:
    SERIN PORTa.1,N9600,["K"],b1

    IF b1 = 51 THEN out ' Ascii 51 = decimal 3 (When you type 3 myvar will be 51)

    goto wating ' this line is esential otherwise any key will activate the function

    out:

    HIGH PORTb.7

    PAUSE 300

    LOW PORTb.7

    goto wating
    -----------------------------------------------
    I am using PIC16F84a and port RA! Connected to 22k ohm then to the pc serial port. And I am using windows hyper terminal to send the serial signal now my question number tow is what I have to send [k3] or [3] or[k] or 51???

    good glass:)

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


    Did you find this post helpful? Yes | No

    Default

    Send K3...
    Dave
    Always wear safety glasses while programming.

  12. #12
    Join Date
    Jul 2009
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Its not working
    PLZ help me

  13. #13
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    check if your wiring is the same as the attached schematic.

    Al.
    Attached Images Attached Images  
    All progress began with an idea

  14. #14
    Join Date
    Jul 2009
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Yes it's like your drawing but not working. I send {k3} from the windows terminal and from another 2 programs and it's not working. I am using PICBASIC PRO and PIC16F84a and My code now exactly like this:

    define osc 4
    include "bs2defs.bas"

    wating:
    SERIN PORTa.1,N9600,["K"],b1

    IF b1 = 51 THEN out ' Ascii 51 = decimal 3 (When you type 3 myvar will be 51)

    goto wating ' this line is esential otherwise any key will activate the function

    out:

    HIGH PORTb.7

    PAUSE 300

    LOW PORTb.7

    goto watin
    -------------------------------------

    best regard
    kindows

  15. #15
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    check if hyperterminal settings are OK.

    In my case serial port is # 2, it could be different for your computer. The setting of snap 165 must be the same.

    Al.
    Attached Images Attached Images   
    Last edited by aratti; - 13th July 2009 at 14:42.
    All progress began with an idea

  16. #16
    Join Date
    Jul 2009
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Avery thing is same I am using USB converter [USB to serial 232] and I set up it to work in port 8 and I test it with another hardware [ customer LCD] and that is working fine.

  17. #17
    Join Date
    Jul 2009
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    plz help me.

  18. #18
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    I think the problem is with the USB-RS232 converter and the resistor connection to the pic.

    You must use a Max232 to connect pic to your PC with this converter.
    In such a case you must also change your code as follow :

    SERIN PORTa.1,T9600,["K"],b1


    Al.
    All progress began with an idea

  19. #19
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,806


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by kindows View Post
    wating:
    SERIN PORTa.1,N9600,["K"],b1

    IF b1 = 51 THEN out ' Ascii 51 = decimal 3 (When you type 3 myvar will be 51)

    goto wating ' this line is esential otherwise any key will activate the function

    out:

    HIGH PORTb.7

    PAUSE 300

    LOW PORTb.7

    goto watin
    Your loop label is wrong. watin instead of wating

    Ioannis

  20. #20
    Join Date
    Jul 2009
    Posts
    15


    Did you find this post helpful? Yes | No

    Default Thanks fo all

    Thanks for all how help me to finalize my project its working fine now. The problem was with output time I make it before 300 only that is not enough to make the LED blinking I make it now 3000 and its working fine now.

    Thanks for all and I hope we can find good idea to be in progress [[ [progress began with an idea]]] and on that time we will wear safety glasses while programming

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


    Did you find this post helpful? Yes | No

    Default

    I am glad it is working. But.....
    You should be able to see 300 millisecond blink.
    How long does the LED stay on now? Your code says 3 seconds.
    Dave
    Always wear safety glasses while programming.

  22. #22
    Join Date
    Jul 2009
    Posts
    15


    Did you find this post helpful? Yes | No

    Default 3000 milsec = 3 sec

    3 sec.That is fine to make relay work

    but now I have new Question I think u can help [blinking LED]

    best Regard in advance
    ------------------------
    KINDOWS

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


    Did you find this post helpful? Yes | No

    Default

    Try this and see if you see it blink
    Code:
    blink:
    HIGH PORTb.7
    PAUSE 250
    LOW PORTb.
    PAUSE 250
    GOTO blink
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. PIC to PIC "wired" serial one-way communication - SERIN2/SEROUT2
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th April 2008, 20:02
  2. Automatic VB6 to pic serial connection
    By arniepj in forum Code Examples
    Replies: 13
    Last Post: - 10th January 2008, 07:57
  3. Serial Com Pic to Pic
    By uludere72 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 31st May 2005, 10:06
  4. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14
  5. Serial communication PIC to PIC help.
    By Rubicon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th January 2005, 15:45

Members who have read this thread : 1

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