Elektryzator sterowany atmegą8


Witam, naskrobałem kawałek programu obsługującego sterownik - monitor transformatora wysokiego napięcia. Jest to popularny pastuch ogrodzeń pastwiskowych. Otóż wszystko działa jak należy poza jedynym faktem że nie potrafię wplątać do tego programu trzech klawiszy za pomocą których mógłbym zmieniać na starcie parametry. Oto co chciałbym wprowadzić w ten poniższy program.
S1 - zwiększenie parametru - od 15 do 45
S2 - zmniejszenie parametru - od 45 do 15
S3 - Zapis do eeprom atmegi i wykonaj program.

Rem Cyfrowy sterownik elektryzatora 
Rem projekt wykonał Karol F. 2015/05/14
Rem Procesor ATMEGA8
 
'$sim
$regfile = "m8def.dat"
$crystal = 16000000                                         ' Taktowanie zegara 8MHz rc wewnętrzny
' $baud = 9600
$hwstack = 32
$swstack = 16
$framesize = 16
 
'Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Rem Konfig. ADC
Config Lcdpin = Pin , Db4 = Portb.2 , Db5 = Portb.3 , Db6 = Portb.4 , Db7 = Portb.5 , E = Portb.1 , Rs = Portb.0
 Config Lcd = 16x2                                          'configure lcd screen
Cls
Cursor Off
Lcd " Pastuch ver.2"
Lowerline
Lcd " High Voltage !"
Waitms 2000
 Cls
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Rem Konfiguracja portów In - Out
Config Portb.0 = Output                                     ' Wolne takt pastucha 350V
Config Portb.1 = Output                                     ' Średni takt pastucha 300V
Config Portb.2 = Output                                     ' Szybki takt pastucha 250V
Reset Portb.0
Reset Portb.1
Reset Portb.2
 
Config Portd.3 = Output
Config Portd.4 = Output
Config Portd.5 = Output
Config Portd.6 = Output
Config Portd.7 = Output
Reset Portd.3
Reset Portd.4
Reset Portd.6
Reset Portd.5
Reset Portd.7
 
 
Rem Inicjacja przetwornika ADC 10bit
'Enable Adc
Const Div = 5 / 1023
Rem stałe zmienne
Dim Vref As Word
Dim Vin As Single
Dim Vbat As Single
Dim Va As Single
Dim Vb As Single
Rem Obsługa klawiszy sterujących
Lcd "Ustaw Parametry"
 
Start Adc
Rem ================  Warunki początkowe
Va = 29                     ' napięcie z dzielnika 400V (29 odpowiada 290V)
Vb = 30
 
 
 
Do
 
' Gosub Bat_high
 Gosub Automat
 Gosub Bat_alarm
 Loop
' End
 
Automat:
Vref = Getadc(0)
Vin = Vref * Div
Vin = Vin * 10
If Vin <= Va Then                                           ' Load DC 250-300V
'Set Portb.0
Set Portd.7                                                 'Dioda LED LOAD
Reset Portd.30                                              ' tranzystor sterujący trafo
  End If
If Vin >= Vb Then
 Reset Portd.7                                             ' Dioda Led LOAD                                           ' SET TRAFO HV 300V impuls sterujący
 Set Portd.6                                                ' tranzystor sterujący trafo
  Waitms 10
  Reset Portd.6
    End If
Print "ADC0 =  " ; Vin ; " value " ; Vref
 Return
Rem Pomiar Napięcia Akumulatora 12V - przy 10V załącz Alarm!
 
Bat_alarm:
 
 Vref = Getadc(1)
  Vbat = Vref * Div
   Vbat = Vbat * 10
If Vbat =< 10.00 Then                                       ' Alarm Battery < 10V buzzer
Reset Portd.4
 
 Reset Portd.5
  Set Portd.5
    Waitms 50
 Reset Portd.5
    Waitms 50
 Set Portd.5
  Reset Portd.5
    Waitms 50
 Set Portd.5
    Waitms 50
  Reset Portd.5
     Waitms 50
     End If
 If Vbat => 10.00 Then
  Set Portd.4
  End If
Return
 
End

Bardzo bym prosił o pomoc tej poprawki.




Portret użytkownika EDC

Odp. Elektryzator

Proszę. Pozmieniałbym dużo więcej w tym programie, ale nie mam dziś więcej czasu. To co chciałeś powinno działać.

Rem Cyfrowy sterownik elektryzatora
Rem projekt wykonał Karol F. 2015/05/14
Rem Procesor ATMEGA8
 
'$sim
$regfile = "m8def.dat"
$crystal = 16000000                                         ' Taktowanie zegara 8MHz rc wewnętrzny
' $baud = 9600
$hwstack = 32
$swstack = 16
$framesize = 16
 
'Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Rem Konfig. ADC
Config Lcdpin = Pin , Db4 = Portb.2 , Db5 = Portb.3 , Db6 = Portb.4 , Db7 = Portb.5 , E = Portb.1 , Rs = Portb.0
 Config Lcd = 16x2                                          'configure lcd screen
Cls
Cursor Off
 
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Rem Konfiguracja portów In - Out
Config Portb.0 = Output                                     ' Wolne takt pastucha 350V
Config Portb.1 = Output                                     ' Średni takt pastucha 300V
Config Portb.2 = Output                                     ' Szybki takt pastucha 250V
Reset Portb.0
Reset Portb.1
Reset Portb.2
 
Config Portd.3 = Output
Config Portd.4 = Output
Config Portd.5 = Output
Config Portd.6 = Output
Config Portd.7 = Output
Reset Portd.3
Reset Portd.4
Reset Portd.6
Reset Portd.5
Reset Portd.7
 
 
Rem Inicjacja przetwornika ADC 10bit
'Enable Adc
Const Div = 5 / 1023
Rem stałe zmienne
Dim Vref As Word
Dim Vin As Single
Dim Vbat As Single
Dim Va As Single
Dim Vb As Single
Rem Obsługa klawiszy sterujących
 
 
Start Adc
Rem ================  Warunki początkowe
Va = 29                     ' napięcie z dzielnika 400V (29 odpowiada 290V)
Vb = 30
 
'----------------------------------------------------------------------------------------
Config Portc.5 = Input : Portc.5 = 1 : S1 Alias Pinc.5
Config Portc.4 = Input : Portc.4 = 1 : S2 Alias Pinc.4
Config Portc.3 = Input : Portc.3 = 1 : S3 Alias Pinc.3
 
Dim Parametr As Byte
 
Readeeprom Parametr , 2
 If Parametr > 45 Then Parametr = 30
 
Dim Odswiez As Byte
 Odswiez = 1
 
Dim Blokada As Byte
 
 
Lcd " Pastuch ver.2"
Lowerline
Lcd " High Voltage !"
Waitms 2000
 Cls
Lcd "Ustaw Parametry"
 
Do
 
 If Odswiez = 1 Then
     Odswiez = 0
     Locate 2 , 1 : Lcd Parametr
 End If
 
Debounce S1 , 0 , Zmniejsz , Sub
Debounce S2 , 0 , Zwieksz , Sub
Debounce S3 , 0 , Zapisz , Sub
 
 
Loop Until Blokada = 1
'-------------------------------------------------------------------------------------------
 
 
 
 
Do
 
' Gosub Bat_high
 Gosub Automat
 Gosub Bat_alarm
 Loop
' End
 
Automat:
Vref = Getadc(0)
Vin = Vref * Div
Vin = Vin * 10
If Vin <= Va Then                                           ' Load DC 250-300V
'Set Portb.0
Set Portd.7                                                 'Dioda LED LOAD
Reset Portd.30                                              ' tranzystor sterujący trafo
  End If
If Vin >= Vb Then
 Reset Portd.7                                             ' Dioda Led LOAD                                           ' SET TRAFO HV 300V impuls sterujący
 Set Portd.6                                                ' tranzystor sterujący trafo
  Waitms 10
  Reset Portd.6
    End If
Print "ADC0 =  " ; Vin ; " value " ; Vref
 Return
Rem Pomiar Napięcia Akumulatora 12V - przy 10V załącz Alarm!
 
Bat_alarm:
 
 Vref = Getadc(1)
  Vbat = Vref * Div
   Vbat = Vbat * 10
If Vbat =< 10.00 Then                                       ' Alarm Battery < 10V buzzer
Reset Portd.4
 
 Reset Portd.5
  Set Portd.5
    Waitms 50
 Reset Portd.5
    Waitms 50
 Set Portd.5
  Reset Portd.5
    Waitms 50
 Set Portd.5
    Waitms 50
  Reset Portd.5
     Waitms 50
     End If
 If Vbat => 10.00 Then
  Set Portd.4
  End If
Return
 
'--------------------------------------------------------------------
Zwieksz:
 If Parametr < 45 Then Incr Parametr
  Odswiez = 1
Return
 
Zmniejsz:
 If Parametr > 15 Then Decr Parametr
  Odswiez = 1
Return
 
Zapisz:
 
  Writeeeprom Parametr , 2
 
    Blokada = 1
Return
'---------------------------------------------------------------------
End

-

BARTek
Moja strona

Portret użytkownika Karlos123

Elektryzator sterowany atmegą8

Bartek jesteś wielki, dzięki za pomoc, ale jak byś był w stanie coś tam poprawić to poczekam...

Portret użytkownika gosc

Elektryzator sterowany atmegą8

Karlos123 pokażesz schemat elektryzatora