سلام دوستان.
من یه برنامه ساعت با avr و سون سگمنت دارم. می خوام در برنامه وقتی به یه ساعت خاصی که خودم تعریف کرده ام برام زنگ بزنه. کل برنامه رو گذاشتم. باید چکار کنم؟
کل برنامه با فایل پروتوس هم گذاشتم.
لطفا کمکم کنید.
http://www.uplooder.net/cgi-bin/dl.c...ed4b1a3b54df36
من یه برنامه ساعت با avr و سون سگمنت دارم. می خوام در برنامه وقتی به یه ساعت خاصی که خودم تعریف کرده ام برام زنگ بزنه. کل برنامه رو گذاشتم. باید چکار کنم؟
کل برنامه با فایل پروتوس هم گذاشتم.
لطفا کمکم کنید.
http://www.uplooder.net/cgi-bin/dl.c...ed4b1a3b54df36
کد:
[left]$regfile "m32def.dat"
$crystal = 8000000
'Config Lcd = 16 * 2
'Config Lcdpin = Pin , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5 , E = Porta.1 , Rs = Porta.0
'***************************************
'********* EBRAHIM KHAVANINZADEH********
'********* http://ebka.persianblog.ir***
'**********09373663936******************
Config Sda = Portc.1
Config Scl = Portc.0
Const Ds1307w = &HD0
Const Ds1307r = &HD1
Config Portc.5 = Output , Portc.6 = Output
Config Portb = Output : Config Portd = Output
Ddrc.2 = 0 : Ddrc.3 = 0 : Ddrc.4 = 0 ': Ddrc.5 = 1 : Ddrc.6 = 1
: Dim N As Byte , _wait As Byte
A Alias Portd.0 : B Alias Portd.1 : C Alias Portd.2 : D Alias Portd.3
E Alias Portd.4 : F Alias Portd.5 : G Alias Portd.6 : H Alias Portd.7
One Alias Portc.5 : Two Alias Portc.6
: Dim _hour As Byte , _minet As Byte , _sece As Byte , X As Byte ,
: Dim Day As Byte , Week As Byte , Mon As Byte , Yaer As Word , Year As Word
Cursor Off
: Dim _min(3) As Byte , Hour(3) As Byte , Sece(3) As Byte , _day(3) As Byte , _mon(3) As Byte
Shoro:
_wait = 5
Cls
Do
Gosub _data
Gosub Taghsim
Gosub Segment
If Pinc.3 = 0 Then Jmp Tanzim
'Home
'Lcd Hour(1) ; Hour(3) ":" ; _min(1) ; _min(3)
Loop
Ebi:
'Data 63 , 6 , 91 , 79 , 102 , 109 , 125 , 7 , 127 , 111
Data 126 , 48 , 109 , 121 , 51 , 91 , 95 , 112 , 127 , 123
'Data &B01111110 , &B00110000 , &B01101101 , &B01111001 , &B00110011 , &B01011011 , &B01011111 , &B01110000 , &B01111111 , &B01111011
Segment:
Set Two : Reset One : Portd = &B11111110
Portb = Lookup(_mon(1) , Ebi)
Waitms _wait
: Portd = &B11111101
Portb = Lookup(_mon(3) , Ebi)
Waitms _wait
: Portd = &B11111011
Portb = Lookup(_day(1) , Ebi)
Waitms _wait
: Portd = &B11110111
Portb = Lookup(_day(3) , Ebi)
Waitms _wait
Set One : Reset Two : E = 0 : F = 1 : G = 1 : H = 1 ' Portd = &B11100000
Portb = Lookup(hour(1) , Ebi)
Waitms _wait
: E = 1 : F = 0 : G = 1 : H = 1 'Portd = &B11010000
Portb = Lookup(hour(3) , Ebi)
Waitms _wait
: E = 1 : F = 1 : G = 0 : H = 1 ' Portd = &B10110000
Portb = Lookup(_min(1) , Ebi)
Waitms _wait
: E = 1 : F = 1 : G = 1 : H = 0 'Portd = &B01110000
Portb = Lookup(_min(3) , Ebi)
Waitms _wait
'Set Two : Reset One : Portd = &B11111110
' Portb = Lookup(n , Ebi)
' Incr N : If N > 9 Then N = 0
' Waitms 400
Return
Zaman:
If _hour > 23 And _hour < 25 Then _hour = 0
If _hour < 0 Or _hour > 254 Then _hour = 23
If _minet > 59 And _minet < 61 Then _minet = 0
If _minet > 254 Or _minet < 0 Then _minet = 59
If Mon > 12 Then Mon = 1
If Mon < 1 Then Mon = 12
If Day > 31 Then Day = 1
If Year > 2020 Then Year = 2012
If _sece > 59 And _sece < 61 Then _sece = 0
If _sece > 254 Or _sece < 0 Then _sece = 59
If _minet > 60 Then _sece = 0
'If Year > 60 Then _sece = 0
' If _sece > 60 Then _sece = 0
Return
Taghsim:
'------------------------------
_min(1) = _minet / 10
_min(2) = _min(1) * 10
_min(3) = _minet - _min(2)
'------------------------------
Hour(1) = _hour / 10
Hour(2) = Hour(1) * 10
Hour(3) = _hour - Hour(2)
'---------------------------
_day(1) = Day / 10
_day(2) = _day(1) * 10
_day(3) = Day - _day(2)
'------------------------------
_mon(1) = Mon / 10
_mon(2) = _mon(1) * 10
_mon(3) = Mon - _mon(2)
'---------------------------
Return
_data:
I2cstart
I2cwbyte Ds1307w
I2cwbyte 0
I2cstart
I2cwbyte Ds1307r
I2crbyte _sece , Ack
I2crbyte _minet , Ack
I2crbyte _hour , Ack
I2crbyte Week , Ack
I2crbyte Day , Ack
I2crbyte Mon , Ack
I2crbyte Year , Nack
I2cstop
_sece = Makedec(_sece) : _minet = Makedec(_minet) : _hour = Makedec(_hour)
Week = Makedec(week) : Day = Makedec(day) : Mon = Makedec(mon) : Year = Makedec(year)
If _minet > 59 Then _minet = 0
If _hour > 23 Then _hour = 0
Return
Tanzim:
Portd = &B11111111
While Pinc.3 = 0
Wend
Do
If Pinc.2 = 0 Then : Waitms 200 : Incr _hour
Elseif Pinc.4 = 0 Then : Waitms 200 : Decr _hour
Elseif Pinc.3 = 0 Then : Jmp Daghighe : End If
Gosub Zaman
Gosub Taghsim
Set One : Reset Two : Portd = &B11100000 ': E = 0 : F = 1 : G = 1 : H = 1 '
Portb = Lookup(hour(1) , Ebi)
Waitms _wait
Portd = &B11010000 ': E = 1 : F = 0 : G = 1 : H = 1 '
Portb = Lookup(hour(3) , Ebi)
Waitms _wait
'Gosub Segment
Loop
Daghighe:
Portd = &B11111111
While Pinc.3 = 0
Wend
Do
If Pinc.2 = 0 Then : Waitms 200 : Incr _minet
Elseif Pinc.4 = 0 Then : Waitms 200 : Decr _minet
Elseif Pinc.3 = 0 Then : Jmp Mah : End If
Gosub Zaman
Gosub Taghsim
Set One : Reset Two : Portd = &B10110000 ' E = 1 : F = 1 : G = 0 : H = 1 '
Portb = Lookup(_min(1) , Ebi)
Waitms _wait
Portd = &B01110000 ' : E = 1 : F = 1 : G = 1 : H = 0 '
Portb = Lookup(_min(3) , Ebi)
Waitms _wait
Loop
Mah:
While Pinc.3 = 0
Wend
Do
If Pinc.2 = 0 Then : Waitms 200 : Incr Mon
Elseif Pinc.4 = 0 Then : Waitms 200 : Decr Mon
Elseif Pinc.3 = 0 Then : Jmp Roz : End If
Gosub Zaman
Gosub Taghsim
Set Two : Reset One : Portd = &B11111110
Portb = Lookup(_mon(1) , Ebi)
Waitms _wait
: Portd = &B11111101
Portb = Lookup(_mon(3) , Ebi)
Waitms _wait
Loop
Roz:
While Pinc.3 = 0
Wend
Do
If Pinc.2 = 0 Then : Waitms 200 : Incr Day
Elseif Pinc.4 = 0 Then : Waitms 200 : Decr Day
Elseif Pinc.3 = 0 Then : Jmp Save : End If
Gosub Zaman
Gosub Taghsim
Set Two : Reset One : Portd = &B11111011
Portb = Lookup(_day(1) , Ebi)
Waitms _wait
: Portd = &B11110111
Portb = Lookup(_day(3) , Ebi)
Waitms _wait
Loop
Save:
For X = 0 To 20
Set One : Reset Two : Portd = &B11100000 ': E = 0 : F = 1 : G = 1 : H = 1 '
Portb = &B1011011 'S
Waitms _wait
Portd = &B11010000 ': E = 1 : F = 0 : G = 1 : H = 1 '
Portb = &B1110111 'A
Waitms _wait
: Portd = &B10110000 ' E = 1 : F = 1 : G = 0 : H = 1 '
Portb = &B0111110 'V
Waitms _wait
Portd = &B01110000 ' : E = 1 : F = 1 : G = 1 : H = 0 '
Portb = &B1001111 'E
Waitms _wait
Set Two : Reset One : Portd = &B11111110
Portb = &B1011011
Waitms _wait
: Portd = &B11111101
Portb = &B1110111
Waitms _wait
: Portd = &B11111011
Portb = &B0111110
Waitms _wait
: Portd = &B11110111
Portb = &B1001111
Waitms _wait
Next
Portb = 0 : Portd = 1
_sece = Makebcd(_sece) : _minet = Makebcd(_minet) : _hour = Makebcd(_hour)
I2cstart
I2cwbyte Ds1307w
I2cwbyte 0
I2cwbyte _sece
I2cwbyte _minet
I2cwbyte _hour
I2cstop
Waitms 200
Year = Makebcd(year) : Mon = Makebcd(mon) : Day = Makebcd(day)
I2cstart
I2cwbyte Ds1307w
I2cwbyte 4
I2cwbyte Day
I2cwbyte Mon
I2cwbyte Year
I2cstop
Goto Shoro[/left]

