سلام من این برنامه تایمر-محافظ ولتاژ رو نوشتم ولی هرکاری کردم نتونستم زمان دقیق نیم ثانیه را حتی با کریستال ساعت به دست بیارم لطفا یکی کمک کنه:
'******************************************** **********************************
'* PROTECTOR & TIMER *
'* *
'* *
'* seven segment anod common * Vadc normal <1.1volt * 0 to 255 miniutes timer * *
'* *
'******************************************** **********************************
$regfile = "M48def.dat"
$crystal = 8000000
Dim B As Word , Volt As Word , S As Bit , Zaman As Byte , V_t As Byte , _
A As Byte , C As Byte , G As Word , Z As Word , T As Word , Seco As Byte , _
N As Single , Yek As Word , Dah As Word , Sad As Word , L As Bit
Config Timer2 = Timer , Async = On , Prescale = 64
Config Adc = Single , Prescaler = Auto , Reference = Internal
Config Timer0 = Timer , Prescale = 64
Config Timer1 = Timer , Prescale = 64
'Config Clock = Soft , Gosub = Sectic
'Set As2
Enable Interrupts
Enable Timer0
Enable Timer1
Enable Timer2
On Timer0 7seg
On Ovf2 Sectic
On Timer1 Volt_sample
Config Portc = Input
Config Portb = Output : Set Ddrb
Config Portd = Output : Set Ddrd
Timer0 = 214
Timer1 = 64440
Start Timer0
Start Timer1
'-----------------------------------------------
Rele Alias Portb.5
Point Alias Portd.7
Abnormal Alias Portb.0
Estop Alias Pinc.3
Z_up Alias Pinc.4
Z_dwn Alias Pinc.5
V_meter Alias Pinc.2
'-----------------------------------------------
Do
If Z_up = 0 Then : Incr Zaman : S = 1 : Waitms 160 : End If
If Z_dwn = 0 Then : Decr Zaman : S = 1 : Waitms 160 : End If
If Estop = 0 Then : Zaman = 0 : S = 0 : End If
If V_meter = 0 Then : Set Point : Z = Volt : Else : Z = Zaman : End If
Sad = Z / 100
T = Z Mod 100
Dah = T / 10
Yek = T Mod 10
If Zaman > 0 Then
Select Case Volt
Case Is < 185
Reset Rele
Set Abnormal
Stop Timer1
Set L
Case 185 To 244
Reset Abnormal
If S = 1 Then : Set Rele : Start Timer1 : End If
Case Is > 244
Reset Rele
Set Abnormal
Stop Timer1
Set L
End Select
Else
Stop Timer1
Reset Rele
Reset Point
S = 0
End If
Loop
End 'end program
'-------------------------------------------------
7seg:
Timer0 = 214
Incr A
Select Case A
Case 1:
Portb.1 = 1 : Portb.2 = 0 : Portb.3 = 0 : Portd = Lookup(sad , W) : Set Point
Case 2:
Portb.1 = 0 : Portb.2 = 1 : Portb.3 = 0 : Portd = Lookup(dah , W) : Set Point
Case 3:
Portb.1 = 0 : Portb.2 = 0 : Portb.3 = 1 : Portd = Lookup(yek , W)
If V_meter = 0 Or L = 0 Then Set Point Else Reset Point
A = 0
End Select
Return
'-------------------------------------------------
Sectic:
Incr Seco
Toggle L
If Seco = 120 Then : Decr Zaman : Seco = 0 : End If
Return
'-------------------------------------------------
Volt_sample:
Timer1 = 64440
Incr C
Start Adc
B = Getadc(0)
Stop Adc
G = G + B
If C = 10 Then
N = G / 38.66
Volt = N
G = 0
C = 0
End If
Return
'-------------------------------------------------
W:
Data &B1000000 , &B1111001 , &B0100100 , &B0110000 , &B0011001 , &B0010010 , &B0000010 , &B1111000 , &B0000000 , &B10010000
'******************************************** **********************************
'* PROTECTOR & TIMER *
'* *
'* *
'* seven segment anod common * Vadc normal <1.1volt * 0 to 255 miniutes timer * *
'* *
'******************************************** **********************************
$regfile = "M48def.dat"
$crystal = 8000000
Dim B As Word , Volt As Word , S As Bit , Zaman As Byte , V_t As Byte , _
A As Byte , C As Byte , G As Word , Z As Word , T As Word , Seco As Byte , _
N As Single , Yek As Word , Dah As Word , Sad As Word , L As Bit
Config Timer2 = Timer , Async = On , Prescale = 64
Config Adc = Single , Prescaler = Auto , Reference = Internal
Config Timer0 = Timer , Prescale = 64
Config Timer1 = Timer , Prescale = 64
'Config Clock = Soft , Gosub = Sectic
'Set As2
Enable Interrupts
Enable Timer0
Enable Timer1
Enable Timer2
On Timer0 7seg
On Ovf2 Sectic
On Timer1 Volt_sample
Config Portc = Input
Config Portb = Output : Set Ddrb
Config Portd = Output : Set Ddrd
Timer0 = 214
Timer1 = 64440
Start Timer0
Start Timer1
'-----------------------------------------------
Rele Alias Portb.5
Point Alias Portd.7
Abnormal Alias Portb.0
Estop Alias Pinc.3
Z_up Alias Pinc.4
Z_dwn Alias Pinc.5
V_meter Alias Pinc.2
'-----------------------------------------------
Do
If Z_up = 0 Then : Incr Zaman : S = 1 : Waitms 160 : End If
If Z_dwn = 0 Then : Decr Zaman : S = 1 : Waitms 160 : End If
If Estop = 0 Then : Zaman = 0 : S = 0 : End If
If V_meter = 0 Then : Set Point : Z = Volt : Else : Z = Zaman : End If
Sad = Z / 100
T = Z Mod 100
Dah = T / 10
Yek = T Mod 10
If Zaman > 0 Then
Select Case Volt
Case Is < 185
Reset Rele
Set Abnormal
Stop Timer1
Set L
Case 185 To 244
Reset Abnormal
If S = 1 Then : Set Rele : Start Timer1 : End If
Case Is > 244
Reset Rele
Set Abnormal
Stop Timer1
Set L
End Select
Else
Stop Timer1
Reset Rele
Reset Point
S = 0
End If
Loop
End 'end program
'-------------------------------------------------
7seg:
Timer0 = 214
Incr A
Select Case A
Case 1:
Portb.1 = 1 : Portb.2 = 0 : Portb.3 = 0 : Portd = Lookup(sad , W) : Set Point
Case 2:
Portb.1 = 0 : Portb.2 = 1 : Portb.3 = 0 : Portd = Lookup(dah , W) : Set Point
Case 3:
Portb.1 = 0 : Portb.2 = 0 : Portb.3 = 1 : Portd = Lookup(yek , W)
If V_meter = 0 Or L = 0 Then Set Point Else Reset Point
A = 0
End Select
Return
'-------------------------------------------------
Sectic:
Incr Seco
Toggle L
If Seco = 120 Then : Decr Zaman : Seco = 0 : End If
Return
'-------------------------------------------------
Volt_sample:
Timer1 = 64440
Incr C
Start Adc
B = Getadc(0)
Stop Adc
G = G + B
If C = 10 Then
N = G / 38.66
Volt = N
G = 0
C = 0
End If
Return
'-------------------------------------------------
W:
Data &B1000000 , &B1111001 , &B0100100 , &B0110000 , &B0011001 , &B0010010 , &B0000010 , &B1111000 , &B0000000 , &B10010000
دیدگاه