Shop OBEX P1 Docs P2 Docs Learn Events
SN75176 CODE FOR receiver end Basic Stamp is there a better way to write this — Parallax Forums

SN75176 CODE FOR receiver end Basic Stamp is there a better way to write this

sam_sam_samsam_sam_sam Posts: 2,286
edited 2007-06-04 21:29 in General Discussion
Hi EveryOne

This routine seem to work ok·I can turn·ON an LED LIGHT base on the Card Names

I have been working on this all day
Can any one tell if there is an better way to write this routine

' {$STAMP BS2}
' {$PBASIC 2.5}

String···· VAR···· Byte·········· 'VAR space for data

scan:
PAUSE 500
DEBUG CLS, CLS
DO
LOW 1··························· '· low=listen For the SN75176 chip
SERIN 0, 16468, [noparse][[/noparse]string]········ '· SEROUT For the SN75176 chip
DEBUG string
LOOP UNTIL string· =· ("0")····· ' valid Names that are SENT which·end with ("0") [noparse][[/noparse]"Sam 0"] sending end Basic Stamp


IF string <> "s" AND "a" AND "m" THEN
GOTO Sound
ELSEIF string <> "M" AND "O" AND "m" THEN
GOTO Sound
ELSEIF string <> "D" AND "E" AND "b" AND "r" AND "a"· AND "C" THEN
GOTO Sound
ELSEIF string <> "S" AND "a" AND "m" AND "C" AND "a" AND "r" THEN
GOTO Sound
ELSEIF string <> "D" AND "a" AND "v" AND "i" AND "d" AND "C" THEN
GOTO Sound
ELSEIF string <> "K" AND "e" AND "n" AND "C" AND "a" AND "r" THEN
GOTO Sound
ELSEIF string <> "D" AND "E" AND "b" AND "r" AND "a"· AND "N" THEN
GOTO Sound
·ELSEIF string <> "T" AND "r" AND "u" AND "c" AND "k" THEN
GOTO Sound
ELSEIF string <>· "D" AND "E" AND "b" AND "r" AND "a"· AND "K" THEN
GOTO Sound
ELSEIF string <>· "S" AND "a" AND "m" AND "K" AND "e" AND "y" THEN
GOTO Sound
ELSEIF string <>· "S" AND "p" AND "a" AND "r" AND "e" AND "1" THEN
GOTO Sound
ELSEIF string <>·· "S" AND "p" AND "a" AND "r" AND "e" AND "2" THEN
GOTO Sound
ENDIF

Sound:
HIGH 15
PAUSE 4000
LOW 15
GOTO scan


Thanks to Any One that can Help with this routine


