اطلاعیه

Collapse
No announcement yet.

کمک(ساعت و تاریخ با DS1307 در bascom)

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

    کمک(ساعت و تاریخ با DS1307 در bascom)

    سلام

    من دو تا برنامه نیاز دارم که خیلی ممنون می شم اگه آماده دارین برام بزارین

    1) ساعت و تاریخ با DS1307 در bascom

    2)ساعت و تاریخ با RTC داخلی میکرو در bascom

    خیلی ممنون میشم

    #2
    پاسخ : کمک(ساعت و تاریخ با DS1307 در bascom)

    [code=vb]regfile = "m16def.dat"
    $crystal = 8000000
    '$baud = 19200
    $lib "mcsbyte.lbx" ' for smaller code
    $lib "ds1307clock.lib" ' modified lib
    $framesize = 16
    $hwstack = 24
    $swstack = 16

    Config Lcdpin = Pin , Db4 = Pinb.4 , Db5 = Pinb.5 , Db6 = Pinb.6 , Db7 = _
    Pinb.7 , Rs = Pinb.2 , E = Pinb.3
    Config Lcd = 16 * 2

    Config Pina.4 = Input
    Config Pina.5 = Input
    Config Pina.6 = Input

    'configure the scl and sda pins
    Config Sda = Portd.6
    Config Scl = Portd.5

    Config Portd.6 = Output
    Config Portd.5 = Output


    'address of ds1307
    Const Ds1307w = &HD0 ' Addresses of Ds1307 clock
    Const Ds1307r = &HD1

    Config Clock = User ' this will dim the bytes automatic
    'dim other needed variables
    Dim Weekday As Byte
    Dim S As Byte
    Dim M As Byte
    Dim V As Byte
    Dim H As Byte

    Enable Interrupts


    Ok Alias Pina.4
    Up Alias Pina.5
    Down Alias Pina.6

    'Print "DS1307"
    'Waitms 100
    ' assigning the time will call the SetTime routine
    'Time$ = "2359" ' to watch the day changing value
    'Date$ = "11-13-02" ' 13 november 2002

    Hom:

    'Start Timer0

    Cursor Off
    Cls
    Do
    Home

    Lcd Date$
    Lowerline
    Lcd Time$
    Waitms 500
    If Ok = 0 Then
    Waitms 150
    Goto Settime
    End If
    **********************************'
    '(
    if _hour=13 then
    _hour=0
    endif
    &#039
    *********************************'
    Loop
    'called from ds1307clock.lib
    Getdatetime:
    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 _day , Ack ' Day of Month
    I2crbyte _month , Ack ' Month of Year
    I2crbyte _year , Nack ' Year
    I2cstop
    _sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
    _day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
    Return

    '********************* settime **********************


    Settime:


    Cls
    Waitms 100

    Do

    If V = 0 Then

    Home

    Lcd " >time date"
    Lowerline
    Lcd " exit "

    End If

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

    If V = 1 Then

    Home
    Lcd " time >date"
    Lowerline
    Lcd " exit "

    End If

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

    If V = 2 Then

    Home
    Lcd " time date"
    Lowerline
    Lcd ">exit "

    End If

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

    If Up = 0 Then

    Waitms 150
    Incr V

    If V = 3 Then V = 0

    End If
    '**************************************

    If Down = 0 Then
    Waitms 150

    If V = 0 Then
    V = 2
    Else
    Decr V
    End If

    End If

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

    If Ok = 0 Then
    Waitms 100
    If V = 0 Then Gosub Tim
    If V = 1 Then Gosub Setdate
    If V = 2 Then Gosub Hom
    End If

    Loop

    '***************** set hour ****************
    Tim:

    'I2cwbyte _hour

    Cls

    S = _sec
    M = _min ' MINUTES
    H = _hour ' MINUTES

    Do

    Home
    Lcd "(H) M S"
    Lowerline
    Lcd H ; " " ; M ; " " ; S ; " "

    If Down = 0 Then

    Waitms 120
    Decr H

    End If

    If Up = 0 Then

    Waitms 120
    Incr H

    End If

    If Ok = 0 Then

    Waitms 120

    Gosub Timm

    End If

    If H = 25 Then H = 0
    If H = 255 Then H = 24

    Loop
    ' Send Data to SECONDS
    '*************** set min **************


    Timm:

    'I2cwbyte _min


    Cls
    Do

    Home
    Lcd " H (M) S"
    Lowerline
    Lcd H ; " " ; M ; " " ; S ; " "

    If Down = 0 Then

    Waitms 120
    Decr M

    End If

    If Up = 0 Then

    Waitms 120
    Incr M

    End If

    If Ok = 0 Then

    Waitms 120

    Gosub Tims

    End If

    If M = 60 Then M = 0
    If M = 255 Then M = 59

    Loop

    '******************* set sec **********************

    Tims:

    ' I2cwbyte _sec

    Cls
    Do

    Home
    Lcd " H M (S)"
    Lowerline
    Lcd H ; " " ; M ; " " ; S ; " "

    If Down = 0 Then

    Waitms 120
    Decr S

    End If

    If Up = 0 Then

    Waitms 120
    Incr S

    End If

    If Ok = 0 Then

    Waitms 120

    _sec = S
    _min = M
    _hour = H

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

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

    ' _sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)

    Goto Hom

    End If

    If S = 60 Then S = 0
    If S = 255 Then S = 59

    Loop

    '************************************* set date **************************************

    Setdate:


    Cls

    S = _day
    M = _month
    H = _year


    Do

    Home
    Lcd "(d) M y"
    Lowerline
    Lcd H ; " " ; M ; " " ; S ; " "

    If Down = 0 Then

    Waitms 100
    Decr H

    End If

    If Up = 0 Then

    Waitms 100
    Incr H

    End If

    If Ok = 0 Then

    Waitms 100
    Gosub Month

    End If
    Loop

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

    Month:

    Cls
    Do

    Home
    Lcd " d (M) y"
    Lowerline
    Lcd H ; " " ; M ; " " ; S ; " "

    If Down = 0 Then

    Waitms 100
    Decr M

    End If


    If Up = 0 Then

    Waitms 100
    Incr M

    End If

    If Ok = 0 Then

    Waitms 100
    Gosub Day

    End If

    If M = 13 Then M = 0
    If M = 255 Then M = 12

    Loop

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

    Day:

    Cls
    Do

    Home
    Lcd " d M (y)"
    Lowerline
    Lcd H ; " " ; M ; " " ; S ; " "

    If Down = 0 Then

    Waitms 100
    Decr S

    End If

    If Up = 0 Then

    Waitms 100
    Incr S

    End If

    If Ok = 0 Then

    Waitms 100

    _day = S
    _month = M
    _year = H

    _day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)

    I2cstart ' Generate start code
    I2cwbyte Ds1307w ' send address
    I2cwbyte 4 ' starting address in 1307
    I2cwbyte _day ' Send Data to SECONDS
    I2cwbyte _month ' MINUTES
    I2cwbyte _year ' Hours
    I2cstop

    Gosub Hom

    End If

    If S = 31 Then S = 0
    If S = 255 Then S = 30

    Loop
    [/code]
    بیا برادر برو اول تشکر بعدم حال کن :mrgreen: اگه سوالی بود در خدمتم
    { خلاف قوانین - پاک شد }

    دیدگاه


      #3
      پاسخ : کمک(ساعت و تاریخ با DS1307 در bascom)

      سلام

      ممنون زحمت کشیدین. میشه یکم توضیح بدین آخه من باید به کدوم پایه DAS17 ذو وصل کنم lcd رو با کدوم پایه

      و.... آخه من با PIC اون با زبان c کار کردم. اگه کمک کنی ممنونت میشم. مثلا شماتیک یا فایل پروتوسش رو بزاری البته من باید خودم یه تغییراتی توش بدم تا مثلا وقتی به یه ساعت خاص رسید یه پایه رو یک یا صفر کنه.

      دیدگاه


        #4
        پاسخ : کمک(ساعت و تاریخ با DS1307 در bascom)

        داداش من ما یدونه تایپک ds1307 داریم بیاین اونجا بگین منم نتیجه گرفتم بابا میدونم چه دردی دارین یه تایپک تخصصی کنیم
        4 صفه پاسخ داره :nice:
        http://www.eca.ir/forum2/index.php?topic=38492.0
        [move][img width=133 height=100]http://bargiri.persiangig.com/aks/0.306310001356499787_taknaz_ir.gif[/img][/move]

        دیدگاه


          #5
          پاسخ : کمک(ساعت و تاریخ با DS1307 در bascom)

          راست میگه دوست عزیز بیا اونجا من کل برنامه رو براتون تشریح میکنم هر سوالی دارین اونجا بپرسین
          { خلاف قوانین - پاک شد }

          دیدگاه

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