📜 ⬆️ ⬇️

Watch two days at attiny2313 and ds1307

Motive


To begin with, every person lives in time, which, unfortunately, is not possible to stop. And since we live in this world, let's watch the time and not waste a minute, wasting it. For this, I made this wonderful device, named clock .
image

Let's start!


On the street the sun rose, I drew a board and scratched it on a photocopier in order to print a fee

image

Then, those who know how the boards are made will understand that I translated the drawing with an iron on textolite, etched, tinned, etc., and those who are not in the know - read on the Internet about making boards using the LUT method - (Laser-iron technology) .
I forgot to take the result, but I think that the quality will be visible on the finished board:
')
image

It can be seen places that did not come from, but nothing terrible happened, only the landfill fell behind.
Then it was necessary to solder the components, which I will not dwell on, just leave their list:

And let you not be confused by the length of this list, because we collect the device for many years, and it should be collected at the proper level!
Who wants to look at the board from the other side, here is a photo:

image

Program


Like all devices, watches need a program. In this case, the program is written in the BASIC language in BASCOM AVR. This language is very convenient for programming, as the code is clear, effective and takes not much space on the microcontroller. I did not write the program from scratch, but took the source of one article from the site of the soldering iron. Who is interested - will find, I just leave the code I modified here:

$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 


We flash almost 2 kilobytes of code in microns and observe how the device that just came to life began to serve the person.
Honestly, I feel incredible pleasure from the fact that I can create something that is distant and incomprehensible to many)
It looks like a device without a case, the case will do after writing the article:

image

And so, the clock is ready, and how do they work? I show this in the first half of this video (I don’t ask for a subscription or anything else, just stuff)



Conclusion


Thus, in 2 days I made a device that will show me how much is left for me to do one thing and move on to another when it's time to go, or start something important.
Well, that's all, thanks to those who read to the end, success in your projects, and as they say: “Cod you, 47, and see you on other frequencies! QRZ .. "

Source: https://habr.com/ru/post/391005/


All Articles