The Code Routine for SEND is not done yet i will work on this latter is in the Attachment below
·

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·idea.gif·that you may have and all of your time finding them

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 6/2/2007 9:32:32 PM GMT

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-06-02 23:13
    You don't need all of those ANDs.
    You should be able to get by with --
    IF string <> [color=red]"s[/color][color=red]a[/color][color=red]m"[/color] THEN
    GOTO Sound
    ELSEIF string <> [color=red]"M[/color][color=red]O[/color][color=red]m"[/color] THEN
    GOTO Sound
    ELSEIF string <> [color=red]"D[/color][color=red]E[/color][color=red]b[/color][color=red]r[/color][color=red]a[/color][color=red]C"[/color] THEN
    GOTO Sound
    ELSEIF string <> [color=red]"S[/color][color=red]a[/color][color=red]m[/color][color=red]C[/color][color=red]a[/color][color=red]r"[/color] THEN
    GOTO Sound
    ELSEIF string <> [color=red]"D[/color][color=red]a[/color][color=red]v[/color][color=red]i[/color][color=red]d[/color][color=red]C"[/color] THEN
    GOTO Sound
     
    [color=black]...and so on[/color]
    
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-06-03 14:59
    PJ,

    There is no string support on the BASIC Stamps. Everything must be dealt with in a byte-by-byte manner.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-06-03 17:06
    I made an interface to link the controller at one intersection with the signals at another, using a BS-1 at the transmitter side and a BS-1 at the receiver side, and it was darned effective.· (It's still there and working, I am not.)· It replaced a few wires between the intersections that actuated AC-controlled relays when a/their conduit was dug up.

    The Transmitter's Program --
    ' INs: P0 = ST P1 = 3G, P2 = 8G
    ' OUTs: P4 = SEROUT, P5 = RTS    'P4 & P5 go into MAX232/233
    DIRS = $F0                       'P0-3 = IN, P4-7 = OUT
    PINS = %00000000
    Begin:
      IF PIN0 = 1 THEN NoGrn         'StopTime is On OR neither 3 nor 8 are Green
      IF PIN1 = 1 THEN Phs3G         'Phase 3 = Green
      IF PIN2 = 1 THEN Phs8G         'Phase 8 = Green
      GOTO NoGrn
     
    NoGrn:
      PIN5 = 0                       'RTS on
      SEROUT 4,T1200,("Phase0 ")
      PIN5 = 1                       'RTS off
      PAUSE 200
      GOTO Begin
     
    Phs3G:
      PIN5 = 0                       'RTS on
      SEROUT 4,T1200,("Phase3 ")
      PIN5 = 1                       'RTS off
      PAUSE 200
      GOTO Begin
     
    Phs8G:
      PIN5 = 0                       'RTS on
      SEROUT 4,T1200,("Phase8 ")
      PIN5 = 1                       'RTS off
      PAUSE 200
      GOTO Begin
    


    The Receiver's Program --

    '  INs: P4 = SERIN
    ' OUTs: P0 = Phs3 G LED, P1= Phs8 G LED, P2 = TRG '123
    SYMBOL ST = B0
    DIRS = $0F                       'P0-3 = OUT, P4-7 = IN
    PINS = %00000000
    ST = 0
     
    Listen:                          
      SERIN 4,T1200,("Phase"), #ST   'Always Listening, #ST determines GOTO
      IF ST = 3 THEN Phs3G           '3 = Green
      IF ST = 8 THEN Phs8G           '8 = Green
      GOTO Neither
     
    Phs3G:
      PIN0 = 1                      'Status1 LED on
      PIN1 = 0
      PULSOUT 2,10                  'TRG '123
      GOTO Listen
     
    Phs8G:
      PIN0 = 0
      PIN1 = 1                      'Status2 LED on
      PULSOUT 2,10                  'TRG '123
      GOTO Listen
     
    Neither:
      PIN0 = 0
      PIN1 = 0
      GOTO Listen
    


    So, perhaps, sam_sam_sam, you could take a similar tack, as there is "no string support on the BASIC stamps."·

    BS-1's don't exactly·have WAIT.· If you're using a BS2, then you could use WAIT and devise your own·moniker (my term, where I used "Phase") followed by an ID character for each card, instead.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2007-06-04 00:27
    PJ Allen


    Thanks for your reply in this matter

    But from what Chris· is saying i seem to have it writen the best way if i am going to use the SN75176 chip

    I will have to look· into how much a set of MAX232/233 Chip are and if they do not cost alot then i may try what
    you have writen here in this post

    Thanks again for your input in this matter



    Thank you Chris for·pointing out·why was having so much trouble writing this routine not knowing that

    Chris

    Everything must be dealt with in a byte-by-byte manner.

    Chris will it be easyer to use··MAX232/233 to do what i want to do then the SN75176

    I want to have the Names of the Cards to be on the receiver end·the·one at the House because i going·to use a

    LCD Display to·show the Name of the Person at the Gate·and for each person to have a·different TONEs that the Basic

    Stamp dose that is why i need to not only show name but·be able to do·some different things with each one

    Thanks Chirs and PJ Allen for all of your help

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 6/4/2007 1:26:18 AM GMT
  • PARPAR Posts: 285
    edited 2007-06-04 01:22
    sam_sam_sam said...
    ...
    ·This routine seem to work ok·I can turn·ON an LED LIGHT base on the Card Names

    ...

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    String···· VAR···· Byte·········· 'VAR space for data

    scan:
    PAUSE 500
    DEBUG CLS, CLS
    DO
    LOW 1··························· '· low=listen For the SN75176 chip
    SERIN 0, 16468, [noparse][[/noparse]string]········ '· SEROUT For the SN75176 chip
    DEBUG string
    LOOP UNTIL string· =· ("0")····· ' valid Names that are SENT which·end with ("0") [noparse][[/noparse]"Sam 0"] sending end Basic Stamp


    IF string <> "s" AND "a" AND "m" THEN
    GOTO Sound
    ELSEIF string <> "M" AND "O" AND "m" THEN
    GOTO Sound
    ELSEIF string <> "D" AND "E" AND "b" AND "r" AND "a"· AND "C" THEN
    GOTO Sound
    ELSEIF string <> "S" AND "a" AND "m" AND "C" AND "a" AND "r" THEN
    GOTO Sound
    ELSEIF string <> "D" AND "a" AND "v" AND "i" AND "d" AND "C" THEN
    GOTO Sound
    ELSEIF string <> "K" AND "e" AND "n" AND "C" AND "a" AND "r" THEN
    GOTO Sound
    ELSEIF string <> "D" AND "E" AND "b" AND "r" AND "a"· AND "N" THEN
    GOTO Sound
    ·ELSEIF string <> "T" AND "r" AND "u" AND "c" AND "k" THEN
    GOTO Sound
    ELSEIF string <>· "D" AND "E" AND "b" AND "r" AND "a"· AND "K" THEN
    GOTO Sound
    ELSEIF string <>· "S" AND "a" AND "m" AND "K" AND "e" AND "y" THEN
    GOTO Sound
    ELSEIF string <>· "S" AND "p" AND "a" AND "r" AND "e" AND "1" THEN
    GOTO Sound
    ELSEIF string <>·· "S" AND "p" AND "a" AND "r" AND "e" AND "2" THEN
    GOTO Sound
    ENDIF

    Sound:
    HIGH 15
    PAUSE 4000
    LOW 15
    GOTO scan
    ...
    I don't understand how this program is supposed to work· ("...seems to work ok...").

    "string" is a byte-sized variable.

    In the IF/THEN statements, "string", a single byte,··is being compared "not equal" (<>) to what?
    Isn't the Do/Loop cycling through input characters (bytes) until a "0" is received, and then continuing on to the IF/THEN section of code, with "string" set to "0"? (And, is it a numeric 0 [noparse][[/noparse]zero] or the character zero "0" that is terminating the input?)

    I.e., how do the multiple-characters (bytes), e.g., "s", "a", "m", ·get compared, each and every one, to "string" (a byte) in this AND-ing fashion?

    What am I missing here about PBasic syntax? How do the above program statements work "byte by byte"? Was there some previous thread that contains the context for this project?

    PAR

    Post Edited (PAR) : 6/4/2007 1:28:58 AM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2007-06-04 01:48
    Par

    I don't understand how this program is supposed to work "...seems to work ok...").
    ·
    "string" is a byte-sized variable.
    ·
    In the IF/THEN statements, "string", a single byte,··is being compared "not equal" (<>) to what?
    That part i am not sure of ether


    Isn't the Do/Loop cycling through input characters (bytes) until a "0" is received Yes
    , and then continuing on to the IF/THEN section of code, with "string" set to "0"?

    (And, is it a numeric 0 [noparse][[/noparse]zero] or the character zero "0" I do not Know if this is the case or not·that is terminating the input?)
    ·
    I.e., how do the multiple-characters (bytes), e.g., "s", "a", "m", ·get compared, each and every one, to "string" (a byte) in this AND-ing fashion?

    When the sam That is the IF statement = [noparse][[/noparse]"S" AND·"a" AND "m"] Then it Flashs the Led

    The [noparse][[/noparse]"0"] is only use for the DO LOOP I only want it to something if the [noparse][[/noparse]"0"]· is at the end of the String that is being sent
    ·
    What am I missing here about PBasic syntax? How do the above program statements work "byte by byte"?
    Yes from what Chris said in the POST above

    · PAR

    Thank You for Your reply

    What i found out is that you can not send all of the characters··At one time· [noparse][[/noparse]"Sam"]·
    That is why this was used [noparse][[/noparse]"S" AND·"a" AND "m" AND "0"] = It is a numeric 0 [noparse][[/noparse]zero]

    Now if some one can Tell me·an easyer way to do this i am very open to this but i need to be able to control By card Names

    You would only ·receive·two characters and could not control any thing with it
    The Demo code for the SN75176 Chip·only sent one character to control an Led
    So that is how i came up with this routine
    That why i put the "0" at the END of what i want to send from one Stamp to the Other Stamp

    Was there some previous thread that contains the context for this project?
    ·
    The Reason I am using this Chip is that in other POST i ask adout talking from one Stamp to onther Stamp That was about 300 feet apart




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 6/4/2007 2:10:06 AM GMT
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-06-04 01:49
    sam_sam_sam --

    MAX232/RS232 isn't required.· Whether the data exchange is·by RS232, or RS422, or some other means is a side issue.··They're just means to an end.· What matters is the SERIN/SEROUT concept/s.

    With the 75176: DE (75176 pin 3) must be HI during Transmit [noparse][[/noparse]note·the use of RTS in my example]; /RE (75176 pin 2) and DE (75176 pin3) must be LO to Receive.

    Update -- You seem stuck in your "names" approach, so I'll leave it at that.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2007-06-04 02:20
    PJ Allen
    Thank You For Your Reply

    I may drop the Name sending and just use one Letter and have the Name: in the routine
    I·just want to see if i could get it to work or not this way if not then i will have to·rethink how i am going to do these
    Routines

    ·Thanks for your ·idea.gifs that helps alot· smile.gifs

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • PARPAR Posts: 285
    edited 2007-06-04 03:58
    sam_sam_sam said...
    Par
    ·...
    ·In the IF/THEN statements, "string", a single byte,··is being compared "not equal" (<>) to what?
    That part i am not sure of ether
    ·...·
    I.e., how do the multiple-characters (bytes), e.g., "s", "a", "m", ·get compared, each and every one, to "string" (a byte) in this AND-ing fashion?

    When the sam That is the IF statement = [noparse][[/noparse]"S" AND·"a" AND "m"] Then it Flashs the Led
    ·...
    I don't think that is what the IF statement is doing. The variable "string" is never going to contain the character strings "sam" nor "DebraC" nor ... nor "spare2". It is always going to contain only one byte of information --the terminating character (the one that got you out of the Do/Loop).

    You are not testing for what you think you are. And, your are always going to end up at the "Sound:" portion of your program and to raise pin 15 high for 4 seconds (regardless of whether any of the conditions of your IF statement are TRUE or FALSE).

    PAR
    ·
  • kjennejohnkjennejohn Posts: 171
    edited 2007-06-04 07:06
    Hi.
    You want to use the 75176 because it can communicate over several hundred feet of wire, while RS232 is typically only good out to 25 feet. Just be sure to PJ Allen's directions on the DE and /RE pins.

    'Luck on your project!
    kenjj
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2007-06-04 15:31
    kjennejohn

    Thank You For Your Reply

    I am going to try PJ Allen's· idea.gif·and see how well this will work for what i am
    trying to do




    .......................................smile.gif............................................................

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2007-06-04 21:29
    PAR

    All i can tell you is that what ever card that i tried i got the card name·in the DEBUG window when the card was scaned

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
Sign In or Register to comment.