{"id":283,"date":"2013-04-01T10:53:37","date_gmt":"2013-04-01T09:53:37","guid":{"rendered":"http:\/\/www.daqq.eu\/?p=283"},"modified":"2023-11-05T22:01:25","modified_gmt":"2023-11-05T21:01:25","slug":"the-avr-controlled-clock","status":"publish","type":"post","link":"https:\/\/www.daqq.eu\/?p=283","title":{"rendered":"The AVR controlled clock"},"content":{"rendered":"<p>The AVR controlled clock:<\/p>\n<p>A friend of mine needed a clock into his amplifier as an extra function. So I made him one. It consists only of one AVR processor and one BQ-M512RD (or compatible, with common anodes) LED display. I tried to keep the whole clock as simple as possible, so anyone can build one...<\/p>\n<p><a href=\"http:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/avr_clock1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-286\" src=\"http:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/avr_clock1.jpg\" alt=\"avr_clock1\" width=\"440\" height=\"189\" srcset=\"https:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/avr_clock1.jpg 440w, https:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/avr_clock1-300x128.jpg 300w\" sizes=\"auto, (max-width: 440px) 100vw, 440px\" \/><\/a><\/p>\n<p>Here's the schematic (click for a bigger image):<\/p>\n<p><a href=\"http:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/sch_hodiny_avr.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-287\" src=\"http:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/sch_hodiny_avr.gif\" alt=\"sch_hodiny_avr\" width=\"1580\" height=\"677\" \/><\/a><\/p>\n<p>And the photo of the device:<\/p>\n<pre> #include &lt;avr\/io.h&gt;\n #include &lt;avr\/interrupt.h&gt;\n #include &lt;avr\/wdt.h&gt;\n #include &lt;stdio.h&gt;\n\n #define _s_A 2\n #define _s_B 0\n #define _s_C 6\n #define _s_D 4\n #define _s_E 3\n #define _s_F 1\n #define _s_G 7\n #define _s_dot 5\n\n const unsigned char segs[] =\n {\n  _BV(_s_A) | _BV(_s_B) | _BV(_s_C) | _BV(_s_D) | _BV(_s_E) | _BV(_s_F), \/\/0\n  _BV(_s_B) | _BV(_s_C), \/\/1\n  _BV(_s_A) | _BV(_s_B) | _BV(_s_D) | _BV(_s_E) | _BV(_s_G), \/\/2\n  _BV(_s_A) | _BV(_s_B) | _BV(_s_C) | _BV(_s_D) | _BV(_s_G), \/\/3\n  _BV(_s_B) | _BV(_s_C) | _BV(_s_F) | _BV(_s_G), \/\/4\n  _BV(_s_A) | _BV(_s_C) | _BV(_s_D) | _BV(_s_F) | _BV(_s_G), \/\/5\n  _BV(_s_A) | _BV(_s_C) | _BV(_s_D) | _BV(_s_E) | _BV(_s_F) | _BV(_s_G), \/\/6\n  _BV(_s_A) | _BV(_s_B) | _BV(_s_C), \/\/7\n  _BV(_s_A) | _BV(_s_B) | _BV(_s_C) | _BV(_s_D) | _BV(_s_E) | _BV(_s_F) | _BV(_s_G),\/\/8\n  _BV(_s_A) | _BV(_s_B) | _BV(_s_C) | _BV(_s_F) | _BV(_s_G),\/\/9\n\n  _BV(_s_A) | _BV(_s_B) | _BV(_s_C) | _BV(_s_E) | _BV(_s_F) | _BV(_s_G), \/\/A\n  _BV(_s_C) | _BV(_s_D) | _BV(_s_E) | _BV(_s_F) | _BV(_s_G), \/\/B\n  _BV(_s_A) | _BV(_s_D) | _BV(_s_E) | _BV(_s_F), \/\/C\n  _BV(_s_B) | _BV(_s_C) | _BV(_s_D) | _BV(_s_E) | _BV(_s_G), \/\/D\n  _BV(_s_A) | _BV(_s_D) | _BV(_s_E) | _BV(_s_F) | _BV(_s_G), \/\/E\n  _BV(_s_A) | _BV(_s_E) | _BV(_s_F) | _BV(_s_G) \/\/F\n };\n\n #define _ms(n) (17*n)\n\n void wait(unsigned int a) \/\/basic wait\n { \n  volatile unsigned int b,c;\n  for(b=0;b!= a; b++)for(c=0;c!= 50;c++);\n  return;\n }\n\n volatile unsigned char prescale=0;\n volatile unsigned char sec=0;\n volatile unsigned char min_1=0;\n volatile unsigned char min_10=0;\n volatile unsigned char hour_1=0;\n volatile unsigned char hour_10=0;\n volatile unsigned char show_t=0;\n\n ISR(TIMER1_OVF_vect)\n {\n  if(++prescale == 225){prescale = 0;sec++;};\n  if(sec&gt;59){min_1++;sec=0;};\n  if(min_1&gt;9){min_1=0;min_10++;};\n  if(min_10&gt;5){min_10=0;hour_1++;};\n  if(hour_1&gt;9){hour_1=0;hour_10++;};\n  if(hour_10&gt;1 &amp;&amp; hour_1&gt;3){hour_1=0;hour_10=0;};\n\n  if(++show_t==4) show_t=0;\n  switch(show_t)\n  {\n   case 0: \/\/show minutes\n    PORTC = 0x04;\n    PORTD = (~segs[min_1]);\n   break;\n   case 1: \/\/show 10 minutes\n    PORTC = 0x08;\n    PORTD = (~segs[min_10]);\n   break;\n   case 2: \/\/show hours\n    PORTC = 0x10;\n    PORTD = (~segs[hour_1]) &amp; ~_BV(_s_dot);\n   break;\n   case 3: \/\/show 10hours\n    PORTC = 0x20;\n    PORTD = (~segs[hour_10]);\n   break;\n   default:\n    show_t = 0;\n   break;\n  } \n  return; \n }\n\n #define B1() (bit_is_clear(PINB,3))\n #define B2() (bit_is_clear(PINB,4))\n #define B_WAIT 300\n\n #define nop() asm volatile (\"nop;\")\n\n int main(void)\n {\n\n  TIMSK = 0x04;\n  TCCR1B = 0x01;\n\n  DDRD = 0xFF;\n  DDRC = 0x3F;\n  DDRB = 0x00;\n  PORTB = 0xFF;\n\n  sei();\n  while(1)\n  {\n   if(B1())\n   {\n    wait(_ms(B_WAIT));\n    min_1++;\n    sec=0;\n   }\n   if(B2())\n   {\n    wait(_ms(B_WAIT));\n    hour_1++;\n    sec=0;\n   }\n  }\n }<\/pre>\n<p>Sorry for the lack of comments. It was a really simple project, so I didn't need em. Enjoy!<\/p>\n<p>Here is the project folder (source, hexfile) and the schematic in Eagle format:<\/p>\n<div class='w3eden'><!-- WPDM Link Template: Default Template -->\n\n<div class=\"link-template-default card mb-2\">\n    <div class=\"card-body\">\n        <div class=\"media\">\n            <div class=\"mr-3 img-48\"><img decoding=\"async\" class=\"wpdm_icon\" alt=\"Icon\" src=\"https:\/\/www.daqq.eu\/wp-content\/plugins\/download-manager\/assets\/file-type-icons\/zip.svg\" \/><\/div>\n            <div class=\"media-body\">\n                <h3 class=\"package-title\"><a href='https:\/\/www.daqq.eu\/?wpdmpro=avr-clock'>AVR clock<\/a><\/h3>\n                <div class=\"text-muted text-small\"><i class=\"fas fa-copy\"><\/i> 1 file(s) <i class=\"fas fa-hdd ml-3\"><\/i> 50.26 KB<\/div>\n            <\/div>\n            <div class=\"ml-3\">\n                <a class='wpdm-download-link download-on-click btn btn-primary ' rel='nofollow' href='#' data-downloadurl=\"https:\/\/www.daqq.eu\/?wpdmpro=avr-clock&wpdmdl=1228&refresh=69f380e2adc5d1777565922\">Download<\/a>\n            <\/div>\n        <\/div>\n    <\/div>\n<\/div>\n\n<\/div>\n<h1>Other implementations<\/h1>\n<p>Several people have made this clock or based their designs on my design. Most of them have not shared, but some have.<\/p>\n<p><a href=\"http:\/\/www.stybnar.ic.cz\/\" target=\"_blank\" rel=\"noopener\">Radek Stybnar:<\/a><\/p>\n<p><a href=\"http:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/avr_clock_radek.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-285\" src=\"http:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/avr_clock_radek.jpg\" alt=\"avr_clock_radek\" width=\"640\" height=\"277\" srcset=\"https:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/avr_clock_radek.jpg 640w, https:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/avr_clock_radek-300x129.jpg 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.ok1kvk.cz\/web\/index.php\/krouek-elektroniky\/452-digitalni-hodiny-s-atmega8\" target=\"_blank\" rel=\"noopener\">OK1KVK <\/a>implementation:<\/p>\n<p><a href=\"http:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/02.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-284\" src=\"http:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/02.jpg\" alt=\"OLYMPUS DIGITAL CAMERA\" width=\"600\" height=\"357\" srcset=\"https:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/02.jpg 600w, https:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/02-300x178.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/mekweb.eu\/?lang=en&amp;q=download-details&amp;file=75\">MEKWEB <\/a>also made a clock based on this design, though with a few improvements.<\/p>\n<p><a href=\"http:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/MekwebImplementation.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1307\" src=\"http:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/MekwebImplementation.jpg\" alt=\"\" width=\"600\" height=\"511\" srcset=\"https:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/MekwebImplementation.jpg 600w, https:\/\/www.daqq.eu\/wp-content\/uploads\/2013\/04\/MekwebImplementation-300x256.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The AVR controlled clock: A friend of mine needed a clock into his amplifier as an extra function. So I made him one. It consists only of one AVR processor and one BQ-M512RD (or compatible, with common anodes) LED display. &hellip; <a href=\"https:\/\/www.daqq.eu\/?p=283\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,19],"tags":[10],"class_list":["post-283","post","type-post","status-publish","format-standard","hentry","category-projects","category-simple-mcu-stuff","tag-avr"],"_links":{"self":[{"href":"https:\/\/www.daqq.eu\/index.php?rest_route=\/wp\/v2\/posts\/283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.daqq.eu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.daqq.eu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.daqq.eu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.daqq.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=283"}],"version-history":[{"count":5,"href":"https:\/\/www.daqq.eu\/index.php?rest_route=\/wp\/v2\/posts\/283\/revisions"}],"predecessor-version":[{"id":1789,"href":"https:\/\/www.daqq.eu\/index.php?rest_route=\/wp\/v2\/posts\/283\/revisions\/1789"}],"wp:attachment":[{"href":"https:\/\/www.daqq.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.daqq.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.daqq.eu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}