Device 16F887
On_Interrupt TIMER
Xtal 10
Asm
CONFIG_REQ
__CONFIG _CONFIG1, HS_OSC & WDT_OFF & DEBUG_OFF & FCMEN_OFF & LVP_OFF & IESO_OFF & BOR_OFF & CPD_OFF & CP_OFF & MCLRE_OFF & PWRTE_ON
__CONFIG _CONFIG2, WRT_OFF & BOR40V
EndAsm
All_Digital true
Symbol GIE = INTCON.7
Symbol T0IF = INTCON.2
Symbol T0IE = INTCON.5
Symbol PS0 = OPTION_REG.0
Symbol PS1 = OPTION_REG.1
Symbol PS2 = OPTION_REG.2
Symbol PSA = OPTION_REG.3
Symbol T0SE = OPTION_REG.4
Symbol T0CS = OPTION_REG.5
Declare LCD_RSPin PORTD.2
Declare LCD_ENPin PORTD.3
Declare LCD_DTPin PORTD.4
Declare Adin_Res = 8
Declare Adin_Tad = frc
Declare Adin_Stime = 50
Symbol STRING_OMVORMER_1 = PORTB.0
Symbol STRING_OMVORMER_2 = PORTB.1
Symbol STRING_OMVORMER_3 = PORTB.2
Symbol LED_FASE_1 = PORTB.3
Symbol LED_FASE_2 = PORTB.4
Symbol LED_FASE_3 = PORTB.5
Symbol I_MAX = 140
Symbol I_MIN = 100
Symbol TMR1_TIJD = 300
Symbol TMR2_TIJD = 305
Symbol TMR3_TIJD = 310
Dim I_MAX_L1 As Byte
Dim I_MAX_L2 As Byte
Dim I_MAX_L3 As Byte
Dim PULS As Bit
Dim TMR_1 As Word
Dim TMR_2 As Word
Dim TMR_3 As Word
Dim TMR_4 As Byte
Dim TMR_5 As Byte
Dim TMR_6 As Byte
Dim VAL_TIMER As Word
Dim LIMITE_TIMER As Word
GIE = 0
GoTo INSTELLING
TIMER:
Context Save
Inc VAL_TIMER
T0IF = 0
Context Restore
INSTELLING:
PS0 = 1
PS1 = 1
PS2 = 1
PSA = 0
T0SE = 0
T0CS = 0
VAL_TIMER = 0
TMR0 = 0
T0IE = 1
GIE = 1
Cls
DelayMS 500
Clear
PORTA = %000000
TRISA = %111111
PORTB = %000000
TRISB = %000000
PORTC = %00000000
TRISC = %00000000
PORTD = %00000000
TRISD = %00000000
PORTE = %000
TRISE = %111
ADCON0 = %00000001
ANSELH = %000000
TMR_1 = 0
TMR_2 = 0
TMR_3 = 0
TMR_4 = 0
TMR_5 = 0
TMR_6 = 0
RUN:
LIMITE_TIMER = 38
If VAL_TIMER > LIMITE_TIMER Then
VAL_TIMER = 0
If VAL_TIMER = 0 Then
PULS = 1
EndIf
EndIf
I_MAX_L1 = ADIn 0
I_MAX_L2 = ADIn 1
I_MAX_L3 = ADIn 2
Print At 1,1,"STR_1="
Print At 2,1,"STR_2="
Print At 3,1,"STR_3="
Print At 1,9,"I_L1="
Print At 2,9,"I_L2="
Print At 3,9,"I_L3="
Print At 1,19,"A"
Print At 2,19,"A"
Print At 3,19,"A"
Print At 1,14,Dec1 I_MAX_L1 / 3.9,
Print At 2,14,Dec1 I_MAX_L2 / 3.9,
Print At 3,14,Dec1 I_MAX_L3 / 3.9,
Print At 4,1,"HvZ_Pro & Sluis_elek"
If I_MAX_L1 < I_MIN Then
If PULS = 1 Then
TMR_1 = TMR_1 + 1
If TMR_1 > TMR1_TIJD Then
STRING_OMVORMER_1 = 1
Print At 1,7,Dec STRING_OMVORMER_1,
TMR_1 = TMR_1 - 1
EndIf
EndIf
EndIf
If I_MAX_L1 > I_MAX Then
TMR_1 = 0
STRING_OMVORMER_1 = 0
Print At 1,7,Dec STRING_OMVORMER_1,
EndIf
If I_MAX_L1 < I_MIN Then
If PULS = 1 Then
TMR_4 = TMR_4 + 1
If TMR_4 > 1 Then
LED_FASE_1 = 1
If TMR_4 > 2 Then
LED_FASE_1 = 0
TMR_4 = 0
EndIf
EndIf
EndIf
EndIf
If STRING_OMVORMER_1 = 1 Then
LED_FASE_1 = 0
TMR_4 = 0
EndIf
If I_MAX_L1 > I_MAX Then
LED_FASE_1 = 0
EndIf
If I_MAX_L1 > I_MIN Then
LED_FASE_1 = 0
EndIf
If I_MAX_L2 < I_MIN Then
If PULS = 1 Then
TMR_2 = TMR_2 + 1
If TMR_2 > TMR2_TIJD Then
STRING_OMVORMER_2 = 1
Print At 2,7,Dec STRING_OMVORMER_2,
TMR_2 = TMR_2 - 1
EndIf
EndIf
EndIf
If I_MAX_L2 > I_MAX Then
TMR_2 = 0
STRING_OMVORMER_2 = 0
Print At 2,7,Dec STRING_OMVORMER_2,
EndIf
If I_MAX_L2 < I_MIN Then
If PULS = 1 Then
TMR_5 = TMR_5 + 1
If TMR_5 > 1 Then
LED_FASE_2 = 1
If TMR_5 > 2 Then
LED_FASE_2 = 0
TMR_5 = 0
EndIf
EndIf
EndIf
EndIf
If STRING_OMVORMER_2 = 1 Then
LED_FASE_2 = 0
TMR_5 = 0
EndIf
If I_MAX_L2 > I_MAX Then
LED_FASE_2 = 0
EndIf
If I_MAX_L2 > I_MIN Then
LED_FASE_2 = 0
EndIf
If I_MAX_L3 < I_MIN Then
If PULS = 1 Then
TMR_3 = TMR_3 + 1
If TMR_3 > TMR3_TIJD Then
STRING_OMVORMER_3 = 1
Print At 3,7,Dec STRING_OMVORMER_3,
TMR_3 = TMR_3 - 1
EndIf
EndIf
EndIf
If I_MAX_L3 > I_MAX Then
TMR_3 = 0
STRING_OMVORMER_3 = 0
Print At 3,7,Dec STRING_OMVORMER_3,
EndIf
If I_MAX_L3 < I_MIN Then
If PULS = 1 Then
TMR_6 = TMR_6 + 1
If TMR_6 > 1 Then
LED_FASE_3 = 1
If TMR_6 > 2 Then
LED_FASE_3 = 0
TMR_6 = 0
EndIf
EndIf
EndIf
EndIf
If STRING_OMVORMER_3 = 1 Then
LED_FASE_3 = 0
TMR_6 = 0
EndIf
If I_MAX_L3 > I_MAX Then
LED_FASE_3 = 0
EndIf
If I_MAX_L3 > I_MIN Then
LED_FASE_3 = 0
EndIf
PULS = 0
GoTo RUN
End