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 8428 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…
  • fbtjbt
    0 fbtjbt over 7 years ago in reply to michaelkellett

    I have received mine, and have started tinkering. How is yours going?

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

    I have two - I built one the other day and it does run. The instructions for operating it are so utterly dreadful that I can't understand them at all - I managed to set it by random fiddling.

     

    I forgot to order Atmel processors but I did that just now: 1841620 from Farnell (ATtiny4313)

     

    I'll write some code for re-purposing the board as a timer - and post it.

     

    How are you getting on ?

     

    image

     

    If anyone can translate into English it would be nice image

     

    MK

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

    This guy shows how to set up the original clock. https://www.youtube.com/watch?v=q421PYti3Ic

     

    Ive been messing with code, but i think I need a different programmer for the ATtiny4313... so I've been searching YouTube for How-to vids and checking out their equipment.

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

    I ordered a different programmer that I saw in a video on youtube. It should be here this weekend/monday. I've modified code for a "multiplexing" clock to (hopefully) work with the pinout of the DIY Clock, so I can try it out once the programmer gets here.

    As long as it works, I can start messing with code for the two projects above.

    How goes the Countdown Timer?

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

    My own playing has not gone well - lack of time so zero progress since Feb25th image

     

    MK

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

    The rest of my kit came in, and everything is assembled, so my first attempt is to get the display working with a simple program.

    It turns out that the schematic associated with the clock is incorrect. I've updated the schematic below with the display pin numbers to match the PCB layout.

    I haven't been able to verify that the segment order is correct, nor if the digit order is correct, because I'm still trying to wrap my head around how it works using sip resistors.

     

    Would you turn OFF the segments by setting the segment pins LOW (and digit pins HIGH) to pull the 5v away from the display?

    Then set the digit pin LOW to select the digit, and the segment pin HIGH to divert the 5v back to the segment?

     

     

    image

     

    EDIT: I've confirmed a few of the display pinouts (above), so I'd imagine that the rest are correct also.

     

    I've gotten to the point where I can blink the display ONCE (without control over duration) then the display becomes unresponsive.

    - Setting the digit pins to HIGH, and the segment pins to LOW disables the display.

    - Setting pin0 (digit pin 12) to LOW, and pin10 (segment pin 5 'g') to HIGH gives me a short "-"blink.

    - Setting pins 0, 1, 4 & 8 (digit pins 12, 9, 8 & 6) to LOW, and pin10 (segment pin 5 'g') to HIGH gives me a short "----"blink.

     

    I still don't fully understand how to drive the display when using pull-up resistors on the segment pins.

    Am I right in that HIGH=SOURCE and LOW=SINK?

    Or do you need to use LOW to SINK (divert power), then "FLOAT" the segment pins to allow the LED to pull power through the 1K resistor array?

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

    At my nephew's request (one of the Boy Scouts that I will eventually be instructing), I have also started experimenting with ArduinoIDE.

     

    I've simplified the schematic for the boys who are new-to-electronics, and added ArduinoPinNumbers in Blue:

    (note that the cathode for dp is digit2, the dp anode lights all segments [making a dim "8"] when digit 1, 3, or 4 cathodes are connected.)

     

    image

     

     

    My limited experience leads me to believe that this should blink "-" on digit one, but it doesn't repeat:

     

     

    int segmentPins[8] = {16, 15, 14, 13, 12, 11, 10, 9};    // SEGMENTS A11, F10, B7, E1, D2, C4, G5, DP3

    int digitPins[4] = {0, 1, 4, 8};                                        // DIGITS (1)12, (2)9, (3)8, (4)6

     

    void setup() {

      for(int i=0; i < 8; i++) {

        pinMode(segmentPins[i], OUTPUT);   // SET SEGMENT PINS TO GND:  OUTPUT+LOW = SINK 5V / INPUT=ON

        digitalWrite(segmentPins[i], LOW);

      }

      for(int i=0; i < 4; i++) {

        pinMode(digitPins[i], OUTPUT);     // SET DIGIT PINS TO GND: OUTPUT+LOW = ON

        digitalWrite(digitPins[i], LOW);

        pinMode(digitPins[i], INPUT);        // TURN OFF DIGIT PINS: INPUT=OFF

      }

    }

     

    void loop() {

    //  delay(2000);                       // doesn't blink the segment when this is enabled

      pinMode(0, OUTPUT);      // DIGIT1 cathode to GND

      pinMode(10, INPUT);       // un-ground SEGMENT 'g' allowing 5v

      delay(500);                       // wait a half second

      pinMode(10, OUTPUT);   // ground SEGMENT 'g' diverting 5v

      pinMode(0, INPUT);         // DIGIT1 cathode to INPUT

      delay(500);                       // wait a half second

    }

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

    In your dash blinking loop I think you need a delay between un-grounding and grounding so that the segment has some time on.

     

    MK

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

    Thanks for catching that. I missed that line while I was typing it here on the forum (now edited to include it).

    I started out using the standard 1000ms delay for the on/off, but the led only flashed once for about 250ms then..... nothing.

     

    It doesn't blink at all when I put a delay(2000); at the beginning of the void loop.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • jc2048
    0 jc2048 over 7 years ago in reply to fbtjbt

    https://www.arduino.cc/reference/en/language/functions/digital-io/pinmode/

     

    "Notes and Warnings

    The analog input pins can be used as digital pins, referred to as A0, A1, etc."

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
<>
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