{"id":199,"date":"2015-12-29T11:20:06","date_gmt":"2015-12-29T11:20:06","guid":{"rendered":"http:\/\/ceptimus.co.uk\/?p=199"},"modified":"2022-06-03T10:59:02","modified_gmt":"2022-06-03T09:59:02","slug":"pov-source-code-part-1","status":"publish","type":"post","link":"https:\/\/ceptimus.co.uk\/index.php\/2015\/12\/29\/pov-source-code-part-1\/","title":{"rendered":"POV source code &#8211; part 1"},"content":{"rendered":"<p>These posts relate to the previous few concerning the Banggood kit: <a href=\"http:\/\/www.banggood.com\/Cross-LED-Dot-Matrix-Display-Circuit-Board-Rotating-Electronic-Kit-p-80601.html\" target=\"_blank\" rel=\"noopener\">Cross LED Dot Matrix Display Circuit Board Rotating Electronic Kit<\/a><\/p>\n<p>It uses an STC89C52RC microcontroller which is a (fairly) modern Chinese version in the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Intel_MCS-51\" target=\"_blank\" rel=\"noopener\">8051 family<\/a>.<\/p>\n<p>You can program it in assembler, but I chose to use the C language for this project.<\/p>\n<h2 style=\"text-align: center;\">The font<\/h2>\n<p>We&#8217;re going to be displaying text so we need some kind of font.&nbsp; The kit provides 16 LEDs arranged vertically on each of the two arms, but I thought that if we use characters the full height of the arms then we wouldn&#8217;t be able to fit many of these large characters around the cylinder that the arms sweep out (unless the characters were ridiculously skinny for their height) so I decided to use an 8&#215;8 font which would allow for two rows of characters.<\/p>\n<p>For simplicity I wanted the characters defined in the font to include the spacing to the left and\/or right of normal characters so most characters in the font are only 7 pixels wide &#8211; or even less for skinny characters such as i &#8211; and only a few characters like q and y have descenders, so the spacing between the two rows of characters is included in the font too.<\/p>\n<p>The kit sensibly arranges the pins driving the LEDs so that the chip&#8217;s four 8-bit I\/O ports, P0, P1, P2, P3 each drive either the top 8 LEDS or the bottom 8 LEDs on an arm:&nbsp; one arm has P2 on the top and P0 on the bottom, the other arm has P1 at the top and P3 at the bottom (at least that&#8217;s the way mine turned out).&nbsp; I chose to fit all blue LEDs to the P0\/P2 arm and all red LEDs to the other one &#8211; obviously you can fit them in other ways &#8211; it might look pretty to get two extra colours &#8211; then you might have (say) yellow and green on the top row with red and blue on the bottom.<\/p>\n<p>Anyway, each of the four ports has the least significant bit at the top, and then the bits going in order down to the most significant bit at the bottom.&nbsp; If you wire up the motor with the red wire as positive, the board spins clockwise (viewed from above) so the LEDs scan the characters out in right-to-left order.&nbsp; The wiring is such that the program has to write a &#8216;0&#8217; to an I\/O pin to illuminate the corresponding pin, or write a &#8216;1&#8217; to switch it off.&nbsp; It&#8217;s convenient to write 8-bit quantities in hexadecimal and in the C language we write 0xFF to indicate all 8 bits high or 0x00 for all eight bits low.<\/p>\n<p>I searched on line and found this 8&#215;8 font which I thought would be suitable:<\/p>\n<p><a href=\"https:\/\/ceptimus.co.uk\/wp-content\/uploads\/2015\/12\/toncFont.gif\" rel=\"attachment wp-att-201\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-201\" src=\"https:\/\/ceptimus.co.uk\/wp-content\/uploads\/2015\/12\/toncFont-300x113.gif\" alt=\"toncFont\" width=\"300\" height=\"113\"><\/a> The font is on this page and includes the data in C-friendly form <a href=\"http:\/\/www.coranac.com\/tonc\/text\/text.htm\" target=\"_blank\" rel=\"noopener\">http:\/\/www.coranac.com\/tonc\/text\/text.htm<\/a><\/p>\n<p>I had to manipulate the font data for right-to-left scan order with the least significant bit at the top and a zero-bit indicating &#8216;LED on&#8217;.&nbsp; I wrote a C# program to do that.<\/p>\n<p>Note that the font starts with the space character (ASCII 32) and is in ASCII order.&nbsp; The last character (ASCII 127 [DEL]) renders a space too, but as that&#8217;s a duplicate you could tweak it to get a \u00a3 or \u20ac or some other symbol you might want to display.<\/p>\n<p>Say our program wants to display the number 2&nbsp; This is the ASCII character 50.&nbsp; Our font doesn&#8217;t have characters defined for the first 32 ASCII values so we subtract 32 to get 18 and then multiply by 8 (eight bytes per character in the table) to get 144.&nbsp; The data we need to display a 2 therefore starts 144 bytes into the font table and consists of the eight bytes:<\/p>\n<p>0xFF,0xB9,0xB0,0xA6,0x8E,0x9C,0xBD,0xFF<\/p>\n<p>So the program outputs those eight bytes in that order and (remembering that the arms scan out the characters from right to left) we get:<\/p>\n<p><a href=\"https:\/\/ceptimus.co.uk\/wp-content\/uploads\/2015\/12\/two.gif\" rel=\"attachment wp-att-202\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-202\" src=\"https:\/\/ceptimus.co.uk\/wp-content\/uploads\/2015\/12\/two.gif\" alt=\"two\" width=\"215\" height=\"235\"><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>These posts relate to the previous few concerning the Banggood kit: Cross LED Dot Matrix Display Circuit Board Rotating Electronic Kit It uses an STC89C52RC microcontroller which is a (fairly) modern Chinese version in the 8051 family. You can program it in assembler, but I chose to use the C language for this project. The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,9],"tags":[],"class_list":["post-199","post","type-post","status-publish","format-standard","hentry","category-programming","category-stc-micro"],"_links":{"self":[{"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/199","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=199"}],"version-history":[{"count":1,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/199\/revisions"}],"predecessor-version":[{"id":598,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/199\/revisions\/598"}],"wp:attachment":[{"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}