element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Code Exchange
  • Technologies
  • More
Code Exchange
Forum Code for small diy clock kits.
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Code Exchange to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 36 replies
  • Answers 18 answers
  • Subscribers 49 subscribers
  • Views 8418 views
  • Users 0 members are here
  • mod
  • clock
  • at89
  • Code Exchange
  • attiny 2313
  • diy
  • assembly_language
Related

Code for small diy clock kits.

fbtjbt
fbtjbt over 7 years ago

I've been looking for a project that would be suitable for young Boy Scouts, and have decided that one of these DIY clock kits would be something that even the youngest could put together.

imageimage

Most of the kits appear to come with an AT89C2051 (they all seem to come with the same pcb as well), so I've also searched out code that the older scouts could program additional AT89C2051s with. I'll reach out to the local university to see if they've got a programmer that we can use, but the boys won't have access to one after we're done making these. I think having a couple extra chips to swap around with different programs would be cool to them.

 

The clock comes with a standard clock program, but I'm still looking for a simple countdown timer and a simple stopwatch. By "simple" I mean something that I can show the scouts, and explain commented snippets of the code.

The code that I've found has been on forums where the members haven't been active for years, so I can't ask them followup questions.

 

If anyone could help me out with simplified code for two projects, I would greatly appreciate it. I can reassign pins in the code if the boards end up being pinned slightly different than what is pictured (you never know with these things).

 

Countdown Timer:

- button1 == cancel timer / cancel buzzer

- button2 == add time to countdown

- button1 held >2sec == enter/exit setup mode.

- button1 in setup mode == toggle buzzer duration between: 60sec / 300sec / 600sec / 9999sec

- button2 in setup mode == toggle button2 "value" between: 30sec / 60sec / 180sec / 240sec / 300sec

Timer counts down in seconds from 9999 - 0 (in base10)

Digits blink at 500ms intervals while <=10sec

Button2 push adds value to current countdown at any time

Buzzer sounds at 500ms interval.

 

Stopwatch:

- button1 == clear

- button2 == start/pause

- button1 + button2 == switches between hh:mm / mm:ss / ss:ms ("Hr:  " / " :S " / " S:  ")

Time counts up (in base 60)

Time stops at 99:59 (i.e. 99hr:59min / 99min:59sec / 99sec:59ms)

 

I think there are some good learning opportunities between the two programs. Showing them the code and having them customize values in their code (like the available "values" for button1&2) will help them feel ownership in the project.

 

 

TheCustomGeek shared some code for one of his projects, and is what I used as the base for my attempts to make the Countdown Timer and Stopwatch described above. Here's a link Multiplexing for a 7 year old | The Custom Geek

I've attached the code, too, mainly so that the multiplexing can be similar in both projects (easier to explain to the scouts). Using a better method is fine too.  I've removed this, and attached the assembly code that I had initially started with -prior to finding TheCustomGeek's project. We do have access to a C compiler and linker for the 8051s (AT89C2051 included), though.

 

I'm still muddling through this on my own, but I'm hoping that one (or more) of you would be able to put together some code much faster/better/cleaner than I.

Attachments:
Countdown Timer.a51.txt.zip
  • Sign in to reply
  • Cancel

