INCLUDE "MODEDEFS.BAS"
Define OSC 20 '20 meg clock`
'define PULSIN_MAX 26000 ' MAX TIME TO READ PULSE 800US added
' Define LCD connections
B2 var PORTB.2
B1 VAR PORTB.1 ' FIRE LINE OR DECODED T"0"
CNT VAR BYTE ' VARIBLE FOR COUNT OF PULSES
PLENGTH1 VAR word ' VAR FOR FREQ MEASURE OF C2 first tone
C2 var portc.2
D4 var portd.4 'input pin
plength2 var byte ' var for second freq
ffid var word ' shot #
cmnd var byte ' var for command number
gosub radio_pwr_on
main: input portb.0
input portd.4
gosub xmit_off
gosub wait_for_t0
wait_for_t0:
if portb.0= 0 then wait_for_t0 ' loop until rssi goes high
'
pulsin portd.4,1,PLENGTH1 ' MEASURE TIME C2 IS HIGH AND STORE
IF PLENGTH1 > 255 AND PLENGTH1 < 270 THEN COUNTPULSes ' 42 usec error allowed
gosub get_comnd
' made into sub routine get_cmnd
'serin2 b2,16780,1000,wait_for_t0,[WAIT ("$$"),cmnd] ' get command wait $$ timeout 1 secs added
'HSEROUT ["debug command = ",dec2 cmnd,13,10]
GOTO wait_for_t0
COUNTPULSES: COUNT portd.4,8,CNT ' COUNT PULSES FOR 10 MILISECS
IF CNT > 6 and cnt < 9 THEN DETECT2
'HSEROUT [" debug count = ",DEC3 cnt,13,10]
GOTO wait_for_t0
DETECT2:
pulsin portd.4,1,PLENGTH2 ' MEASURE PERIOD HIGH
IF PLENGTH2 > 115 AND PLENGTH2 < 130 THEN FIRE ' 20 usec error
GOTO main
FIRE: LOW B1
HIGH B1
PAUSE 10
LOW B1
ffid = ffid + 1
if ffid =65535 then ffid = 0 ' reset ffid id exceeds word size
HSEROUT ["fired ok ffid # =",dec5 ffid,13,10]
HSEROUT ["debug fired plength 1 =",DEC3 plength1,13,10]
HSEROUT ["debug fired plength 2 =",DEC3 plength2,13,10]
HSEROUT ["debug fired count = ",DEC3 cnt,13,10]
goto main
Radio_pwr_on: high portd.0
pause 10
low portd.0
pause 500 ' wait for power to come up
return
Radio_pwr_off: high portd.1
pause 10
low portd.1
return
xmit_off : high portd.2
pause 1
return
xmit_on : low portd.2
pause 50
return
get_comnd: serin2 b2,16780,1000,wait_for_t0,[WAIT ("$$"),cmnd] ' get command wait $$ timeout 1 secs added
HSEROUT ["debug command = ",dec2 cmnd,13,10]
return
command_decode: Select case cmnd
case 1 ' command #1 T0 mode
gosub xmit_on
serout2 portc.2,84,["Buoy is in fire Mode",13,10]
gosub xmit_off
gosub wait_for_t0
case 2
gosub power_on_sbc ' command #2 turn on external power to device #1 SBC power on
gosub xmit_on
serout2 portc.2,84,["SBC power is on",13,10]
gosub xmit_off
case else
return
End select
power_on_sbc: high portb.5
return
The problem is not with the serin2 command. It is the pulsin command with the addition of serin2 command. Everything was working until I added sub routine get_cmnd. The correct pulse stream is still coming in etc. It is not decoded properly at pulin command .Sorry for the mess of commented out code I have been trying everything I can think of.
thanks
Scott
Bookmarks