اطلاعیه

Collapse
No announcement yet.

سوال؟ال سی دی گرافیکی با ساعت و تقویم و دماسنج و الارم

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

    #46
    پاسخ : سوال؟ال سی دی گرافیکی با ساعت و تقویم و دماسنج و الارم

    سلام
    کسی از دوستان می تونه بگه این برنامه مشکلش چیه؟
    وقتی ماه میلادی 31 روزه هست به مشکل میخوره برنامه
    یعنی مثلا الان روز 30 میلادی هست بعد باید بشه 31 ولی نمیشه و میشه اول ماه جدید و بعد که میری تو منو برای تغییرات، چه تغییر بدی و چه ندی و بیای بیرون یکی به روز اضافه میکنه!!!

    این برنامه کسی می تونه کمک کنه؟!؟!؟ :cry2:

    $regfile = "m32def.dat"

    $include "font8x8.font"
    $crystal = 8000000

    Declare Function M_kabise(byref Sal As Word)as Byte
    Declare Function Sh_kabise(byref Sal As Word)as Byte
    '-----------------------------------------------------
    $hwstack = 64
    $swstack = 64
    $framesize = 64
    $lib "glcdKS108.lbx"
    Config Graphlcd = 128 * 64sed , Dataport = Portd , Controlport = Portb , Enable = 2 , Cd = 0 , Ce = 3 , Ce2 = 4 , Reset = 5 , Rd = 1
    Setfont Font8x8
    ''''''''&# 039;'''''''&#03 9;'''''''' ''''''''&# 039;'''''''&#03 9;
    Config Adc = Single , Prescaler = Auto , Reference = Avcc
    Enable Adc
    Start Adc
    '-----------------------------------------------------
    Config Sda = Portb.7
    Config Scl = Portb.6
    '****************************
    Const Ds1307w = &HD0
    Const Ds1307r = &HD1


    Dim _sec As Byte
    Dim _min As Byte
    Dim _hour As Byte
    Dim _year As Word
    Dim Weekday As Byte
    '--------------
    Dim M_day As Word
    Dim Sh_day As Word
    Dim M_year As Word
    Dim Sh_year As Word
    Dim M_month As Word
    Dim Sh_month As Word
    Dim Kabise As Byte
    Dim Kole_roz_m As Word
    Dim Kole_roz_sh As Word
    '----------------
    Dim A1_day As Word
    Dim A1_month As Word
    Dim A1_year As Word
    Dim A1_hour As Byte
    Dim A1_min As Byte
    Dim Aselection As Byte
    A1_day = 0
    A1_year = 0
    A1_month = 0
    A1_hour = 0
    A1_min = 0

    Dim Z1 As String * 15
    Dim Z As String * 10
    Dim H As Byte
    Dim W As Word
    Dim Temperature As Single
    '-------------

    '********************************

    Dim Conter1 As Word
    Dim Conter2 As Word
    Dim Conter3 As Word
    Dim Conter4 As Word
    Dim Day_of_month(12) As Byte
    Day_of_month(1) = 31
    Day_of_month(2) = 28
    Day_of_month(3) = 31
    Day_of_month(4) = 30
    Day_of_month(5) = 31
    Day_of_month(6) = 30
    Day_of_month(7) = 31
    Day_of_month(8) = 31
    Day_of_month(9) = 30
    Day_of_month(10) = 31
    Day_of_month(11) = 30
    Day_of_month(12) = 31
    '----------------------

    Dim Temp1 As Integer
    Dim Temp2 As Integer
    Dim Temp3 As Word
    Dim Temp4 As Word
    Dim Temp5 As Byte

    '-------bUZZZZZ-----
    'Buzz Alias Pina.3
    Config Portc.3 = Output
    Portc.3 = 0

    '----------------------- keys
    Key_menu Alias Pinc.0
    Config Key_menu = Input
    Portc.0 = 1

    Key_incr Alias Pinc.1
    Config Key_incr = Input
    Portc.1 = 1

    Key_decr Alias Pinc.2
    Config Key_decr = Input
    Portc.2 = 1
    '-----------------------------------
    Dim Menu As Byte
    Dim Timer_1 As Word
    Dim Timer_2 As Word
    Dim P As String * 15
    P = " dlydavood"
    Dim S1 As String * 20
    Dim S As String * 20
    S1 = " dlydavood"
    Dim Blink_flag As Bit
    Dim Selection As Byte
    Dim X1_sec As String * 4
    Dim X2_min As String * 4
    Dim X3_hour As String * 4

    Dim X4_sh_day As String * 4
    Dim X5_sh_month As String * 4
    Dim X6_sh_year As String * 4

    Dim X7_m_day As String * 4
    Dim X8_m_month As String * 4
    Dim X9_m_year As String * 4
    '------------------------------------

    Cls
    Lcdat 4 , 1 , S1
    Waitms 500
    Gosub Read_date_time
    Gosub M_to_sh
    A1_day = Sh_day
    A1_month = Sh_month
    A1_min = _min - 3
    A1_hour = _hour
    A1_year = Sh_year
    Cls

    Do 'Loop Asli
    Gosub Read_date_time
    Gosub M_to_sh


    'damasang

    W = Getadc(1)

    Temperature = W / 2

    Lcdat 8 , 1 , "T:" ; Temperature ; " "
    '---------------------------------------------


    If A1_year = Sh_year Then
    If A1_month = Sh_month Then
    If A1_day = Sh_day Then
    If A1_hour = _hour Then
    If A1_min = _min Then
    Lcdat 8 , 120 , "A"
    End If
    If A1_min > _min Then
    Lcdat 8 , 120 , "A"
    End If
    End If
    If A1_hour > _hour Then
    Lcdat 8 , 120 , "A"
    End If
    End If
    If A1_day > Sh_day Then
    Lcdat 8 , 120 , "A"
    End If
    End If
    If A1_month > Sh_month Then
    Lcdat 8 , 120 , "A"
    End If
    End If


    If A1_year > Sh_year Then
    Lcdat 8 , 120 , "A"
    End If


    If A1_day = Sh_day And A1_month = Sh_month And A1_year = Sh_year And A1_hour = _hour And A1_min = _min Then

    Cls
    Lcdat 1 , 1 , "Alarm!!!!"
    Lcdat 3 , 1 , "Press Key_decr"
    Lcdat 4 , 59 , "button to"
    Lcdat 6 , 1 , "shut off"
    Lcdat 7 , 59 , "the alarm"
    Do
    Portc.3 = 1
    For H = 1 To 20
    If Key_decr = 0 Then Exit Do
    Waitms 10
    Next
    Portc.3 = 0
    For H = 1 To 20
    If Key_decr = 0 Then Exit Do
    Waitms 10
    Next
    Loop Until Key_decr = 0
    A1_min = A1_min - 2


    Portc.3 = 0


    Cls
    End If

    Lcdat 1 , 1 , P

    '--------------------2 raghami kardane date v time---------------
    X1_sec = Str(_sec)
    X1_sec = Format(x1_sec , "00&quot

    X2_min = Str(_min)
    X2_min = Format(x2_min , "00&quot

    X3_hour = Str(_hour)
    X3_hour = Format(x3_hour , "00&quot

    X4_sh_day = Str(sh_day)
    X4_sh_day = Format(x4_sh_day , "00&quot

    X5_sh_month = Str(sh_month)
    X5_sh_month = Format(x5_sh_month , "00&quot

    X6_sh_year = Str(sh_year)
    X6_sh_year = Format(x6_sh_year , "0000&quot

    X7_m_day = Str(m_day)
    X7_m_day = Format(x7_m_day , "00&quot

    X8_m_month = Str(m_month)
    X8_m_month = Format(x8_m_month , "00&quot

    X9_m_year = Str(m_year)
    X9_m_year = Format(x9_m_year , "0000&quot
    '----------------------------------------------------------------

    Lcdat 2 , 1 , "TIME: " ; X3_hour ; ":" ; X2_min ; ":" ; X1_sec
    Lcdat 4 , 1 , "D_SH: " ; X6_sh_year ; "/" ; X5_sh_month ; "/" ; X4_sh_day
    Lcdat 6 , 1 , "D_M_: " ; X9_m_year ; "/" ; X8_m_month ; "/" ; X7_m_day
    'If Sh_month <= 6 Then
    'If Sh_day = 31 Then
    'or
    'If Sh_month > 6 Then
    'If Sh_day = 30 Then
    ' Cls
    If _sec = 59 Then
    Waitms 300
    Cls
    Lcdat 1 , 1 , P
    Lcdat 2 , 1 , "TIME: " ; X3_hour ; ":" ; X2_min ; ":"
    Lcdat 4 , 1 , "D_SH: " ; X6_sh_year ; "/" ; X5_sh_month ; "/" ; X4_sh_day
    Lcdat 6 , 1 , "D_M_: " ; X9_m_year ; "/" ; X8_m_month ; "/" ; X7_m_day
    End If
    If _min = 59 Then
    Waitms 300
    Cls
    Lcdat 1 , 1 , P
    Lcdat 2 , 1 , "TIME: " ; X3_hour ; ": " ; ; ":" ; X1_sec
    Lcdat 4 , 1 , "D_SH: " ; X6_sh_year ; "/" ; X5_sh_month ; "/" ; X4_sh_day
    Lcdat 6 , 1 , "D_M_: " ; X9_m_year ; "/" ; X8_m_month ; "/" ; X7_m_day
    End If
    If _hour = 24 Then Cls

    '---------------------------- namayesh rozhaye hafte-------------------

    If Weekday = 0 Then Lcdat 8 , 80 , " SAT"
    If Weekday = 1 Then Lcdat 8 , 80 , " SUN"
    If Weekday = 2 Then Lcdat 8 , 80 , " MON"
    If Weekday = 3 Then Lcdat 8 , 80 , " TUE"
    If Weekday = 4 Then Lcdat 8 , 80 , " WED"
    If Weekday = 5 Then Lcdat 8 , 80 , " THU"
    If Weekday = 6 Then Lcdat 8 , 80 , " FRI"



    '---------------------------- WAIT AND READ KEY

    If Key_menu = 0 Then
    Waitus 10

    If Key_menu = 0 Then
    Cls
    Lcdat 4 , 45 , "MENU"

    Waitms 400
    Gosub Menu
    End If



    End If

    If Key_incr = 0 Then
    Waitus 10

    If Key_incr = 0 Then
    Cls
    Lcdat 4 , 24 , "ALARM-1-SET"

    Waitms 400
    Gosub Alarm1
    End If



    End If



    '------------------------------
    Loop


    Menu:

    Selection = 1
    Cls
    Do

    Incr Timer_1
    If Timer_1 > 5 Then
    Timer_1 = 0
    Toggle Blink_flag
    End If
    'Blink_flag = 0
    S1 = "TIME: "
    '-----------------------------
    If Selection = 1 And Blink_flag = 0 Then

    S1 = S1 + " "
    Else

    S = Str(_hour)
    S = Format(s , "00&quot
    S1 = S1 + S

    End If
    S1 = S1 + ":"
    '------------------------------
    If Selection = 2 And Blink_flag = 0 Then

    S1 = S1 + " "
    Else

    S = Str(_min)
    S = Format(s , "00&quot
    S1 = S1 + S

    End If
    S1 = S1 + ":"
    '------------------------------
    If Selection = 3 And Blink_flag = 0 Then

    S1 = S1 + " "
    Else

    S = Str(_sec)
    S = Format(s , "00&quot
    S1 = S1 + S

    End If


    Lcdat 1 , 1 , S1



    S1 = "DATE: "
    '--------------------------------
    If Selection = 4 And Blink_flag = 0 Then

    S1 = S1 + " "
    Else

    S = Str(sh_year)
    S = Format(s , "0000&quot
    S1 = S1 + S

    End If
    S1 = S1 + "/"
    '---------------------------------
    If Selection = 5 And Blink_flag = 0 Then

    S1 = S1 + " "
    Else

    S = Str(sh_month)
    S = Format(s , "00&quot
    S1 = S1 + S

    End If
    S1 = S1 + "/"
    '----------------------------------
    If Selection = 6 And Blink_flag = 0 Then

    S1 = S1 + " "
    Else

    S = Str(sh_day)
    S = Format(s , "00&quot
    S1 = S1 + S

    End If

    Lcdat 4 , 1 , S1





    If Key_menu = 0 Then
    Waitus 10
    If Key_menu = 0 Then Incr Selection
    End If


    '-----------------------------------
    If Key_incr = 0 Then
    Waitus 10
    If Key_incr = 0 Then

    If Selection = 1 Then Incr _hour
    If Selection = 2 Then Incr _min
    If Selection = 3 Then Incr _sec
    If Selection = 4 Then Incr Sh_year
    If Selection = 5 Then Incr Sh_month
    If Selection = 6 Then Incr Sh_day

    End If

    End If
    '------------------------------------
    If Key_decr = 0 Then
    Waitus 10
    If Key_decr = 0 Then

    If Selection = 1 Then Decr _hour
    If Selection = 2 Then Decr _min
    If Selection = 3 Then Decr _sec
    If Selection = 4 Then Decr Sh_year
    If Selection = 5 Then Decr Sh_month
    If Selection = 6 Then Decr Sh_day

    End If

    End If

    '--------------------------------------
    If _hour > 100 Then _hour = 24
    If _min > 100 Then _min = 59
    If _sec > 100 Then _sec = 59

    If _hour > 24 Then _hour = 00
    If _min > 59 Then _min = 00
    If _sec > 59 Then _sec = 00

    If Sh_year > 1470 Then Sh_year = 1390
    If Sh_month > 12 Then Sh_month = 1
    If Sh_day > 31 Then Sh_day = 1


    If Sh_year < 1390 Then Sh_year = 1470
    If Sh_month < 1 Then Sh_month = 12
    If Sh_day < 1 Then Sh_day = 31
    '---------------------------------------


    Waitms 40

    If Selection > 6 Then Exit Do

    Loop

    Cls
    Lcdat 4 , 40 , "saving"

    Wait 1
    Gosub Sh_to_m
    Gosub Setdate
    Gosub Settime
    Cls
    Return

    '----------------------------

    Alarm1:
    Cls
    Lcdat 1 , 40 , "Alarm1"
    Aselection = 1
    'Timer_1 = 0
    'Blink_flag = 0
    Do
    Incr Timer_1
    If Timer_1 > 5 Then
    Timer_1 = 0
    Toggle Blink_flag
    End If
    Z1 = "TIME: "
    '-----------------------------
    If Aselection = 1 And Blink_flag = 0 Then
    Z1 = Z1 + " "
    Else

    Z = Str(a1_hour)
    Z = Format(z , "00&quot
    Z1 = Z1 + Z

    End If
    Z1 = Z1 + ":"
    '------------------------------
    If Aselection = 2 And Blink_flag = 0 Then
    Z1 = Z1 + " "
    Else
    Z = Str(a1_min)
    Z = Format(z , "00&quot
    Z1 = Z1 + Z

    End If
    'Z1 = Z1 + ":"
    Lcdat 3 , 1 , Z1



    Z1 = "DATE: "
    '------------------------------
    If Aselection = 3 And Blink_flag = 0 Then
    Z1 = Z1 + " "
    Else
    Z = Str(a1_year)
    Z = Format(z , "0000&quot
    Z1 = Z1 + Z

    End If
    Z1 = Z1 + "/"
    '---------------------------------
    If Aselection = 4 And Blink_flag = 0 Then
    Z1 = Z1 + " "

    Else

    Z = Str(a1_month)
    Z = Format(z , "00&quot
    Z1 = Z1 + Z

    End If
    Z1 = Z1 + "/"
    '----------------------------------
    If Aselection = 5 And Blink_flag = 0 Then
    Z1 = Z1 + " "
    Else


    Z = Str(a1_day)
    Z = Format(z , "00&quot
    Z1 = Z1 + Z

    End If
    '-----------------

    Lcdat 6 , 1 , Z1


    If Key_menu = 0 Then
    Waitus 10
    If Key_menu = 0 Then Incr Aselection
    End If


    '-----------------------------------
    If Key_incr = 0 Then
    Waitus 10
    If Key_incr = 0 Then

    If Aselection = 1 Then Incr A1_hour
    If Aselection = 2 Then Incr A1_min
    If Aselection = 3 Then Incr A1_year
    If Aselection = 4 Then Incr A1_month
    If Aselection = 5 Then Incr A1_day

    End If

    End If
    '------------------------------------
    If Key_decr = 0 Then
    Waitus 10
    If Key_decr = 0 Then

    If Aselection = 1 Then Decr A1_hour
    If Aselection = 2 Then Decr A1_min
    If Aselection = 3 Then Decr A1_year
    If Aselection = 4 Then Decr A1_month
    If Aselection = 5 Then Decr A1_day

    End If

    End If

    '--------------------------------------
    If A1_hour > 100 Then A1_hour = 24
    If A1_min > 100 Then A1_min = 59

    If A1_hour > 24 Then A1_hour = 00
    If A1_min > 59 Then A1_min = 00

    If A1_year > 1470 Then A1_year = 1390
    If A1_month > 12 Then A1_month = 1
    If A1_day > 31 Then A1_day = 1


    If A1_year < 1390 Then A1_year = 1470
    If A1_month < 1 Then A1_month = 12
    If A1_day < 1 Then A1_day = 31
    '---------------------------------------


    Waitms 40

    If Aselection > 5 Then Exit Do

    Loop


    Cls
    Lcdat 4 , 40 , "saving"

    Wait 1
    Cls
    Return









    Read_date_time:
    I2cstart ' Generate start code
    I2cwbyte Ds1307w ' send address
    I2cwbyte 0 ' start address in 1307
    I2cstart ' Generate start code
    I2cwbyte Ds1307r ' send address
    I2crbyte _sec , Ack
    I2crbyte _min , Ack ' MINUTES
    I2crbyte _hour , Ack ' Hours
    I2crbyte Weekday , Ack ' Day of Week
    I2crbyte M_day , Ack ' Day of Month
    I2crbyte M_month , Ack ' Month of Year
    I2crbyte _year , Nack ' Year
    I2cstop
    _sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
    M_day = Makedec(m_day) : M_month = Makedec(m_month) : _year = Makedec(_year)
    M_year = 2000 + _year

    Weekday = Makedec(weekday)


    Return


    Setdate:

    _year = M_year - 2000
    M_day = Makebcd(m_day) : M_month = Makebcd(m_month) : _year = Makebcd(_year)
    Weekday = Makebcd(weekday)


    If Weekday > 6 Then Weekday = 0
    I2cstart ' Generate start code
    I2cwbyte Ds1307w ' send address
    I2cwbyte 3 ' starting address in 1307
    I2cwbyte Weekday
    I2cwbyte M_day ' Send Data to SECONDS
    I2cwbyte M_month ' MINUTES
    I2cwbyte _year ' Hours
    I2cstop


    Return


    Settime:
    _sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)

    I2cstart ' Generate start code
    I2cwbyte Ds1307w ' send address
    I2cwbyte 0 ' starting address in 1307
    I2cwbyte _sec ' Send Data to SECONDS
    I2cwbyte _min ' MINUTES
    I2cwbyte _hour ' Hours
    I2cstop
    Return



    M_to_sh:

    '----------------
    If M_kabise(m_year) = 0 Then
    Day_of_month(2) = 28
    Else
    Day_of_month(2) = 29
    End If
    '----------------

    Conter2 = M_month - 1
    Kole_roz_m = 0

    For Conter1 = 1 To Conter2
    Kole_roz_m = Kole_roz_m + Day_of_month(conter1)
    Next
    Kole_roz_m = Kole_roz_m + M_day

    '**********************************

    If Kole_roz_m > 79 Then

    Sh_year = M_year - 621
    Kole_roz_sh = Kole_roz_m - 79

    Else

    Sh_year = M_year - 622

    Temp4 = M_year - 1
    Temp5 = M_kabise(temp4)

    If Temp5 = 0 Then
    Kole_roz_sh = Kole_roz_m + 286
    Else
    Kole_roz_sh = Kole_roz_m + 287
    End If

    End If

    '**********************************

    Sh_month = 1

    '****************
    While Kole_roz_sh > 30

    If Sh_month < 7 Then
    Kole_roz_sh = Kole_roz_sh - 31
    Else
    Kole_roz_sh = Kole_roz_sh - 30
    End If

    Incr Sh_month

    Wend
    '***************
    '---------------
    If Kole_roz_sh = 0 Then

    Decr Sh_month
    If Sh_month < 7 Then
    Sh_day = 31
    Else
    Sh_day = 30
    End If
    Else
    Sh_day = Kole_roz_sh
    End If
    '---------------
    Return


    Sh_to_m:

    '------------------
    Kole_roz_sh = 0
    '------------------

    If Sh_month > 6 Then

    Kole_roz_sh = 186
    Temp4 = Sh_month - 7
    Temp4 = Temp4 * 30
    Kole_roz_sh = Kole_roz_sh + Temp4

    Else

    Temp4 = Sh_month - 1
    Temp4 = Temp4 * 31
    Kole_roz_sh = Kole_roz_sh + Temp4

    End If
    Kole_roz_sh = Kole_roz_sh + Sh_day

    '****************************
    If Kole_roz_sh > 286 Then

    M_year = Sh_year + 622
    Kole_roz_m = Kole_roz_sh - 286

    Else

    M_year = Sh_year + 621
    Kole_roz_m = Kole_roz_sh + 79

    End If
    '**************************
    Temp5 = M_kabise(m_year)

    If Temp5 = 0 Then
    Day_of_month(2) = 28
    Else
    Day_of_month(2) = 29
    End If

    '----------------

    For M_month = 1 To 12

    If Kole_roz_m < 31 Then Exit For
    Kole_roz_m = Kole_roz_m - Day_of_month(m_month)

    Next


    If Kole_roz_m > Day_of_month(m_month) Then

    Kole_roz_m = Kole_roz_m - Day_of_month(conter1)
    Incr M_month

    End If

    M_day = Kole_roz_m

    Return


    End




    Function M_kabise(byref Sal As Word)as Byte

    Local T1 As Integer
    Local T2 As Integer
    Local T3 As Integer
    Local B As Byte
    '=========================
    T1 = Sal Mod 4
    T2 = Sal Mod 100
    T3 = Sal Mod 400
    B = 0
    '=========================
    '------
    If T1 = 0 And T2 <> 0 Then
    B = 1
    End If
    '------
    If T2 = 0 And T3 = 0 Then
    B = 1
    End If
    '------
    M_kabise = B

    End Function


    Function Sh_kabise(byref Sal As Word)as Byte

    Local T1 As Integer
    Local B As Byte
    '==================
    T1 = Sal Mod 33
    B = 0
    '==================
    '------
    If T1 = 1 Or T1 = 5 Or T1 = 9 Or T1 = 13 Or T1 = 17 Or T1 = 22 Or _
    T1 = 26 Or T1 = 30 Then

    B = 1

    End If
    '------
    Sh_kabise = B

    End Function

    دیدگاه

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