View Full Version : help with SERIN & SEROUT
navaismo
- 14th September 2005, 19:48
hello my name is Max I`m from Mexico
I have a problem; Im building a remote control using RF with modulation ASK, at the beginning I try to turn on and turn off a led. and Iam using the pic 16f84a. To turn on the led i used a switch and the command serout example:
if sw1=1 then
serout datout,N2400,{5}
end
to turn off i used another switch an the command serout
if sw2=1 then
serout datout, N2400,{8}
endif
the first test works very good even a 50mts of distance.
But my problem is here: I try to turn on and turn off with the same switch but i cant do this, why? i have some theory about.
when i use a one SW only have 2 (obvius)on/off, when is off the serout send the data again and again and when the SW do the same. the RX recieve the data time and time again with this the program behaves very rare.
how i can to do the tx send only one time the code, even the sw still on or off during anytime?
the rx: code is like this
rx:
serin datin, N2400,dato
if dato =5 then
high led
endif
if dato=8 then
low led
endif
I was reading the command serin is able to compare the entrance variables, but i dont know how
please any have an idea??? help me
P.S. my english is too bad sorry i hope you understand my problem
mister_e
- 14th September 2005, 20:03
Even it could be much than what you think, can you try that one and post resukt
Oldata var byte
Dato var byte
dato=0
oldata=1
rx:
serin datin, N2400,[dato]
if dato != Oldata then
if dato =5 then
high led
oldata-dato
endif
if dato=8 then
low led
oldata=dato
endif
endif
But you may/must need a synchro data, then receive the function you want to do. Lookj for the WAIT modifier.
A common protocol is Manchester, do a search within this forum you'll find the theory. But as you want to receive only 1 or few bytes, send some preamble data (like $aa, $55), then send a Synchro by, then your data). The receiver must wait the synchro, then get the data.
navaismo
- 14th September 2005, 22:46
thank you.
I will test with your code or similar, but i dont understand the syncrho data. the transmitter and recivier works with asyncronous data too.
mister_e
- 15th September 2005, 02:10
SEROUT SerPin,BAUD,["UUUUUSYNCHRO",YourByte]
RECEIVER SIDE
SERIN2 SerPin,BAUD,[WAIT ("SYNCHRO"),YourByte]
Or a variant of it.
navaismo
- 16th September 2005, 17:45
well, i tested the first program and doestn works, then I use a LCD (16X2) for view the variable in the Reciever, the lcd show me the number and show me how works my program and i can view that my program is wrong because the data is send time and time again, and before a while the data changes. I mean first put p.e.: 0,0,0,0,0,3,3,3,0,0,0,0 during the switch is off an suposed the lcd put only zeros. and "viceversa"
Then i try to fix the problem but now i doesnt pass anything, i cant recieve or i cant transmitt, i testes the pics and works perfectly, I thought that modules RF had been disturbed, And I connected pics directly and even so it does not pass anything, then I believe that it is my program and at this point already my mind is blocked some help?
here the two codes: (when it worked )
transmitter code:'TX CODIGO TRANSMISOR
INCLUDE "modedefs.bas"
TRISA=6
DATOUT VAR PORTA.0
ONN VAR PORTA.1
OF1 VAR PORTA.2
C VAR BYTE
TX:
IF OF1=1 THEN
C=2
ENDIF
IF ONN=1 THEN
C=5
ENDIF
IF C=2 THEN
SEROUT DATOUT,N1200,[0]
ENDIF
IF C=5 THEN
SEROUT DATOUT,N1200,[7]
ENDIF
GOTO TX
reciever code:'RX CODIGO RECEPTOR
INCLUDE "modedefs.bas"
TRISB=1
DATAIN VAR PORTB.0
LEDVER VAR PORTB.1
DATO VAR WORDS
RX:
SERIN DATAIN,N1200,DATO
IF DATO=0 THEN
LOW LEDVER
ENDIF
IF DATO=7 THEN
HIGH LEDVER
ENDIF
goto rx
navaismo
- 17th September 2005, 01:49
Hola, mi cabeza ya de plano tiene muchos golpes, como volví hacer todo, hagamos de cuenta que no uso los modulos rf, ahora solo comunico los pics con un cable directamente, pero no me sale nada. se supone que con un switch mando un dato para prender un led y si esta cerrado mando otro para apagarlo y no lo hace. ya revise los pics y si funcionan, ya me canse de cambiar el programa y nada la verdad ya no se que hacer. les juro que ya me duele la cabeza de estar piense y piense y nada mas no me queda. he hecho otros programas pero este en particular como me ha dado dolores de cabeza
alguna ayuda aqui los codigos:
'TX CODIGO TRANSMISOR
INCLUDE "MODEDEFS.BAS"
TRISA=1
BOTON VAR PORTA.0
VIATX VAR PORTA.1
LEDVE VAR PORTA.2
LEDRO VAR PORTA.3
pause 500
TX:
IF BOTON=1 THEN
GOSUB SEND1
ENDIF
IF BOTON=0 THEN
GOSUB SEND2
ENDIF
GOTO TX
SEND1:
SEROUT VIATX,N9600,[7]
LOW LEDRO
HIGH LEDVE
RETURN
SEND2:
SEROUT VIATX,N9600,[0]
LOW LEDVE
HIGH LEDRO
RETURN
.............................................
' RX CODIGO RECEPTOR
INCLUDE "MODEDEFS.BAS"
TRISB=1
VIARX VAR PORTB.0
LEDRO VAR PORTB.1
LEDVE VAR PORTB.2
DATO VAR BYTE
RX:
SERIN VIARX,N9600,DATO
IF DATO=0 THEN
HIGH LEDVE
LOW LEDRO
ENDIF
IF DATO=7 THEN
LOW LEDVE
HIGH LEDRO
ENDIF
GOTO RX:
.......................................
ya no puedo mas estoy frito alguna ayuda porfavor
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.