PDA

View Full Version : Sending Commands from Visual Basic about IR to Pic



tne_de
- 1st April 2009, 09:58
Hello,
i want to send commands about a Visual Basic (Express 2008) about IR to a pic.
The IR Led is connected with my pc on COM 1.

My VB Code Snippet:


[...]
' Connection to COM1
With serialPort
.PortName = cbbCOMPorts.Text 'COM1
.BaudRate = 2400
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
End With
[...]
serialPort.Write(txtDataToSend.Text) 'txtDataToSend = Input txt field



My PBP Code for recipient


main:
serin ir,0,["9999"],dat

IF dat=1 THEN
led2=turnoff
led1=turnon
ENDIF

IF dat=5 THEN
led1=turnoff
led2=turnon
ENDIF
GOTO main


My PBP Code for sender


main:
SEROUT led5,12,["9999",1]
PAUSE 100
SEROUT led5,12,["9999",5]
PAUSE 100
GOTO main


With this PBP Code it works regarding Pic to Pic communication.
But if I send "99991" or "99995" by my Visual Basic programm it does not work.

I read in the manual that the 12 in the SEROUT command send the data "open inverted" - what does it mean? How could I "open inverted" my command in Visual Basic (Express 2008)?

Best regards

EDIT: Additional Information I use a PIC 12F629

sougata
- 2nd April 2009, 04:00
Hi,

I really don't know if inversion can be achieved using the default serial class. You can connect the LED to the positive rail and the TX output via a limiting resistor. This give you a straight out. Positive rail is not available on the RS232 connector. So use the DTR line and flip it (Set High) in VB before starting the communication. This gives you a steady positive supply on DTR (8-12 volts). Connecting the LED to the ground inverts the signal. Take care of the LED polarity at the TxOut in both the cases.

mister_e
- 2nd April 2009, 14:44
I would suggest you try to send data to your PC to a terminal software first (Hyperterm, MicroCode Serial communicator or whatever else).

Then from your PC to your PIC.

I you have good results, then move on VB. I had some bad experiments in the past on some computer on low baudrate.

High likely, you're using the internal OSC of your PIC? Don't forget at least the OSCCAL_1K define. Not a bad idea to use DEBUG/DEBUGIN as well. It perform better on some case.

Use current limiting resistor & the InvertedMode on the PIC side, and it should work on small distance between your PIC and the PC.

On VB side, I would suggest you to use ReadLine. To use it, you'll need to modify your PIC code to send a LF character (10) at the end.

Luckyborg
- 2nd April 2009, 16:02
I think the problem is with "1" vs 1 (SOH)


My PBP Code for sender
Code:

main:
SEROUT led5,12,["9999",1]
PAUSE 100
SEROUT led5,12,["9999",5]
PAUSE 100
GOTO main

With this PBP Code it works regarding Pic to Pic communication.
But if I send "99991" or "99995" by my Visual Basic programm it does not work.

Your pic is sending out hex 1 and your vb is sending out hex 31
To get vb to send out a 1 try
txtDatatoSend.txt = "9999" & chr(1)
this will add a 1 to it, though if you ever want to send 0 it will actually be sending nul characters

On the other hand you could send a "1" and on the pic side once you receive your dat variable, just subtract "0" from it to give you the value you want or change your if statements to check for "1"

samrulezzz
- 29th April 2009, 06:09
Hi Sougata

needed a bit of help on inverters using pic16f72
read ur posts on the following thread
http://www.letbasic.com/forum/showthread.php?t=1846&page=4

this thread is a year or more old so i believe u have advanced ur inverter quite a lot

can u help on pic 16f72 code as i'm very bad on coding weras i ve pretty gud hardware knowledge.......

sam
[email protected]