How to receive and analyze text via SERIN ?


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default How to receive and analyze text via SERIN ?

    Hello.

    I want to receive text via SERIN and do actions based on it. Like in exampole below

    Code:
    CIKLI:
    Serin SHESVLA,N2400,MONACEMI    'READ INTO VARIABLE
    if monacemi="X" then 
    CCP1CON = %00000000 
    goto cikli
    this works fine, while "X" is single character, when I'd like to make it say "hamex", the code does not works.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: How to receive and analyze text via SERIN ?

    Quote Originally Posted by CuriousOne View Post


    this works fine, while "X" is single character, when I'd like to make it say "hamex", the code does not works.
    Just from WAG, HAMEX is a string, so I "think" you would need to read it into an array and test the array for the value of each letter.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191


    Did you find this post helpful? Yes | No

    Default Re: How to receive and analyze text via SERIN ?

    Couple of years ago I had a similar problem/question.
    See this post. It might help you.

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: How to receive and analyze text via SERIN ?

    Ok, this works, setup for a 16F690 demo board
    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF  
    DEFINE OSC 4
    
    DEFINE DEBUG_MODE  0    ' Debug sending True serial data
    DEFINE DEBUG_REG_PORTA  ' Debug Port = PortA as required by PICKIT2 serial Monitor
    DEFINE DEBUG_BIT 0      ' Debug.bit = PortA.0
    DEFINE DEBUG_BAUD 9600  ' Default baud rate = 9600
    DEFINE DEBUGIN_REG PORTA' Debug Port = PortA as required by PICKIT2 serial Monitor 
    DEFINE DEBUGIN_BIT 1    ' Debugin bit PortA.1
    DEFINE DEBUGIN_BAUD 9600' Default baud rate = 9600
    DEFINE DEBUGIN_MODE 0   ' Debugin receiving data true = 0 inverted = 1
    
    ANSEL=0
    ANSELH=0
    ADCON0 = 0
    ADCON1 = 0
    ;CCP1CON = %10001100 ;Dual PWM 10xx11xx P1A/RC5 P1B/RC4 RC3/AN7 RC2/AN6
    TRISA = %00000010           
    TRISB = %00000000           
                
    portC = 0
    TrisC = %00000000
    tank var byte[5]
    tank = 0
    
    
    
    main:
    debugin[str tank\5]
    PAUSE 30
    
    if (tank[0] = "H") AND (tank[1] = "A") AND (tank[2] = "M") AND (tank[3] = "E") AND (tank[4] = "X")THEN
    gosub flash
    
    debug " tank"," ",str tank\5
    else
    
    
                            
    
    debug " FAIL"
    endif
    
    
    goto main
    
    flash:
    portc.0 = 1
    pause 500
    portc.0 = 0
    pause 500
    return
    
    
    
    end
    If HAMEX is sent it flashes the led on portc.0, if anything else, is sent it responds with FAIL
    Last edited by Archangel; - 18th July 2014 at 19:07. Reason: else in text
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: How to receive and analyze text via SERIN ?

    Wow, thank you very much!

  6. #6
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: How to receive and analyze text via SERIN ?

    Here is a very good example of how to compare strings. The comparisons are done in Check_List.

    Quote Originally Posted by dan-tron View Post
    EUREKA!
    Thanks guys! You have been a huge help. I have finally figured it out.
    My problem was more like 3 problems...

    1. I have never done EEPROM stuff before so I was lost to begin with.
    2. As Bruce pointed out, the mathematical order of operations in one line was not correct. I guess the BS2 thinks a little differently from PBP in that respect.
    3. My PicBasic Pro compiler was Version 2.30 form 2000. It seems that v2.30 supports the PIC 16F628 but the PIC 16F628A was implemented in a later version. I have upgraded my PBP to version 2.47 and now the EEPROM features work correctly on the 16F628A. When I successfully tested a 16F84A using the same code, that lead me to question the compiler.

    So for future generations and the benefit of other people like me, here's my WORKING code that is tested successfully on a PIC 16F628A with a 20MHz resonator compiled using PBP v2.47. It reads data from the Parallax RFID Reader Module, compares it against known values stored in EEPROM and allows or denies access accordingly. Enjoy.

    Code:
    CMCON = 7   
    DEFINE OSC 20	'Set oscillator in MHz
    
    ' -----[ Variables ]-------------------------------------------------------
    
    buf	VAR	Byte(10)	' RFID bytes buffer
    tagNum	VAR	Byte	' from EEPROM table
    idx	VAR	Byte	' tag byte index
    char	VAR	Byte	' character from table
    
    ' -----[ EEPROM Data ]-----------------------------------------------------
    
    Tag1	DATA	"100050A4B7"
    Tag2	DATA	"1000508E0A"
    Tag3	DATA	"10005091DC"
    Tag4	DATA	"100050203A"
    Tag5	DATA	"100050DA36"
    
    ' -----[ Initialization ]--------------------------------------------------
    
    HIGH portb.3	' turn off RFID reader
    LOW portb.6	' lock the door!
    Low portb.4	'Turn off LED
    
    ' -----[ Program Code ]----------------------------------------------------
    
    Main:
    
    LOW portb.3				' activate the reader
    SERIN2 portb.2, 396, [WAIT($0A), STR buf\10]	' wait for hdr + ID
    HIGH portb.3				' deactivate reader
    
    Check_List:
      FOR tagNum = 1 to 5			' scan through known tags
        FOR idx = 0 TO 9				' scan bytes in tag
        READ (((tagNum-1) * 10) + idx), char		' get tag data from table
        IF (char <> buf(idx)) THEN Bad_Char		' compare tag to table
        NEXT
        GOTO Tag_Found				' all bytes match!
    Bad_Char:					' try next tag
      NEXT
    
    Bad_Tag:
      tagNum = 0
      FREQOUT portb.5, 1000 */ $100, 115 */ $100	' groan
      PAUSE 1000
      GOTO Main
    
    Tag_Found:
      HIGH portb.6				' remove latch
      High portb.4				' Light LED
      FREQOUT portb.5, 2000 */ $100, 880 */$100	' beep
      LOW portb.6				' restore latch
      Low portb.4				' LED OFF
      GOTO Main

Similar Threads

  1. DMX receive issue
    By NoahLD in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th August 2014, 14:51
  2. How to prepare text (lots of text) for HSEROUT ?
    By Byte_Butcher in forum General
    Replies: 0
    Last Post: - 15th February 2010, 23:31
  3. Best way to receive RF bits
    By ruijc in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st November 2008, 00:55
  4. receiver can not receive signal
    By nicolelawsc in forum Schematics
    Replies: 1
    Last Post: - 19th May 2006, 09:01
  5. Replies: 4
    Last Post: - 7th September 2005, 15:11

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts