Fossil
- 30th December 2003, 07:11
Hi, I am currently doing my final year project and have been having problems with the serout2 and serin2 commands. At first, I written a simple program which is when I pressed 1 button of chip A, the led on chip B will light up. It works but whenever I press it after resetting both chips, the the first press of the button will not work, it will only work on the second time.
I solved the problem by sending a blank message before starting the program. But now I seem to be stuck with the same problem again when I did a more complicated again.
DEFINE OSC 4
ADCON1=7
TRISA=%00111000
TRISB=%00000001
TRISC=%00011000
PRESS VAR BYTE
REC VAR BYTE
PORTA=$00
PORTB=$00
PORTC=$00
BEGIN: PRESS=5
SERIN2 PORTC.4,3313,[WAIT("ABC"),REC]
PAUSE 50
SEROUT2 PORTC.5,3313,["ABC",PRESS]
SEROUT2 PORTC.5,3313,["ABC",PRESS]
HIGH PORTA.0
PAUSE 250
LOW PORTA.0
READY: SERIN2 PORTC.4,3313,[WAIT("ABC"),REC]
HIGH PORTA.0
REPLY: IF PORTA.3=0 THEN
PAUSE 300
IF PORTA.3=0 THEN
PRESS=1
SEROUT2 PORTC.5,3313,["ABC",PRESS]
HIGH PORTA.2
PAUSE 100
LOW PORTA.2
LOW PORTA.0
ELSE
PRESS=2
SEROUT2 PORTC.5,3313,["ABC",PRESS]
HIGH PORTA.1
PAUSE 100
LOW PORTA.1
LOW PORTA.0
ENDIF
ELSE
GOTO REPLY
ENDIF
GOTO READY
END
DEFINE OSC 4
ADCON1=7
TRISA=%00000100
TRISB=%00000001
TRISC=%00011000
PRESS VAR BYTE
REC VAR BYTE
PORTA=$00
PORTB=$00
PORTC=$00
BEGIN: PRESS=5
PAUSE 50
SEROUT2 PORTC.5,3313,["ABC",PRESS]
SEROUT2 PORTC.5,3313,["ABC",PRESS]
SERIN2 PORTC.4,3313,[WAIT("ABC"),REC]
HIGH PORTA.0
PAUSE 250
LOW PORTA.0
READY: IF PORTA.2=0 THEN
LOW PORTA.0
LOW PORTA.1
SEROUT2 PORTC.5,3313,["ABC",PRESS]
HIGH PORTA.3
PAUSE 150
LOW PORTA.3
ELSE
GOTO READY
ENDIF
RECEIVE: SERIN2 PORTC.4,3313,[WAIT("ABC"),REC]
SELECT CASE REC
CASE 1
HIGH PORTA.0
CASE 2
HIGH PORTA.1
CASE ELSE
GOTO RECEIVE
END SELECT
GOTO READY
END
Can anyone help me with this problem?
I solved the problem by sending a blank message before starting the program. But now I seem to be stuck with the same problem again when I did a more complicated again.
DEFINE OSC 4
ADCON1=7
TRISA=%00111000
TRISB=%00000001
TRISC=%00011000
PRESS VAR BYTE
REC VAR BYTE
PORTA=$00
PORTB=$00
PORTC=$00
BEGIN: PRESS=5
SERIN2 PORTC.4,3313,[WAIT("ABC"),REC]
PAUSE 50
SEROUT2 PORTC.5,3313,["ABC",PRESS]
SEROUT2 PORTC.5,3313,["ABC",PRESS]
HIGH PORTA.0
PAUSE 250
LOW PORTA.0
READY: SERIN2 PORTC.4,3313,[WAIT("ABC"),REC]
HIGH PORTA.0
REPLY: IF PORTA.3=0 THEN
PAUSE 300
IF PORTA.3=0 THEN
PRESS=1
SEROUT2 PORTC.5,3313,["ABC",PRESS]
HIGH PORTA.2
PAUSE 100
LOW PORTA.2
LOW PORTA.0
ELSE
PRESS=2
SEROUT2 PORTC.5,3313,["ABC",PRESS]
HIGH PORTA.1
PAUSE 100
LOW PORTA.1
LOW PORTA.0
ENDIF
ELSE
GOTO REPLY
ENDIF
GOTO READY
END
DEFINE OSC 4
ADCON1=7
TRISA=%00000100
TRISB=%00000001
TRISC=%00011000
PRESS VAR BYTE
REC VAR BYTE
PORTA=$00
PORTB=$00
PORTC=$00
BEGIN: PRESS=5
PAUSE 50
SEROUT2 PORTC.5,3313,["ABC",PRESS]
SEROUT2 PORTC.5,3313,["ABC",PRESS]
SERIN2 PORTC.4,3313,[WAIT("ABC"),REC]
HIGH PORTA.0
PAUSE 250
LOW PORTA.0
READY: IF PORTA.2=0 THEN
LOW PORTA.0
LOW PORTA.1
SEROUT2 PORTC.5,3313,["ABC",PRESS]
HIGH PORTA.3
PAUSE 150
LOW PORTA.3
ELSE
GOTO READY
ENDIF
RECEIVE: SERIN2 PORTC.4,3313,[WAIT("ABC"),REC]
SELECT CASE REC
CASE 1
HIGH PORTA.0
CASE 2
HIGH PORTA.1
CASE ELSE
GOTO RECEIVE
END SELECT
GOTO READY
END
Can anyone help me with this problem?