Serin to Serin2 ??


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2007
    Location
    Toronto, Ontario
    Posts
    23

    Default Serin to Serin2 ??

    Hello,

    I have a simple serial relay controller setup using two pics, one for the transmitter and one for the receiver. Using the "serout2" command I can send control data to the RX. The RX code was written using the "serin" command. I have tried but to no avail, here is the original code, how do I convert this code to allow "serin2" to be used along with modes..ie 396 for t2400.
    PAUSE 100
    INCLUDE "bs2defs.bas"


    relay VAR b3 'relay number storage variable
    stat VAR b4 'relay status ON/OFF variable
    trisa = %00010000
    trisb = %00000000

    loop:

    SERIN porta.4,t2400,[254],relay,stat 'serial data in on PortA.4
    IF relay = 1 THEN outr1 ' if request is for relay#1 then goto relay#1 routine
    IF relay = 2 THEN outr2 ' if request is for relay#2 then goto relay#2 routine
    IF relay = 3 THEN outr3 ' if request is for relay#3 then goto relay#3 routine
    IF relay = 4 THEN outr4 ' if request is for relay#4 then goto relay#4 routine
    IF relay = 5 THEN outr5
    IF relay = 6 THEN outr6
    IF relay = 7 THEN outr7
    IF relay = 8 THEN outr8
    IF relay = 9 THEN outr9
    IF relay = 10 THEN outr10
    IF relay = 11 THEN outr11
    IF relay = 12 THEN outr12

    GOTO loop

    outr1:
    IF stat = 1 THEN high1 ' If status request is I/O pin#0 logic 1 [high]
    LOW 0: GOTO loop ' then make I/O pin#0 high, else make it [low]

    high1:
    HIGH 0: GOTO loop ' Make I/O pin#0 logic 1 [high]

    outr2:
    IF stat = 1 THEN high2
    LOW 1: GOTO loop

    high2:
    HIGH 1: GOTO loop

    outr3:
    IF stat = 1 THEN high3
    LOW 2: GOTO loop

    high3:
    HIGH 2: GOTO loop

    outr4:
    IF stat = 1 THEN high4
    LOW 3: GOTO loop

    high4:
    HIGH 3: GOTO loop

    outr5:
    IF stat = 1 THEN high5
    LOW 4: GOTO loop

    high5:
    HIGH 4: GOTO loop

    outr6:
    IF stat = 1 THEN high6
    LOW 5: GOTO loop

    high6:
    HIGH 5: GOTO loop

    outr7:
    IF stat = 1 THEN high7
    LOW 6: GOTO loop

    high7:
    HIGH 6: GOTO loop

    outr8:
    IF stat = 1 THEN high8
    LOW 7: GOTO loop

    high8:
    HIGH 7: GOTO loop

    outr9:
    IF stat = 1 THEN high9
    porta.0 = 0: GOTO loop

    high9:
    porta.0 = 1: GOTO loop

    outr10:
    IF stat = 1 THEN high10
    porta.1 = 0: GOTO loop

    high10:
    porta.1 = 1: GOTO loop

    outr11:
    IF stat = 1 THEN high11
    porta.2 = 0: GOTO loop

    high11:
    porta.2 = 1: GOTO loop

    outr12:
    IF stat = 1 THEN high12
    porta.3 = 0: GOTO loop

    high12:
    porta.3 = 1: GOTO loop

    thanks alot
    John

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Code:
    INCLUDE "bs2defs.bas"
    relay var portb.3 '<-----?????? Relay VAR b3 'relay number storage variable
    stat var portb.4 '<------??????stat VAR b4 'relay status ON/OFF variable
    trisa = $10 : trisb = 0 : PAUSE 100
    loop:     SERIN porta.4,396,[ WAIT [254],relay,stat]      'serial data in on PortA.4
    '--note for line above...Is porta.4 an optional analog port?  Are the correct ADCON bits set?
    '---depends on the PIC you're using....which we don't know, in this case, they're not.....
    branch relay,[outr1,outr2,outr3,outr4,outr5,outr6,outr7,outr8,outr9,outr10,outr11,outr12]
    GOTO loop
    outr1:    if stat = 1 then
    high 0
    else
    low 0
    endif
    goto loop
    
    outr2:    IF stat = 1 THEN
    high 1
    else
    low 1
    endif
    goto loop
    
    outr3:    IF stat = 1 THEN
    high 2
    else
    low 2
    endif
    GOTO loop
    
    outr4:    if stat = 1 then
    high 3
    else
    low 3
    endif
    goto loop
    
    outr5:    IF stat = 1 THEN
    high 4
    else
    low 4
    endif
    goto loop
    
    outr6:    if stat = 1 then
    high 5
    else
    low 5
    endif
    goto loop
    
    outr7:    if stat = 1 then
    high 6
    else
    low 6
    endif
    goto loop
    
    outr8:    if stat = 1 then
    high 7
    else
    low 7
    endif
    goto loop
    
    outr9:    if stat = 1 then
    porta.0 = 1
    else
    porta.0 = 0
    endif
    goto loop
    
    outr10:    if stat = 1 then
    porta.1 = 1
    else
    porta.1 = 0
    endif
    goto loop
    
    outr11:    if stat = 1 then
    porta.2 = 1
    else
    porta.2 = 0
    endif
    goto loop
    
    outr12:    if stat = 1 then
    porta.3 = 1
    else
    porta.3 = 0
    endif
    goto loop
    
    end
    Like I said in the code above, if your ADCON and/or ANSEL bits aren't set right, chances are anything you try to do digitally with an analog capable pin won't work right.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    ...double post...
    Last edited by skimask; - 25th January 2008 at 03:49. Reason: removed

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


    Did you find this post helpful? Yes | No

    Default

    Hi Gixxer,
    To get more help you have to give a little more . . . Which PIC are you using?
    Because as Skimask pointed out, you need to disable the analog stuff on pins you are trying to use as digital , and PICs have different ways of doing that based upon their number.
    oh, I do not what you are getting from include bs2defs.bas, statement, but to use serin porta.4,t2400, . . . use include "modedefs.bas"
    otherwise use serin porta.4,1, . . .
    Last edited by Archangel; - 25th January 2008 at 04:06. Reason: Add something
    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.

Similar Threads

  1. Serin vs Serin2
    By The Master in forum mel PIC BASIC
    Replies: 12
    Last Post: - 19th October 2007, 16:50
  2. serin and serin2??? need to understand
    By tkly36 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th April 2006, 05:13
  3. Serin / Serin2 / Debugin Differences
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 19th January 2006, 06:32
  4. SERIN SERIN2 Timeout
    By markedwards in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 23rd June 2005, 18:59
  5. serin and serin2
    By rastan in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 3rd January 2005, 13:10

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