Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Comparing strings with PIC Basic Pro???????

Not open for further replies.


New Member
Hello all.

I have a need to compare srtings with PIC Basic Pro. I have a Siteplayer ethernet module connected to a PIC16F877A and I want to send a string through the siteplayer out to the 877A. When the 877A recieves the string I want to compare it with an IF THEN statement and then send a serial command out. I can currently send strings out of my siteplayer to my PC as a test. But when I try to compile an IF THEN statement (comparing a string) in PIC Basic Pro I get an error that says "misplaced or incorrect ENDIF command".

Can anyone help?

You can't compare strings with PICBASIC PRO.. it is said in the manual. :( .... Actually PICBASIC PRO is awful at handling any type of strings. what are you trying to do? You can work around it say instead of having the siteplayer return to you a string, how about some comands?.

For example if instead of having the siteplayer send a "button1" you have some type of code that you made up then you can compare it. Say ASCII 27, 1 means button 1 was pressed.

I have a siteplayer and I have played with it around for a little bit.

Good LUck

Thanks Ivancho

Let me further explain what I am doing as I am still a bit confused with your response. :oops:

I have an 877A that will send binary data out to a device. If I have a momentary switch connected to one of the ports and push this switch, the data is sent fine. The end device responds accordingly. However, I want to control this device via ethernet with a Siteplayer. I could connect all 8 ports of the Siteplayer to 8 ports on the 877A but that would be a waste of ports on both ends (I may want to use these ports later for something else).

What I want to do is pass a command serially throught the Siteplayer to the 877A and then have the 877A send out the binary data (from above) to my device. I dont' need to read back to the Siteplayer from the 877A just outputting for now.

I have already tested sending a string from the Siteplayer to my PC. So I know that I can send data serially from my Siteplayer. Now I want my 877A to respond to different serial commands and act accordingly.

My dilema is the IF THEN statement in PIC Basic. How do I get around this? I do apologize as I don't fully understand your response. Could you elaborate?

Thanks again
Sorry I did not elaborate on that. I am still confuse as to what type of data you are sending to your device. Binary data? is this serial data sent thru RS232? I am going to assume that when you press that momentary switch, the PIC reads that the switch was pressed and sends a string "Hello", as an example.

So you want to accomplish the same with the SitePlayer (SP). You first have to connect your pic straight to the SP pin7 (SP receive) and pin8 (SP transmit). On pin8 you MUST have a 4.7K resistor pulled down ( this is because a problem there is with the SP board, not able to pull the line completely down). That straight connection with the pic means that you are going to send and receive information from the SP in a true mode. I am going to guess that you are using a MAX232 since you were able to send data to the PC. You will no need the MAX232 to connect to the PIC, but if you do then all the data received from the Siteplayer will be inverted and you will have to account for that on your program. The good think of having a MAX232 is that you can connect to your computer as well. Since you sent some data to the SP already I am going to skip what to do so that the SP sends serially.

On the PIC side you are going to have to match the baudrate you program in the siteplayer. And you are going to have to match if TRUE or INVERTED mode is needed. So our task is to send the string "Hello", when the SP tell us to do so. Then we must come up with a way of having the SP tell us to send such command. For personal preference I always use the "ESC + a number" as my commands. ESC if you look at a ASCII table is decimal 27. So lets say that to simulate the momentary switch pressed down we are going to send a ESC + A (decimal 27, 65). So you tell the SP to send this thru the serial port when a link is presses or whatever your interface might be.

The PIC will then have a program that checks for a ESC + A (decimal 27, 65), Make sure is capital A and not a(who's ASCII value is different). How do you do that? With the Serin command

Assume: PIC receiving on PortB.1, Baudrate 9600 and no MAX232.
Include "modedefs.bas"   'Definitions used with serin and other commands


SERIN PortB.1, T9600,[27],COMMAND	' Wait until the character “ESC” is received serially on Pin1 
                                    'and put next character into COMMAND variable

If COMMAND = 65 then
 'Send binary data or as the example
 Serout PORTB.2, T9600, ["Hello"]

If COMMAND = 66 then
 'Send binary data or as the example
 Serout PORTB.2, T9600, ["Bye"]
Goto Loop

What this does is allow you for more than one command. So if you were to send a ESC + B, you could have the PIC send something else.

I hope it helps you some.

wow!!! thanks for elaborating.

I will give this a shot. One question though. Shouldn't the serin statement be:
SERIN PortB.1, T9600,[27,COMMAND]

instead of
SERIN PortB.1, T9600,[27],COMMAND

I get errors with the latter but compiles fine with the first.

Any hoo, I will give this a shot.

Thanks again.
I belive the
SERIN PortB.1, T9600,[27],COMMAND

is correct... maybe the COMMAND variable can't be used. Try changing it yo MYVAR or something else.
What this does it tells the PIC to wait for character 27 (ESC code) and once it receives it, then put the next character into the variable COMMAND. But as I said before, COMMAND could be a reserved word ;)

Everything worked.

Communication is flawless!!!!

Thanks again.

Very interesting thread. Ok Ivancho, Beefer3, I'm sold. Ordering a siteplayer dev. board tonight. I'm sure I'll be needing plenty of help from you guys.
I'll start a new thread when the time comes.
I have not played with my siteplayer for a while now :( I better find time for the stuff I really love to do.
The siteplayer works good, but not for what I wanted, I wanted to make a cheap RS232 to Ethernet adapter. It worked well when I sent commands to it from the PC thru the ethernet into the siteplayer, and then serially to the end circuit being controlled.
The problem I had was when communicating the other way around, from the circuit to the siteplayer and finnally to the PC.

The siteplayer is a "pasive" device, meaning that it waits there to receive comunications and perform, but it is not good at starting communications and all that.

Siteplayer id perfect for controlling stuff over the internet, where a PC is not available, and even if a PC is available. :)

I got a couple of links that will be very helpfull when you need them.

Not open for further replies.

Latest threads

New Articles From Microcontroller Tips