win_832001
- 7th April 2006, 10:18
i need a help here..i have a project that require serial program.the input is from visual basic. so i guess i have to use SERIN command. but then my project has to use as a switch.so,after that there is not require a input from serial but the input is from the switch as a input sensor.i give the program condition IF to run the program. but the program has do not working like that i want.need help please...
the program should working as above :
1)initially red LED flashed
2)after vb send =1 and IRswitch=0 (servo pen and green LEd flashed)
3)after IRswitch =1 (servo close and green LED-->RED led)- do not require serial input.
the program that i wrote :
INCLUDE "modedefs.bas"
DEFINE OSC 4
GreenLED VAR PORTB.4
RedLED VAR PORTB.5
SerialIn VAR PORTA.4 'serial programming
IRSwitch VAR PORTB.1 'sensor
PinState VAR BYTE
val VAR WORD
Main:
val = 0
SerIn SerialIn,4,[255],PinState
High GreenLED 'start condition
Low RedLED 'start condition
IF PinState=1 AND IRSwitch= 0 Then OpenGate 'when the vb send '1' and the sensor is = 0 (this part working)
IF IRSwitch =1 Then
Pause 1000
GoSub CloseGate 'when the sensor =1 (this part is not working)
EndIF
GoSub Main
OpenGate
Pause 1000
Low GreenLED
High RedLED
val=0
For val=0 TO 80 'servo rotation (working)
PulsOut PORTB.3,150
Pause 20
Next val
GoSub Main
CloseGate
Pause 1000
High GreenLED
Low RedLED
For val=0 TO 80 'servo rotation (not working)
PulsOut PORTB.3,50
Pause 20
Next val
GoSub Main
-need help here please.TQ
the program should working as above :
1)initially red LED flashed
2)after vb send =1 and IRswitch=0 (servo pen and green LEd flashed)
3)after IRswitch =1 (servo close and green LED-->RED led)- do not require serial input.
the program that i wrote :
INCLUDE "modedefs.bas"
DEFINE OSC 4
GreenLED VAR PORTB.4
RedLED VAR PORTB.5
SerialIn VAR PORTA.4 'serial programming
IRSwitch VAR PORTB.1 'sensor
PinState VAR BYTE
val VAR WORD
Main:
val = 0
SerIn SerialIn,4,[255],PinState
High GreenLED 'start condition
Low RedLED 'start condition
IF PinState=1 AND IRSwitch= 0 Then OpenGate 'when the vb send '1' and the sensor is = 0 (this part working)
IF IRSwitch =1 Then
Pause 1000
GoSub CloseGate 'when the sensor =1 (this part is not working)
EndIF
GoSub Main
OpenGate
Pause 1000
Low GreenLED
High RedLED
val=0
For val=0 TO 80 'servo rotation (working)
PulsOut PORTB.3,150
Pause 20
Next val
GoSub Main
CloseGate
Pause 1000
High GreenLED
Low RedLED
For val=0 TO 80 'servo rotation (not working)
PulsOut PORTB.3,50
Pause 20
Next val
GoSub Main
-need help here please.TQ