Top Replies

  • michaelkellett
    michaelkellett over 7 years ago in reply to shabaz +4 suggested
    The atTiny2313A is a supported product of Atmel/Microchip in current production. It's a way better part than the 8051 based one. Atmel Studio 7 supports it and gives you a free C compiler and debugger…
  • michaelkellett
    michaelkellett over 7 years ago in reply to fbtjbt +4 suggested
    I had some free Paypal money (from "Have a beer" promotion on Embedded related") so I just ordered 2 of these: https://www.ebay.co.uk/itm/282484911382?ViewItem=&item=282484911382 I'll try re-hearting one…
  • shabaz
    shabaz over 7 years ago in reply to fbtjbt +3 suggested
    That's assembler code, which is likely what you'll need to do for the AT89C2051, unless you can find a C compiler and linker (I have no idea if that is practical for that chip, and it will require some…
Parents
  • shabaz
    0 shabaz over 7 years ago

    Hi,

     

    The attached code is for an Arduino, which contains a different microcontroller compared to AT89C2051. The code isn't compatible.

    You could rewrite the code for AT89C2051, but you'd almost have to start from scratch, since even the LED display is different, yours appears to have 12 pins, and the one that the Arduino code is for has 16 pins, so yours is multiplexed differently, and that would need to be deciphered too. So, a non-trivial exercise to do this, but possible.

    The AT89C2051 is a really ancient chip, so although you'll likely find information on the Internet on how to program it and perhaps some example programs to get you started, personally I don't have any example source code for this microcontroller - I think I maybe briefly used it >10 years ago. Personally I wouldn't advise it, because you'll need to source a programmer and compiler, and most of this is really ancient as mentioned. Better to just have a construction project with it using the pre-programmed chip supplied with the kit perhaps, and have a different project if you want to demonstrate different code.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • fbtjbt
    0 fbtjbt over 7 years ago in reply to shabaz

    Dangit. I had started this project using code from one of those other groups that I mentioned, but then started looking for other code after a while. TheCustomGeek code was more 'legible' to me, so that's when I pivoted. Here is what I was working with before (see attached txt).

    Attachments:
    1856.Countdown Timer.a51.txt.zip
    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 7 years ago in reply to shabaz

    The atTiny2313A is a supported product of Atmel/Microchip in current production. It's a way better part than the 8051 based one. Atmel Studio 7 supports it and gives you a free C compiler and debugger. Just for fun I'm down loading it now. If the OP is interested I'm happy to help code this thing. I let my serious paid for AVR compiler license lapse years ago  - it would be fun to play with one again.

     

    MK

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 7 years ago in reply to fbtjbt

    Where did you get your board ?

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • gadget.iom
    0 gadget.iom over 7 years ago in reply to shabaz

    shabaz  wrote:

     

    From the pinout they could be swapped out, the work effort is probably around the same in terms of coding.

     

    Could it be programmed using the Arduino IDE and an Arduino as the ISP?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 7 years ago in reply to gadget.iom

    You could possibly program it using the Arduino IDE but why, oh why, would you want to ?

     

    (I didn't spend enough time looking on the web to find if you really can use this atTiny chip as an Arduino but you can use others.)

     

    You can get a proper C compiler and dev tools for free - you'll need to program to the metal to get it work properly (it has almost no RAM) so C is a much better bet.

     

    MK

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • gadget.iom
    0 gadget.iom over 7 years ago in reply to michaelkellett

    The suggestion was inspired by this sentence in the original post:

    By "simple" I mean something that I can show the scouts, and explain commented snippets of the code.

    I've personally programmed ATTiny85's through this method:

    https://create.arduino.cc/projecthub/arjun/programming-attiny85-with-arduino-uno-afb829

     

    Further research shows that somebody has already done it:

    http://arduinolearning.com/code/program-attiny2313-arduino.php

     

    The Arduino ecosystem was developed with STEM in mind. It might afford the opportunity for young people to experiment with the code and put their own modified programs onto the board.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • shabaz
    0 shabaz over 7 years ago in reply to gadget.iom

    Hi Paul,

     

    That's interesting, I hadn't realized that the '2313 was usable with Arduino IDE.

    As you say, the requirement that young children be able to understand it at least partially, would be good, which is why I was sceptical that one should resurrect assembler code or even old 8051 compilers, and all that goes along with it, like having to answer the awkward questions that all kids will ask if one goes down the 8051 path, like "what does 'sbit' mean?".

     

    That can be eliminated to some extent by hiding it in a different C file and calling simplified functions or to use Arduino as you say, since that has simplified functions. My first C code experience was not Arduino and was using a normal compiler, and so the teacher went that route; hiding anything unnecessary, and we just had to know to include a header and link to a library, and that way we could concentrate on the interesting stuff and not see more complexity than we needed to during that learning phase.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 7 years ago in reply to gadget.iom

    I guess it depends on what you want to learn/teach.

     

    Lots of kids will be happy to attempt soldering the board together.

     

    Only a few will want to get into why it works - I always think that the ones who will stick with programming are the ones who get cheesed off when teachers, to use Shabaz's example, refuse to explain what 'sbit' means.

     

    To me the Arduino IDE is obfuscation not simplification (but that's just me image)

     

    For the OP, the good news is that he can use the atTiny and has a nice choice of options.

     

    MK

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • fbtjbt
    0 fbtjbt over 7 years ago in reply to michaelkellett

    I haven't ordered one yet, but here is the one I had planned on getting (just purchased):

    c51 4 bits digital 7-segment led electronic clock DIY kit set

     

    I just read up on the Atmel Studio 7 that you mentioned, and I think it's an excellent option!

    Downloading now...

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • fbtjbt
    0 fbtjbt over 7 years ago in reply to gadget.iom

    I haven't experimented with Arduino yet, but I see it everywhere.

    I've been able to explain C code fairly easily to my younger nephews, but I'm up for learning something new if it will be something these boys will use later on.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 7 years ago in reply to gadget.iom

    The Digispark Pro is using the ATtiny167 and this includes a bootloader.

     

    I'm not sure how compatible the two are, but in terms of the ease of use then Arduino with all it's limits and benefits might be a better option.

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • mcb1
    0 mcb1 over 7 years ago in reply to gadget.iom

    The Digispark Pro is using the ATtiny167 and this includes a bootloader.

     

    I'm not sure how compatible the two are, but in terms of the ease of use then Arduino with all it's limits and benefits might be a better option.

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube