serout and serin problems with BS2 and BS2SX (again)
Hi all,
Had some problems last night in regards to networking the two stamps.
No hardware problems though. Just a programming issue. Tracy and Jon
are aware of the schematic I am using but for those of you that
aren't familiar, here it is:
| BS2-SX | | BS2 |
| | 1 kohm | |
| P1 |
/\/\/\/\
|P5 |
| | | |
| | 470 ohm 470 ohm | |
| P0 |--/\/\/\/\---0---/\/\/\/\/\---|P4 |
| | | | |
| | | | |
\
/
> \ 10 kohm
> /
> \
> |
>
> ---
> -
I have a 4-to-2 encoded user input which supplies 2 input lines to
the BS2SX. My problem is the master code executes the 2nd instruction
(to get the time) in the branch statement instead of the third (to
get the day). I can get the time from the BS2 and the day as well but
when it displays the day, the master executes the second branch
instruction instead of the third. Why is that happening? I copied and
pasted complete code for the master (the BS2SX) and partial and
relevant coding for the slave (the BS2). Any help would be
appreciated. I will perhaps put both the codes in the "files" section
for everyone's convenience.
THanks,
RP
Program for BS2SX:
'{$STAMP BS2sx}
'Display time stream from the slave upon user input
'tdata VAR byte(9)
command VAR nib
index VAR nib
hour VAR byte
minute VAR byte
dayo VAR byte
'dayh VAR nib
dayh VAR byte
day VAR word
' tdata(9) = 0
DEBUG Home, "Time code not received"
high 1
Main:
' command = ~in2 | ~in3 'any pushed button will send
a command to receive tdata
' command = 0
command = (2 * ~in3) + ~in2
SEROUT 1\0, 16624, 1000, Main, [noparse][[/noparse]DEC command]
INPUT 1
INPUT 0
IF command = 2 THEN receiveday
BRANCH command,[noparse][[/noparse]EOM,receivetime,receiveday]
receivetime:
DEBUG Home
SERIN 1\0, 16624, 1000, Main, [noparse][[/noparse]hour,minute]
' DEBUG "timedata: "
' for index = 0 to 9
' DEBUG BIN8 tdata(index), " "
' NEXT
hour = 10*hour.highnib + hour.lownib
minute = 10*minute.highnib + minute.lownib
DEBUG "time: ", DEC2 hour,":", DEC2
minute, " ", CR
GOTO EOM
receiveday:
DEBUG Home
SERIN 1\0, 16624, 1000, Main, [noparse][[/noparse]dayh, dayo]
' DEBUG "dayh: ", BIN8 dayh, "dayo: ", BIN8 dayo, CR
' DEBUG "one: ", DEC1 2*dayh.bit1+dayh.bit0, HEX2 dayo, CR
day = 100 * (2*dayh.bit1 + dayh.bit0) + 10 * dayo.highnib +
dayo.lownib
DEBUG "two: ", DEC day, " ", CR
GOTO EOM
EOM:
GOTO Main
END
Here's partial coding of the BS2:
main: 'main program
serout txpin,84,[noparse][[/noparse]$1] 'send "read time"
command
' serout txpin,240,[noparse][[/noparse]$1] 'send "read time"
command
' serout txpin,1021,[noparse][[/noparse]$1]
serin rxpin, 84, 2000, nw, [noparse][[/noparse]str tdata\8] 'read
string from M321BS
' serin rxpin, 240,[noparse][[/noparse]str tdata\8] 'read string from
M321BS
' serin rxpin,1021,[noparse][[/noparse]str tdata\8]
' serin rxpin, 240, 2000, nw, [noparse][[/noparse]str tdata\8] 'read
string from M321BS (BS2SX)
'allow 2
seconds for output to BS2SX
serin 5\4, 16468, 10, disp_t, [noparse][[/noparse]command]
' branch command, [noparse][[/noparse]disp_t, sendsx]
'sendsx: 'send data to BS2SX
' serout 5\4, 16468, 10, disp_t, [noparse][[/noparse]str tdata\8]
branch command, [noparse][[/noparse]disp_t,sendtime,sendday]
sendtime:
serout 5\4, 16468, 30, disp_t, [noparse][[/noparse]tdata(4),tdata(5)]
GOTO disp_t
sendday:
' serout 5\4, 16468, 10, disp_t, [noparse][[/noparse]tdata.nib0(4),tdata(3)]
serout 5\4, 16468, 30, disp_t, [noparse][[/noparse]tdata(2),tdata(3)]
' gosub SwitchState 'read
time zone selection
disp_t:
gosub display 'display it
goto main
Had some problems last night in regards to networking the two stamps.
No hardware problems though. Just a programming issue. Tracy and Jon
are aware of the schematic I am using but for those of you that
aren't familiar, here it is:
| BS2-SX | | BS2 |
| | 1 kohm | |
| P1 |
/\/\/\/\
|P5 |
| | | |
| | 470 ohm 470 ohm | |
| P0 |--/\/\/\/\---0---/\/\/\/\/\---|P4 |
| | | | |
| | | | |
\
/
> \ 10 kohm
> /
> \
> |
>
> ---
> -
I have a 4-to-2 encoded user input which supplies 2 input lines to
the BS2SX. My problem is the master code executes the 2nd instruction
(to get the time) in the branch statement instead of the third (to
get the day). I can get the time from the BS2 and the day as well but
when it displays the day, the master executes the second branch
instruction instead of the third. Why is that happening? I copied and
pasted complete code for the master (the BS2SX) and partial and
relevant coding for the slave (the BS2). Any help would be
appreciated. I will perhaps put both the codes in the "files" section
for everyone's convenience.
THanks,
RP
Program for BS2SX:
'{$STAMP BS2sx}
'Display time stream from the slave upon user input
'tdata VAR byte(9)
command VAR nib
index VAR nib
hour VAR byte
minute VAR byte
dayo VAR byte
'dayh VAR nib
dayh VAR byte
day VAR word
' tdata(9) = 0
DEBUG Home, "Time code not received"
high 1
Main:
' command = ~in2 | ~in3 'any pushed button will send
a command to receive tdata
' command = 0
command = (2 * ~in3) + ~in2
SEROUT 1\0, 16624, 1000, Main, [noparse][[/noparse]DEC command]
INPUT 1
INPUT 0
IF command = 2 THEN receiveday
BRANCH command,[noparse][[/noparse]EOM,receivetime,receiveday]
receivetime:
DEBUG Home
SERIN 1\0, 16624, 1000, Main, [noparse][[/noparse]hour,minute]
' DEBUG "timedata: "
' for index = 0 to 9
' DEBUG BIN8 tdata(index), " "
' NEXT
hour = 10*hour.highnib + hour.lownib
minute = 10*minute.highnib + minute.lownib
DEBUG "time: ", DEC2 hour,":", DEC2
minute, " ", CR
GOTO EOM
receiveday:
DEBUG Home
SERIN 1\0, 16624, 1000, Main, [noparse][[/noparse]dayh, dayo]
' DEBUG "dayh: ", BIN8 dayh, "dayo: ", BIN8 dayo, CR
' DEBUG "one: ", DEC1 2*dayh.bit1+dayh.bit0, HEX2 dayo, CR
day = 100 * (2*dayh.bit1 + dayh.bit0) + 10 * dayo.highnib +
dayo.lownib
DEBUG "two: ", DEC day, " ", CR
GOTO EOM
EOM:
GOTO Main
END
Here's partial coding of the BS2:
main: 'main program
serout txpin,84,[noparse][[/noparse]$1] 'send "read time"
command
' serout txpin,240,[noparse][[/noparse]$1] 'send "read time"
command
' serout txpin,1021,[noparse][[/noparse]$1]
serin rxpin, 84, 2000, nw, [noparse][[/noparse]str tdata\8] 'read
string from M321BS
' serin rxpin, 240,[noparse][[/noparse]str tdata\8] 'read string from
M321BS
' serin rxpin,1021,[noparse][[/noparse]str tdata\8]
' serin rxpin, 240, 2000, nw, [noparse][[/noparse]str tdata\8] 'read
string from M321BS (BS2SX)
'allow 2
seconds for output to BS2SX
serin 5\4, 16468, 10, disp_t, [noparse][[/noparse]command]
' branch command, [noparse][[/noparse]disp_t, sendsx]
'sendsx: 'send data to BS2SX
' serout 5\4, 16468, 10, disp_t, [noparse][[/noparse]str tdata\8]
branch command, [noparse][[/noparse]disp_t,sendtime,sendday]
sendtime:
serout 5\4, 16468, 30, disp_t, [noparse][[/noparse]tdata(4),tdata(5)]
GOTO disp_t
sendday:
' serout 5\4, 16468, 10, disp_t, [noparse][[/noparse]tdata.nib0(4),tdata(3)]
serout 5\4, 16468, 30, disp_t, [noparse][[/noparse]tdata(2),tdata(3)]
' gosub SwitchState 'read
time zone selection
disp_t:
gosub display 'display it
goto main