$regfile = "attiny2313.dat" $crystal = 8000000 Dim Count As Byte Dim Number(4) As Integer Dim Pointmem As Byte Dim Point As Bit Dim Mine As Byte Dim Hour As Byte Dim Seco As Byte Config Porta.1 = Output Porta.1 = 1 Waitms 10 Porta.1 = 0 Waitms 70 Porta.1 = 1 Waitms 10 Porta.1 = 0 Config Portb = Output Config Porta.0 = Output Config Portd.2 = Output Config Portd.3 = Output Config Portd.6 = Output Config Sda = Portd.5 Config Scl = Portd.4 Config Pind.0 = Input Portd.0 = 1 Config Pind.1 = Input Portd.1 = 1 Config Timer1 = Timer , Prescale = 64 On Timer1 Awake: Config Timer0 = Timer , Prescale = 64 On Ovf0 Refresh Dig1 Alias Porta.0 : Dig2 Alias Portd.2 : Dig3 Alias Portd.3 : Dig4 Alias Portd.6 Enable Interrupts Enable Ovf0 Enable Timer1 Start Timer1 Hour = 0 Mine = 0 If Pind.1 = 0 And Pind.0 = 0 Then Porta.1 = 1 Waitms 100 Porta.1 = 0 Hour = 0 Mine = 0 Seco = 1 Seco = Makebcd(seco) I2cstart I2cwbyte &HD0 I2cwbyte 0 I2cwbyte Seco I2cstop Mine = Makebcd(mine) I2cstart I2cwbyte &HD0 I2cwbyte 1 I2cwbyte Mine I2cstop Hour = Makebcd(hour) I2cstart I2cwbyte &HD0 I2cwbyte 2 I2cwbyte Hour I2cstop Waitms 1000 Porta.1 = 1 Waitms 10 Porta.1 = 0 End If Do I2cstart I2cwbyte &HD0 I2cwbyte &H00 I2cstart I2cwbyte &HD1 I2crbyte Seco , Ack I2crbyte Mine , Ack I2crbyte Hour , Nack I2cstop Seco = Makedec(seco) Mine = Makedec(mine) Hour = Makedec(hour) If Seco = 80 Then Seco = 10 Seco = Makebcd(seco) I2cstart I2cwbyte &HD0 I2cwbyte 0 I2cwbyte Seco I2cstop End If If Hour > 9 Then Number(1) = Hour / 10 Number(1) = Abs(number(1)) Else Number(1) = 20 End If Number(2) = Hour Mod 10 If Mine > 9 Then Number(3) = Mine / 10 Number(3) = Abs(number(3)) Else Number(3) = 0 End If Number(4) = Mine Mod 10 If Pind.1 = 0 Then Porta.1 = 1 Waitms 10 Porta.1 = 0 If Mine = 59 Then Mine = 0 Else Incr Mine End If Mine = Makebcd(mine) I2cstart I2cwbyte &HD0 I2cwbyte 1 I2cwbyte Mine I2cstop Else If Pind.0 = 0 Then Porta.1 = 1 Waitms 10 Porta.1 = 0 If Hour = 23 Then Hour = 0 Else Incr Hour End If Hour = Makebcd(hour) I2cstart I2cwbyte &HD0 I2cwbyte 2 I2cwbyte Hour I2cstop End If End If Waitms 250 Loop Awake: If Point = 1 Then Porta.1 = 1 Waitus 10 Porta.1 = 0 End If Toggle Point Return Refresh: Reset Dig1 : Reset Dig2 : Reset Dig3 : Reset Dig4 Incr Count : If Count > 4 Then Count = 1 If Count = 2 And Point = 1 Then Pointmem = Number(2) + 10 Portb = Lookup(pointmem , Digits) Else Portb = Lookup(number(count) , Digits) End If Select Case Count Case 1 : Set Dig1 Case 2 : Set Dig2 Case 3 : Set Dig3 Case 4 : Set Dig4 End Select Return Digits: Data &B00101000 , &B01111011 , &B00110100 , &B00110010 , &B01100011 Data &B10100010 , &B10100000 , &B00101011 , &B00100000 , &B00100010 Data &B00001000 , &B01011011 , &B00010100 , &B00010010 , &B01000011 Data &B10000010 , &B10000000 , &B00001011 , &B00000000 , &B00000010 Data &B11111111
Source: https://habr.com/ru/post/391005/
All Articles