اطلاعیه

Collapse
No announcement yet.

مشکل عدم ریست شدن خروجی های برنامه..

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    مشکل عدم ریست شدن خروجی های برنامه..

    با سلام

    یک برنامه نوشتم که جدا از اینکه یک ساعت را در اولین اجرای خودش نمایش میده این قابلیت را داره که با کلیک کردن دکمه اینتر بشه ساعت رو تنظیم نمود.
    قابلیت دیگرش به کمک 2 کلید تایمر جهت تنظیم زمان روشن و خاموش کردن برای دو خروجی مرتبط با رله ها هست.
    1) مشکل اینجاست که پس از تنظیم زمان تایمر، در ابتدا چشمک زده بعد روشن میشه.
    2) زمان تنظیم شده برای خاموشی اصلا اجرایی روی پایه خروجی نداره.

    در هردوی تایمرها همین مشکل هست.
    برنامه را با شبیه سازی میگذارم ممنون میشم اشکال برنامه را بررسی بفرمایید.

    کد:
    $regfile = "m8def.dat"
    $crystal = 8000000
    
    Config Timer2 = Timer , Async = On , Prescale = 128
    On Ovf2 Clock
    
    Enable Interrupts
    Enable Timer2
    
    
    Config Lcdpin = Pin , Rs = Portd.0 , E = Portd.2 , Db4 = Portd.3 , Db5 = Portd.4 , Db6 = Portd.5 , Db7 = Portd.6
    Config Lcd = 16 * 2
    Cursor Off
    Config Portb = Input
    Config Portc = Output
    
    
    Dim W As Byte
    W = Timer2
    Timer2 = W
    
    Dim Hour As Byte
    Dim Minute As Byte
    Dim Second As Byte
    
    Dim Status As Byte
    Dim Tim As Byte
    Dim Comp As Bit
    Comp = 0
    
    Dim Hour_ont1 As Byte
    Dim Minute_ont1 As Byte
    Dim Second_ont1 As Byte
    Dim Hour_ont2 As Byte
    Dim Minute_ont2 As Byte
    Dim Second_ont2 As Byte
    
    Dim Hour_offt1 As Byte
    Dim Minute_offt1 As Byte
    Dim Second_offt1 As Byte
    Dim Hour_offt2 As Byte
    Dim Minute_offt2 As Byte
    Dim Second_offt2 As Byte
    
    Dim Set_h As Byte
    Dim Set_m As Byte
    Dim Set_s As Byte
    Set_h = 0
    Set_m = 0
    Set_s = 0
    
    Dim Shw_lcd As Bit
    Dim Dly As Byte
    Dim Clean As String * 16
    Dly = 50
    Clean = "        "
    
    Down Alias Pinb.0
    Enter Alias Pinb.1
    Up Alias Pinb.2
    Time_1 Alias Pinb.3
    Time_2 Alias Pinb.4
    Relay_1 Alias Pinc.1
    Relay_2 Alias Pinc.0
    
    
    Main:
    
      Do
    
       If Comp = 1 Then
    
         '''''''''''''''''''''''''''' Timer 1 Check ''''''''''''''''''''''''
       If Hour_ont1 = Hour And Minute_ont1 = Minute And Second_ont1 = Second Then
         Waitms 25
         Set Relay_1
       End If
    
       If Hour = Hour_offt1 And Minute = Minute_offt1 And Second = Second_offt1 Then
        Waitms 25
         Reset Relay_1
       End If
    
    
         '''''''''''''''''''''''''''' Timer 2 Check ''''''''''''''''''''''''
       If Hour_ont2 = Hour And Minute_ont2 = Minute And Second_ont2 = Second Then
         Waitms 25
         Set Relay_2
       End If
    
       If Hour = Hour_offt2 And Minute = Minute_offt2 And Second = Second_offt2 Then
         Waitms 25
         Reset Relay_2
       End If
       End If
    
    
       If Enter = 0 Then
         Waitms Dly
         Shw_lcd = 0
         Cls
         Locate 1 , 2
         Lcd "Clock Setting"
         Set_h = Hour
         Set_m = Minute
         Set_s = Second
         Gosub Set_time
         Hour = Set_h
         Minute = Set_m
         Second = Set_s
       End If
    
       If Time_1 = 0 Then
         Waitms Dly
         Shw_lcd = 0
         Tim = 1
         Gosub Set_timer
       End If
    
       If Time_2 = 0 Then
         Waitms Dly
         Shw_lcd = 0
         Tim = 2
         Gosub Set_timer
       End If
    
    
       Shw_lcd = 1
       Set_h = 0
       Set_m = 0
       Set_s = 0
    
      Loop
    
    
    Set_timer:
    
      Cls
      Locate 1 , 2
      Lcd "Setting Timer" ; Tim
      Locate 2 , 2
      Lcd "Select UP/DOWN"
      Status = 3
      Set_h = 0
      Set_m = 0
      Set_s = 0
    
      Do
       If Down = 0 Then
         Waitms Dly
         Locate 2 , 1
         Lcd Clean
         Waitms 2
         Locate 2 , 1
         Lcd "ST" ; Tim ; " On"
         If Tim = 1 Then
          Locate 2 , 9
          Lcd Hour_ont1 ; ":" ; Minute_ont1 ; ":" ; Second_ont1
         Else
          Locate 2 , 9
          Lcd Hour_ont2 ; ":" ; Minute_ont2 ; ":" ; Second_ont2
         End If
         Status = 1
       End If
    
       If Up = 0 Then
         Waitms Dly
         Locate 2 , 1
         Lcd Clean
         Waitms 2
         Locate 2 , 1
         Lcd "ST" ; Tim ; " OFF"
         If Tim = 1 Then
          Locate 2 , 9
          Lcd Hour_offt1 ; ":" ; Minute_offt1 ; ":" ; Second_offt1
         Else
          Locate 2 , 9
          Lcd Hour_offt2 ; ":" ; Minute_offt2 ; ":" ; Second_offt2
         End If
         Status = 0
       End If
    
       If Enter = 0 And Status = 0 And Tim = 1 Then
         Waitms Dly
         Cls
         Locate 1 , 2
         Lcd "Set Timer1 OFF"
         Set_h = Hour_offt1
         Set_m = Minute_offt1
         Set_s = Second_offt1
         Gosub Set_time
         Hour_offt1 = Set_h
         Minute_offt1 = Set_m
         Second_offt1 = Set_s
         Status = 1
         Comp = 1
         Goto Set_timer
       End If
    
       If Enter = 0 And Status = 1 And Tim = 1 Then
         Waitms Dly
         Cls
         Locate 1 , 2
         Lcd "Set Timer1 ON"
         Set_h = Hour_ont1
         Set_m = Minute_ont1
         Set_s = Second_ont1
         Gosub Set_time
         Hour_ont1 = Set_h
         Minute_ont1 = Set_m
         Second_ont1 = Set_s
         Status = 0
         Comp = 1
         Goto Set_timer
       End If
    
       If Enter = 0 And Status = 0 And Tim = 2 Then
         Waitms Dly
         Cls
         Locate 1 , 2
         Lcd "Set Timer2 OFF"
         Set_h = Hour_offt2
         Set_m = Minute_offt2
         Set_s = Second_offt2
         Gosub Set_time
         Hour_offt2 = Set_h
         Minute_offt2 = Set_m
         Second_offt2 = Set_s
         Status = 1
         Comp = 1
         Goto Set_timer
       End If
    
       If Enter = 0 And Status = 1 And Tim = 2 Then
         Waitms Dly
         Cls
         Locate 1 , 2
         Lcd "Set Timer2 ON"
         Set_h = Hour_ont2
         Set_m = Minute_ont2
         Set_s = Second_ont2
         Gosub Set_time
         Hour_ont2 = Set_h
         Minute_ont2 = Set_m
         Second_ont2 = Set_s
         Status = 0
         Comp = 1
         Goto Set_timer
       End If
    
       If Time_1 = 0 Or Time_2 = 0 Then
         Waitms Dly
         Return
       End If
      Loop
    
    
    ''''''''''''''''''''''''''''''''''' Setting Time ''''''''''''''''''''''''''''
    
    Set_time:
    
      Do
       If Up = 0 Then
         Waitms Dly
         Incr Set_h
         If Set_h = 24 Then Set_h = 0
       End If
    
       If Enter = 0 Then
         Waitms Dly
         Exit Do
       End If
    
       If Down = 0 Then
         Waitms Dly
         Decr Set_h
         If Set_h = 255 Then Set_h = 23
       End If
       Gosub Show_lcd
      Loop
    
      Do
       If Up = 0 Then
         Waitms Dly
         Incr Set_m
         If Set_m = 60 Then Set_m = 0
       End If
    
       If Enter = 0 Then
         Waitms Dly
         Exit Do
       End If
    
       If Down = 0 Then
         Waitms Dly
         Decr Set_m
         If Set_m = 255 Then Set_m = 59
       End If
       Gosub Show_lcd
      Loop
    
      Do
       If Up = 0 Then
         Waitms Dly
         Incr Set_s
         If Set_s = 60 Then Set_s = 0
       End If
    
       If Enter = 0 Then
         Waitms Dly
         Cls
         Return
       End If
    
       If Down = 0 Then
         Waitms Dly
         Decr Set_s
         If Set_s = 255 Then Set_s = 59
       End If
       Gosub Show_lcd
      Loop
    
    
    
      ''''''''''''''''''''''''''''''''' Show On LCD '''''''''''''''''''''''''''''
    Show_lcd:
    
      Locate 2 , 1
      Lcd Clean
      Locate 2 , 5
      Lcd Set_h ; ":" ; Set_m ; ":" ; Set_s
      Return
    
    
    '################################# Clock ######################################'
    
    
    Clock:
    
    'get here every second with a 32768 Hz xtal
    
        If Second = 59 Then
            Second = 0
            If Minute = 59 Then
                Minute = 0
                If Hour = 23 Then
                    Hour = 0
                Else
                    Incr Hour
                End If
            Else
                Incr Minute
            End If
        Else
            Incr Second
        End If
      If Shw_lcd = 1 Then
       Cls
       Locate 1 , 6
       Lcd Hour ; ":" ; Minute ; ":" ; Second
      End If
    
    Return
    
    End                             'end program

    لینک فایل شبیه ساز : http://www.4shared.com/zip/cOHd6u56/Clock__Two_Timer.html

    #2
    پاسخ : مشکل عدم ریست شدن خروجی های برنامه..

    چقدر زود تاپیک ما مدفون شد oo:
    کسی نظری نداره؟

    دیدگاه


      #3
      پاسخ : مشکل عدم ریست شدن خروجی های برنامه..

      [move] :wow: :wow: :wow:[/move]
      ببین یک مشکل خیلی ساده و پیش پا افتیده چطور مارو الچک میکنه.
      از دوستان گلی که به این تاپیک توجه کردن ممنونم
      احتمالا اگر شد کار رو در لیست پروژه ها قرار دادم

      دیدگاه

      لطفا صبر کنید...
      X