با سلام. اخیرا برد یک ساعت دیجیتال با DS1307 و ATMEGA16 طراحی کردم. اولش خوب کار می کرد اما الان بعد از گذشت حدود 3 ساعت از کار دیگه میکرو قادر به قرائت زمان از روی RTC نیست؟ آیا نرخ نمونه برداری بالا و سریع از این آی سی ممکنه منجر به هنگ گردنش بشه؟
فرکانس پردازنده : 8 مگاهرتز
زبان برنامه نویسی : بسکام
تکنیک : روش سون سگمنت در حلقه تکرار 40 مرتبه
برنامه :
[code=vb]
'IN THE NAME OF ALLAH
$regfile = "m16def.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 10
$framesize = 40
Config Portb = Output
Config Portd = Output
'Config Porta.2 = Input
Config Sda = Porta.1
Config Scl = Porta.0
Const Ds1307w = &HD0
Const Ds1307r = &HD1
Dim A As Word
Dim I As Integer
Dim C As Single
C = 0
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 M_month As Word
'_sec = 00
'_min = 40
'_hour = 16
'_sec = Makebcd(_sec)
'_min = Makebcd(_min)
'_hour = Makebcd(_hour)
'I2cstart
'I2cwbyte Ds1307w
'I2cwbyte 0
'I2cwbyte _sec
'I2cwbyte _min
'I2cwbyte _hour
'I2cstop
'first time read
'/ first time read
'Start Timer1
'-------------------------vars
Dim Sy As Integer
Dim Sd As Integer
Dim My As Integer
Dim Md As Integer
Dim Hy As Integer
Dim Hd As Integer
Dim Tmp1 As Single
Dim Tmp2 As Single
Dim Tmp3 As Single
Dim Tmp4 As Single
Dim Tmp5 As Single
Dim Tmp6 As Single
Dim Tmp7 As Single
Dim Tmp8 As Single
Dim Tmp9 As Single
Dim Tmp10 As Single
Dim Tmp11 As Single
Dim Tmp12 As Single
Dim Tmp13 As Single
Dim Tmp14 As Single
'Effects
For I = 0 To 200
'A
Portb = &B00100000
Portd = &B00101000
Waitms 2
'L
Portb = &B00010000
Portd = &B11011010
Waitms 2
'L
Portb = &B00001000
Portd = &B11011010
Waitms 2
'A
Portb = &B00000100
Portd = &B00101000
Waitms 2
'H
Portb = &B00000010
Portd = &B10101000
Waitms 2
Next
Portb = &H00
Portd = &B11111101
Portb = &HFF
Waitms 1700
Portd = &B11110111
Waitms 1800
Restart:
Waitms 400
'7SEG TEST
Portd = &H00
Waitms 10
Portb = &B00000001
Waitms 100
Portb = &B00000010
Waitms 100
Portb = &B00000100
Waitms 100
Portb = &B00001000
Waitms 100
Portb = &B00010000
Waitms 100
Portb = &B00100000
Waitms 100
Do
Gosub R_de_t
Tmp1 = _hour
Tmp2 = _hour
Tmp3 = _min
Tmp4 = _min
Tmp5 = _sec
Tmp6 = _sec
'Second
Tmp7 = Tmp5 / 10
Sd = Int(tmp7)
Tmp8 = Sd * 10
Sy = Tmp6 - Tmp8
'Minute
Tmp9 = Tmp3 / 10
Md = Int(tmp9)
Tmp10 = Md * 10
My = Tmp4 - Tmp10
'Hour
Tmp11 = Tmp1 / 10
Hd = Int(tmp11)
Tmp12 = Hd * 10
Hy = Tmp2 - Tmp12
For I = 0 To 40
'hour
Portb = &B00010000
Portd = Lookup(hy , Numbers)
Waitms 2
Portb = &B00100000
Portd = Lookup(hd , Numbers)
Waitms 2
'min
Portb = &B00000100
Portd = Lookup(my , Numbers)
Waitms 2
Portb = &B00001000
Portd = Lookup(md , Numbers)
Waitms 2
'sec
Portb = &B00000001
Portd = Lookup(sy , Numbers)
Waitms 2
Portb = &B00000010
Portd = Lookup(sd , Numbers)
Waitms 2
Next
Waitms 2
Loop
End
R_de_t:
I2cstart
I2cwbyte Ds1307w
I2cwbyte 0
I2cstart
I2cwbyte Ds1307r
I2crbyte _sec , Ack
I2crbyte _min , Ack
I2crbyte _hour , Ack
I2crbyte Weekday , Ack
I2crbyte M_day , Ack
I2crbyte M_month , Ack
I2crbyte _year , Nack
I2cstop
_sec = Makedec(_sec)
_min = Makedec(_min)
_hour = Makedec(_hour)
Return
Numbers:
Data &B00001010 '0
Data &B10101111 '1
Data &B00011100 '2
Data &B00001101 '3
Data &B10101001 '4
Data &B01001001 '5
Data &B01001000 '6
Data &B00101011 '7
Data &B00001000 '8
Data &B00001001 '9
[/code]
فرکانس پردازنده : 8 مگاهرتز
زبان برنامه نویسی : بسکام
تکنیک : روش سون سگمنت در حلقه تکرار 40 مرتبه
برنامه :
[code=vb]
'IN THE NAME OF ALLAH
$regfile = "m16def.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 10
$framesize = 40
Config Portb = Output
Config Portd = Output
'Config Porta.2 = Input
Config Sda = Porta.1
Config Scl = Porta.0
Const Ds1307w = &HD0
Const Ds1307r = &HD1
Dim A As Word
Dim I As Integer
Dim C As Single
C = 0
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 M_month As Word
'_sec = 00
'_min = 40
'_hour = 16
'_sec = Makebcd(_sec)
'_min = Makebcd(_min)
'_hour = Makebcd(_hour)
'I2cstart
'I2cwbyte Ds1307w
'I2cwbyte 0
'I2cwbyte _sec
'I2cwbyte _min
'I2cwbyte _hour
'I2cstop
'first time read
'/ first time read
'Start Timer1
'-------------------------vars
Dim Sy As Integer
Dim Sd As Integer
Dim My As Integer
Dim Md As Integer
Dim Hy As Integer
Dim Hd As Integer
Dim Tmp1 As Single
Dim Tmp2 As Single
Dim Tmp3 As Single
Dim Tmp4 As Single
Dim Tmp5 As Single
Dim Tmp6 As Single
Dim Tmp7 As Single
Dim Tmp8 As Single
Dim Tmp9 As Single
Dim Tmp10 As Single
Dim Tmp11 As Single
Dim Tmp12 As Single
Dim Tmp13 As Single
Dim Tmp14 As Single
'Effects
For I = 0 To 200
'A
Portb = &B00100000
Portd = &B00101000
Waitms 2
'L
Portb = &B00010000
Portd = &B11011010
Waitms 2
'L
Portb = &B00001000
Portd = &B11011010
Waitms 2
'A
Portb = &B00000100
Portd = &B00101000
Waitms 2
'H
Portb = &B00000010
Portd = &B10101000
Waitms 2
Next
Portb = &H00
Portd = &B11111101
Portb = &HFF
Waitms 1700
Portd = &B11110111
Waitms 1800
Restart:
Waitms 400
'7SEG TEST
Portd = &H00
Waitms 10
Portb = &B00000001
Waitms 100
Portb = &B00000010
Waitms 100
Portb = &B00000100
Waitms 100
Portb = &B00001000
Waitms 100
Portb = &B00010000
Waitms 100
Portb = &B00100000
Waitms 100
Do
Gosub R_de_t
Tmp1 = _hour
Tmp2 = _hour
Tmp3 = _min
Tmp4 = _min
Tmp5 = _sec
Tmp6 = _sec
'Second
Tmp7 = Tmp5 / 10
Sd = Int(tmp7)
Tmp8 = Sd * 10
Sy = Tmp6 - Tmp8
'Minute
Tmp9 = Tmp3 / 10
Md = Int(tmp9)
Tmp10 = Md * 10
My = Tmp4 - Tmp10
'Hour
Tmp11 = Tmp1 / 10
Hd = Int(tmp11)
Tmp12 = Hd * 10
Hy = Tmp2 - Tmp12
For I = 0 To 40
'hour
Portb = &B00010000
Portd = Lookup(hy , Numbers)
Waitms 2
Portb = &B00100000
Portd = Lookup(hd , Numbers)
Waitms 2
'min
Portb = &B00000100
Portd = Lookup(my , Numbers)
Waitms 2
Portb = &B00001000
Portd = Lookup(md , Numbers)
Waitms 2
'sec
Portb = &B00000001
Portd = Lookup(sy , Numbers)
Waitms 2
Portb = &B00000010
Portd = Lookup(sd , Numbers)
Waitms 2
Next
Waitms 2
Loop
End
R_de_t:
I2cstart
I2cwbyte Ds1307w
I2cwbyte 0
I2cstart
I2cwbyte Ds1307r
I2crbyte _sec , Ack
I2crbyte _min , Ack
I2crbyte _hour , Ack
I2crbyte Weekday , Ack
I2crbyte M_day , Ack
I2crbyte M_month , Ack
I2crbyte _year , Nack
I2cstop
_sec = Makedec(_sec)
_min = Makedec(_min)
_hour = Makedec(_hour)
Return
Numbers:
Data &B00001010 '0
Data &B10101111 '1
Data &B00011100 '2
Data &B00001101 '3
Data &B10101001 '4
Data &B01001001 '5
Data &B01001000 '6
Data &B00101011 '7
Data &B00001000 '8
Data &B00001001 '9
[/code]
دیدگاه