View Full Version : serial to PIC
kindows
- 10th July 2009, 10:02
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.
mackrackit
- 10th July 2009, 11:31
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.
kindows
- 11th July 2009, 06:30
So So but I can't find the answer on it
mackrackit
- 11th July 2009, 07:23
I misread your post before...
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.
kindows
- 11th July 2009, 09:37
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.
kindows
- 11th July 2009, 13:59
its not working
:D
aratti
- 11th July 2009, 16:29
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.
kindows
- 12th July 2009, 16:31
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 ??
mackrackit
- 12th July 2009, 16:49
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.
kindows
- 12th July 2009, 17:02
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:)
mackrackit
- 12th July 2009, 17:31
Send K3...
kindows
- 13th July 2009, 11:31
Its not working
PLZ help me
aratti
- 13th July 2009, 13:23
check if your wiring is the same as the attached schematic.
Al.
kindows
- 13th July 2009, 14:20
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
aratti
- 13th July 2009, 14:40
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.
kindows
- 13th July 2009, 14:55
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.
kindows
- 13th July 2009, 15:48
plz help me.
aratti
- 13th July 2009, 18:13
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.
Ioannis
- 14th July 2009, 09:28
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
kindows
- 14th July 2009, 12:31
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
mackrackit
- 14th July 2009, 13:34
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.
kindows
- 14th July 2009, 13:40
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
mackrackit
- 14th July 2009, 13:58
Try this and see if you see it blink
blink:
HIGH PORTb.7
PAUSE 250
LOW PORTb.
PAUSE 250
GOTO blink
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.