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.

Bs2 If Serin Rs232 question

Status
Not open for further replies.

steven_first_2001

New Member
DO

Hello all! I was hoping that I could get a hand with some programming. I am trying to use a basic stamp 2, bs2 2.5, more specificily, a homework board with rs232. I am trying to interface it with a Amulet touch screen display and I am having some trouble with setting up the serin command. I am trying to do this: SERIN 16, 16468, ["hex values"] ...that is as far as I have gotten. Here is the idea; for class, we are to interface a amulet standalone touch screen to a bs2 via the rs232 port, I have gotten that far.... The bs2 is to have 3 separate songs programmed into it with some kind of loop that runs the songs as subroutines. The display is to have some sort of interface that allows you to push a button with the name of the song and thus uses a UART protocol to communicate with the bs2 to tell it to play that song. I have them "communicating" meaning that I have them set to the proper baud rates using ASCII data. I just need to know how to make a condition that if say the display sends ASCII E0 it will play one song, if it sends F0, it will play another. I guess this is all one big question that is this; how do I write an IF statement conditional to the SERIN command?

Thanks!

lOOP
 
Hi Steven;

I'm no expert at this, but am going to try and answer your question as I myself did a little RS-232 experimentation yesterday. Sorry, I can't help you with C, but the principles will be the same.

Thanks goes out to Nigel for his , again! ;)

Anyway, from what I understand, when SERIN receives a byte, it is stored in RCREG. Once the byte has been set, you can grab it and test it for what it is. IE. store it in the W reg.

Code:
    movf      RCREG, W     ; grab the character from the receive register
    movwf   temp             ; temp = W (received char)
    sublw     0xE0             ; subtract E0 from W 
    btfsc      STATUS, Z     ; is the Zero flag set?
    goto       Play_Song_1 ; yes, play song 1
    movfw   temp             ; no, put received char back in W
    sublw     0xF0             ; subtract F0 from W
    btfsc      STATUS, X     ; is the Zero flag set?
    goto       Play_Song_2 ; yes, play song 2
    goto       Somewhere  ; no, goto another loop, or back to SERIN

I'm sure the above could be written better, it was just a quick off-the-top-of-my-head code sample.

So, basically, grab the character from the receive register and test it against knowns, ignoring everything else. When a known is found, branch out and do what is required based on that known (so if E0 = song 1, play song 1, etc.).

At least that's how I'm understanding it -- and hope I have it right as I got basic serial communications working last night and wanted to do exactly what you asked about this evening! (Flash a light based on receiving a specific character, etc.). :)

Regards;
Kyle
 
I guess I should have mentioned the "IF" part of your question. Again, I am not a C guy, but I have used IF statements in other languages, which are basically the same.

In a nutshell; (this code is NOT functional -- and I don't know if the syntax is right for C -- it's simply to demonstrate.)

Code:
if (RCREG == "E0") {
   play song 1;
} elseif (RCREG == "F0") {
   play song 2;
} else {
   default, branch out or return to SERIN
}
 
Kyle-s4h - you appear to be under a number of misconceptions?.

You've posted assembler, and you've posted C - neither of which apply. A BS2 (BASIC Stamp 2) is a module including a PIC programmed with a BASIC interpreter, and an EEPROM that stores the tokenised code.

The BS2 is a VERY expensive item for what it is, and rather slow (in PIC terms), but it's simple to use, and there's a LOT of support on the net for it.
 
Head over to the **broken link removed** and ask there. :)

I have a Basic Stamp 2 on a BOE. It was the first microcontroller I bought. It very quickly got retired and replaced with 68HC11's, 68HC12's, AVR's and PIC's when I realized its limitations and low speed. I still occasionally pull it out to test the odd thing.

It's a fine learning tool though. Very simple and good easy to understand docs.
 
futz said:
when I realized its limitations and low speed.

But bear in mind the slow speed is relative to fast PIC's, in actual use it's more than fast enough for an incredible number of applications - the killing thing really is the cost! - which is where PICAXE has cleaned up!.
 
Hi Nigel;

Nigel Goodwin said:
Kyle-s4h - you appear to be under a number of misconceptions?.

You've posted assembler, and you've posted C - neither of which apply.

I believe I stated that in my first post...

Kyle-s4h said:
I'm no expert at this, but am going to try and answer your question ... the principles will be the same.

The question was how to branch based on a value read from RS-232 -- I answered that question (regardless of language).

As for "neither of which apply"... have a look at the "supposed" C code.... if you have programmed in any other language, you should recognize that as a BASIC routine, PHP, Perl and on and on. The concept is what I was trying to relay, not the language. I see posts from you where you routinely offer assembler code for someones problem, stating "I have never used C (and don't plan too)" -- I'm pretty sure it's the "concept" you are trying to relay, not the actual code.

Nigel Goodwin said:
A BS2 (BASIC Stamp 2) is a module including a PIC programmed with a BASIC interpreter, and an EEPROM that stores the tokenised code.

That I did not know -- I was more interested in the question than the product -- thanks for the information.

So far, I am the only one who even tried to answer to OP's question. ;)
 
I agree that the Parallax manuals are top notch, the IF statement should cover the three commands easy enough.
Melabs PICBASIC is BS1 compatible and they have examples on their site.

PS. I'll be doing demos of the Junebug at Creatron Inc in Toronto this Thursday between 3pm and 8pm if anyone's in the neighbourhood drop by and say hi.
 
ok, lets take a step back.... first, I found that to transmit using the actual RS232 port I must use 16 as the pin:

serout 16, baud, [yada yada]

but what is the pin labble for using the rs232 port for serin then? I have not had much luck with that.

Oh and also how do I get this to wait till it has receives a ASCII char; I am only sending data when a button is pressed. SERIN 16, 16468, [STR zr\8] I tired this but it didn't like it:
SERIN 16, 16468, [WAIT (STR zr\8)]
 
Last edited:
As already suggested, why not ask on the Parallax forums where people use these?, or read the manual? - I can remember looking at a STAMP manual back last century, and it clearly explained what you're asking.
 
I've used a BS2 ages ago, it's a prehistoric PIC16F57 so all the serial commands are done in software and you can use any pin for serial input and or output.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top