PDA

View Full Version : Serin to Serin2 ??



Gixxer
- 25th January 2008, 00:49
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

skimask
- 25th January 2008, 03:47
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,ou tr9,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.

skimask
- 25th January 2008, 03:48
...double post...

Archangel
- 25th January 2008, 03:56
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, . . .