$regfile = "ATtiny2313.DAT" $crystal = 1000000 $baud = 9600 $hwstack = 32 $swstack = 10 $framesize = 40 $lib "lcd4.lbx" $lib "mcsbyte.lbx" Enable Interrupts 'Декларируем функции Declare Sub Enterdatetime() Declare Sub Getkey() Declare Sub Menu() Config Lcdpin = Pin , Rs = Portb.0 , E = Portb.2 , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portd.3 , Db7 = Portd.4 Config Lcd = 16 * 2 Cursor Off Cls Config Sda = Portd.1 Config Scl = Portd.0 Config Clock = User Config Date = Dmy , Separator = . Config Pind.2 = Input Config Pind.3 = Input Config Pind.4 = Input Config Pind.5 = Input Set Portd.2 Set Portd.3 Set Portd.4 Set Portd.5 Portd.2 = 1 Portd.3 = 1 Portd.4 = 1 Portd.5 = 1 Cn Alias Pind.2 'КНОПКА КУРСОР ВНИЗ Cv Alias Pind.3 'КНОПКА КУРСОР ВЕРХ Vv Alias Pind.4 'КНОПКА ВВОД M Alias Pind.5 'КНОПКА МЕНЮ 'декларируем переменные Dim J1 As Byte Dim M1 As Byte Dim D1 As Byte Dim H1 As Byte Dim Min1 As Byte Dim Aa As Byte Dim X1 As Byte Dim Chr_code As Byte 'address of ds1307 Const Ds1307w = &HD0 ' Addresses of Ds1307 clock Const Ds1307r = &HD1 'Основной бесконечный цикл программы Cls Do Locate 1 , 1 Lcd Time$ Locate 2 , 1 Lcd Date$ If M = 0 Then Gosub Menu End If Loop End '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 Setdate: _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 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 End Sub Enterdatetime() Cls X1 = 08 Aa = 0 Do If X1 > 50 Then X1 = 8 If X1 < 8 Then X1 = 50 Locate 1 , 1 Lcd "©cїaЅoієa" 'Установка Locate 2 , 1 Lcd "ґoгa" 'года Getkey J1 = X1 Loop Until Aa = 1 Cls Aa = 0 X1 = 11 Do If X1 > 12 Then X1 = 1 If X1 < 1 Then X1 = 12 Locate 1 , 1 Lcd "©cїaЅoієa" 'Установка Locate 2 , 1 Lcd "јecЗеa:" ; X1 ; " " 'месяца Getkey M1 = X1 Loop Until Aa = 1 Cls Aa = 0 X1 = 1 Do If X1 > 31 Then X1 = 1 If X1 < 1 Then X1 = 31 Locate 1 , 1 Lcd "©cїaЅoієa" 'Установка Locate 2 , 1 Lcd "гЅЗ:" ; X1 ; " " 'дня Getkey D1 = X1 Loop Until Aa = 1 _year = J1 _month = M1 _day = D1 Gosub Setdate Cls Aa = 0 X1 = 12 Do If X1 > 23 Then X1 = 0 If X1 < 0 Then X1 = 23 Locate 1 , 1 Lcd "©cїaЅoієa" 'Установка Locate 2 , 1 Lcd "Аacoі:" ; X1 ; " " 'часов Getkey H1 = X1 Loop Until Aa = 1 Cls Aa = 0 X1 = 30 Do If X1 > 59 Then X1 = 0 If X1 < 1 Then X1 = 59 Locate 1 , 1 Lcd "©cїaЅoієa" 'Установка Locate 2 , 1 Lcd "јёЅyї:" ; X1 ; " " 'минут Getkey Min1 = X1 Loop Until Aa = 1 _hour = H1 _min = Min1 _sec = 0 Gosub Settime End Sub Sub Getkey() Waitms 300 If Cv = 0 Then Incr X1 If Cn = 0 Then Decr X1 If Vv = 0 Then Aa = 1 Else Aa = 0 End If End Sub Sub Menu() Aa = 0 X1 = 0 Getkey Enterdatetime Cls End Sub End