i using the proton to write this code and i have the problem of the delay time cannot put at the if else statement and i want write the emergency stop button when the button is close (voltage is off) the condition stop when button is open (voltage on) it will resume
'****************************************************************
Device 16F877A
XTAL = 20 ' crystal = 20 Mhz
ALL_DIGITAL = TRUE ' set all input output in digital form
PORTB_PULLUPS = TRUE ' enable the portb have a pullups resistance
Dim i As Byte
TRISA = %000000 ' set the port A as ouput
TRISB = %11111111 ' set the port B as output
TRISC = %00000000 ' set the port C as input
TRISD = %11111111 ' set the port D as input
TRISE = %000 ' set the port E as input
INTCON = %10010000 ' Enable RB0 interrupt
PORTB = 0
ON_INTERRUPT GoTo emergency
main:
Disable
PORTC = %01100100
If PORTB.6 = 1 And PORTB.7 = 1 And PORTD.1 = 1 Then
PORTC = %00100010 'motor base ccw
EndIf
If PORTD.3 = 1 And PORTB.7 = 1 Then
PORTC = %00001100 'arm motor clock wise base brake
EndIf
If PORTD.2 = 1 And PORTD.3 = 1 Then
PORTC = %10100100 'break base and arm and extrude cylinder
EndIf
If PORTB.5 = 1 And PORTB.7 = 1 And PORTD.3 = 1 Then
PORTC = %10100100 'break base and arm and extrude cylinder
Set PORTA.0 'gripper grip
EndIf
If PORTB.1 = 1 And PORTD.3 = 1 Then
PORTC = %10010100 'gripper grip arm motor up and cylinder in extrude
EndIf
If PORTD.1 = 1 And PORTB.1 = 1 And PORTD.3 = 1 Then
PORTC = %01100100 'cylinder retract in
EndIf
If PORTB.4 = 1 And PORTD.1 = 1 And PORTB.1 = 1 Then
PORTC = %01100001 ' move left
EndIf
If PORTB.1 = 1 And PORTD.4 = 1 And PORTB.4 = 1 Then
PORTC = %01001100 ' arm move down, cylinder in retract condition
EndIf
If PORTB.1 =1 And PORTD.4 = 1 And PORTD.2 = 1 Then
PORTC = %10100100 ' arm stop and cylinder extract
EndIf
If PORTB.5 = 1 And PORTD.4 = 1 And PORTD.2 = 1 Then
PORTC = %10100100 'extrude sensor on and at left and at limit arm up
Clear PORTA.0 'gripper release
EndIf
If PORTD.0 = 1 And PORTD.2 = 1 And PORTD.4 = 1 Then
PORTC = %10010100 'arm motor turn ccw and extract valve on
EndIf
If PORTD.1 = 1 And PORTD.4 = 1 And PORTD.0 = 1 Then
PORTC = %01100100 'motor arm turn off and cylinder retract
EndIf
If PORTD.1 = 1 And PORTB.1 = 0 And PORTB.4 = 1 Then main
emergency:
INTCON.7 = 1 'disable all interrputs
While PORTB.0 = 0 ' waiting untill
PORTC= %00100100 ' reset output to PORTC
Wend ' push-button is release
DelayMS 100 ' debounce time
INTCON = %10010000 ' Enable RB0 interrupt
' reset RB0 interrupt flag
Context Restore
Resume ' Return to main program
Enable ' Enable interrupts after handler
