{"id":216,"date":"2016-02-06T17:18:10","date_gmt":"2016-02-06T17:18:10","guid":{"rendered":"http:\/\/ceptimus.co.uk\/?p=216"},"modified":"2022-05-24T13:31:39","modified_gmt":"2022-05-24T12:31:39","slug":"an-arduino-based-programmer-for-the-at89c2051-chip","status":"publish","type":"post","link":"https:\/\/ceptimus.co.uk\/index.php\/2016\/02\/06\/an-arduino-based-programmer-for-the-at89c2051-chip\/","title":{"rendered":"An Arduino-based programmer for the AT89C2051 chip"},"content":{"rendered":"<p>The Atmel AT89C2051 is a low cost microcontroller in a 20-pin DIL package.\u00a0 It runs MCS-51 (commonly termed &#8216;8051&#8217;) code.\u00a0 It works from 2.7V to 6V at anything from 0 Hz up to 24 MHz.\u00a0 It has 2K bytes of Flash memory to hold the program and 128 bytes of RAM.\u00a0 It has 15 I\/O lines, a UART, an analogue comparator and two 16-bit timer\/counters.<\/p>\n<p>I came across the chip as it&#8217;s often used in cheap 7-segment clock kits such as this one from <a href=\"http:\/\/www.banggood.com\/6-Digital-LED-Electronic-Clock-DIY-Kit-Parts-Components-9V12V-p-926716.html\">BangGood (only \u00a32.71 at the time of writing).<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"http:\/\/3.bp.blogspot.com\/-NazVX9DLdTs\/Vj4TrtCPH3I\/AAAAAAAAAfs\/H8mNEw8mDTY\/s1600\/20151107_082926.jpg\" alt=\"\" width=\"1600\" height=\"900\" \/><\/p>\n<p>I wanted to <a href=\"https:\/\/ceptimus.co.uk\/index.php\/2022\/05\/24\/sh-e-879-clock-kit-stopwatch\/\">reprogram the chip so I could use the kit as a stopwatch\/timer instead of a regular clock<\/a>.\u00a0 Of course I could have bought a programmer to do the job, but reading the chip&#8217;s data sheet it seemed straightforward to do the programming with an Arduino &#8211; and I thought it would be a fun project to do that.<\/p>\n<p>The chip is programmed a byte at a time by setting up each byte on 8 of the chip&#8217;s I\/O lines and then pulsing some of the other I\/O lines to &#8216;burn&#8217; the byte to flash memory and move on to the next byte to be programmed.\u00a0 You can also read the existing program out of a chip (unless a read-protect bit has been set) and there are special ways of pulsing the I\/O lines to erase the whole chip and so on.<\/p>\n<p>The only tricky thing is that one pin has to be raised from the nominal operating voltage of five volts up to twelve volts during programming &#8211; the challenge was working out the easiest way to do this using an Arduino.<\/p>\n<p>So I decided to use an Arduino Mega 2560 for this project.\u00a0 A Uno doesn&#8217;t have quite enough I\/O to do the job properly, and the Mega 2560&#8217;s double row of I\/O pins makes routing the connections to the chip simple as the chip can sit directly over the double-row connector.<\/p>\n<p>I decided to use a charge pump (voltage multiplier) running off the Arduino&#8217;s five volts to generate the programming voltage &#8211; that seemed cleaner than needing a separate twelve volt supply.\u00a0 It just uses a few diodes and capacitors and relies on the Arduino pulsing some of its I\/O lines to drive the voltage multiplier.\u00a0 A couple of zener diodes clip the voltage down to exactly 5V or 12V and a couple of transistors, also switched by the Arduino, select between either of those voltages or 0V to drive the pin on the chip.<\/p>\n<p>I designed a PCB using the free KiCad package.\u00a0 <a href=\"https:\/\/ceptimus.co.uk\/wp-content\/uploads\/2016\/02\/AT89C2051programmer.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">Here&#8217;s a .pdf<\/a> of the circuit diagram, and here is what KiCad produces as a picture of the design.\u00a0 In the picture it looks like the chip to be programmed is soldered straight into the board, but of course in reality a ZIF socket is fitted in that position so that the chip(s) you are programming can be quickly swapped.<\/p>\n<p><a href=\"https:\/\/ceptimus.co.uk\/wp-content\/uploads\/2016\/02\/programmer3D.gif\" rel=\"attachment wp-att-219\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-219\" src=\"https:\/\/ceptimus.co.uk\/wp-content\/uploads\/2016\/02\/programmer3D-283x300.gif\" alt=\"programmer3D\" width=\"283\" height=\"300\" \/><\/a>That picture wrongly shows the tracks on the top of the board &#8211; I design them that way for home production as the transfer process mirror-images the tracks so that they&#8217;re correct for the back of the board.\u00a0 If you fancy making one of your own, it would be quite straightforward to\u00a0 do it on strip board &#8211; like I say most of the pins of the chip just connect direct to the Arduino pins that the chip sits over.\u00a0 If you want to etch your own PCB, <a href=\"https:\/\/ceptimus.co.uk\/wp-content\/uploads\/2016\/02\/AT89C2051programmer-F.Cu_.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">here is a .pdf of the mask<\/a>.<\/p>\n<p>Here are a couple of snaps of the prototype board.\u00a0 You can see I didn&#8217;t bother to crop back the board edges!<\/p>\n<p><a href=\"https:\/\/ceptimus.co.uk\/wp-content\/uploads\/2016\/02\/top.jpg\" rel=\"attachment wp-att-225\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-225\" src=\"https:\/\/ceptimus.co.uk\/wp-content\/uploads\/2016\/02\/top-300x268.jpg\" alt=\"top\" width=\"300\" height=\"268\" \/><\/a><a href=\"https:\/\/ceptimus.co.uk\/wp-content\/uploads\/2016\/02\/back.jpg\" rel=\"attachment wp-att-226\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-226\" src=\"https:\/\/ceptimus.co.uk\/wp-content\/uploads\/2016\/02\/back-209x300.jpg\" alt=\"back\" width=\"209\" height=\"300\" \/><\/a>And this is what it looks like when docked on top of the Arduino Mega 2560.<\/p>\n<p><a href=\"https:\/\/ceptimus.co.uk\/wp-content\/uploads\/2016\/02\/topDocked.jpg\" rel=\"attachment wp-att-227\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-227\" src=\"https:\/\/ceptimus.co.uk\/wp-content\/uploads\/2016\/02\/topDocked-300x150.jpg\" alt=\"topDocked\" width=\"300\" height=\"150\" \/><\/a><a href=\"https:\/\/ceptimus.co.uk\/wp-content\/uploads\/2016\/02\/backDocked.jpg\" rel=\"attachment wp-att-228\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-228\" src=\"https:\/\/ceptimus.co.uk\/wp-content\/uploads\/2016\/02\/backDocked-300x249.jpg\" alt=\"backDocked\" width=\"300\" height=\"249\" \/><\/a>So that&#8217;s about it for the hardware.\u00a0 I&#8217;ll make a separate post about the Arduino sketch that does the work of programming the chip, and the PC program that talks to the Arduino to send and receive hex files.<\/p>\n<p><a href=\"https:\/\/ceptimus.co.uk\/?p=231\">Part 2<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Atmel AT89C2051 is a low cost microcontroller in a 20-pin DIL package.\u00a0 It runs MCS-51 (commonly termed &#8216;8051&#8217;) code.\u00a0 It works from 2.7V to 6V at anything from 0 Hz up to 24 MHz.\u00a0 It has 2K bytes of Flash memory to hold the program and 128 bytes of RAM.\u00a0 It has 15 I\/O [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-216","post","type-post","status-publish","format-standard","hentry","category-arduino","category-programming"],"_links":{"self":[{"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/216","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=216"}],"version-history":[{"count":1,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/216\/revisions"}],"predecessor-version":[{"id":574,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/216\/revisions\/574"}],"wp:attachment":[{"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}