Post Reply 
RPN scientific calculator firmware for $13 calculator kit
10-07-2019, 08:07 AM (This post was last modified: 10-07-2019 10:09 PM by jklsadf.)
Post: #1
RPN scientific calculator firmware for $13 calculator kit
I started writing an RPN calculator replacement firmware for the "diyleyuan" calculator here. This is one of the cheapest diy calculator solder kits you can buy (about $13 on ebay) with a full LCD. The original firmware has a fixed point calculator that only operates in chain mode.

My replacement firmware operates in decimal floating point and supports calculating more functions, but doesn't support the original firmware's resistor color code calculator or the hex <=> decimal converter. It does arithmetic with an 18 decimal digit significand, and is reasonably accurate. Eventually, I'd like for it to be able to do all the functions of the original HP 35. The functions supported can be seen in the Qt emulator GUI below:
[Image: calc_small.jpg]
[Image: qt_gui.png]

The diy kit uses an STC microcontroller (which is unfortunate, but likely due to cost). It uses an Intel 8051 compatible architecture instead of a more modern 8-bit architecture like AVR (like in the arduino). But on the bright side, all of these microcontrollers come from the factory with a serial bootloader permanently installed in ROM. All you need to reprogram them is a USB to serial converter dongle thing.
Find all posts by this user
Quote this message in a reply
10-07-2019, 02:00 PM
Post: #2
RE: RPN scientific calculator firmware for $13 calculator kit
Quote:The diy kit uses an STC microcontroller...All you need to reprogram them is a USB to serial converter dongle thing.
I was looking at those this past week for my own DIY project. At least one of the models has a schematic showing how you can directly wire USB to two of the pins and program it with no dongle! They have some other cool stuff, but I passed on them since they don't support external program memory like traditional 8051s. The Atmel AT89LP51 costs about $2 in qty 1, also does single cycle execution, and supports external program and data memory, but it only runs at 20MHz vs 35MHz for some of the STC chips. Dallas has one that runs at 33MHz for $25 if you want all of those features. In any case, it's hard to beat an 8051 if you want to build a DIY calculator with a lot of memory and you're sticking to through hole microcontrollers.

Good luck on your project! I'm gonna buy one of the kits and I'd love to try out your firmware when you're finished.
Find all posts by this user
Quote this message in a reply
10-07-2019, 07:41 PM
Post: #3
RE: RPN scientific calculator firmware for $13 calculator kit
The newer STC microcontrollers have a direct USB interface, instead of serial. The entire industry is moving towards that direction (e.g. arduinos used to have a separate FTDI USB-to-serial converter chip, but the new ones just use a microcontroller with USB built in). The STC microcontrollers aren't bad, and are much faster per clock than the original 8051 (like most modern implementations). I'd consider their main advantage though (other than 8051 compatibility) to be their extremely low cost. The surface-mount version of the chip used in this calculator is less than a dollar in one-off quantities: https://lcsc.com/product-detail/STC_IAP1...08538.html

I would personally probably use an Atmel/Microchip ATxmega for new projects that needed an external memory bus (but still the simplicity of an 8-bit microcontroller), just for the better compiler support for programming in "high-level" languages like C. For anything more powerful, probably an ARM microcontroller. I personally don't mind surface-mount components as long as the pin pitch isn't too fine. Also, there are a lot of really small ARM development boards like the teensy which can be through-hole mounted.

If you're already used to 8051 programming it might not be too bad though. It was my first time though, as I mentioned in the writeup under "Implementation on an STC 8051 Microcontroller". I had originally written the firmware kind of similar to the BigNumber library where functions take pointers to the bignums, but that quickly filled up all available code space, and I had to rewrite large parts of it to just use globals.
Find all posts by this user
Quote this message in a reply
10-11-2019, 01:58 AM
Post: #4
RE: RPN scientific calculator firmware for $13 calculator kit
I bought two of these kits last year and assembled one so far. The fact that the button labels are just paper is a plus. You can break the two-piece buttons apart and relabel at will. The display is impressive in its brightness but I'm pretty sure I've seen the same display in many point of sale terminals.

I'd absolutely be interested in testing an RPN firmware if there is a clear way to reprogram it.
Find all posts by this user
Quote this message in a reply
10-11-2019, 09:06 PM
Post: #5
RE: RPN scientific calculator firmware for $13 calculator kit
I just ordered one of these shipped from an Aliexpress seller for under $11. I'll be waiting a couple of weeks for it though.
I'll absolutely be trying your firmware. Thanks!
I like that it's so easy to relabel the keys.

Georgia, USA
10BII+, 12C, 14B (AE), 17B, 17BII, 20B, WP-34S, 28S, 35S, 39GS, 48G, 82240A,B
+ sliderules galore, mostly Hemmi/Post & Dietzgen
Find all posts by this user
Quote this message in a reply
10-15-2019, 07:11 PM (This post was last modified: 10-15-2019 09:48 PM by jklsadf.)
Post: #6
RE: RPN scientific calculator firmware for $13 calculator kit
The button labels are a huge plus. I think the transparent button keycap cover for relabeling might be an innovation of the Chinese clones. The original Omron B3F series doesn't have these transparent keycap covers. Not many of the major manufacturers have tactile switches with re-labelable keycaps, or if they do they're either very large or expensive (or both).

Reprogramming is fairly straightforward. There is a prebuilt main.hex file in the binaries folder. You do have to solder at least 3 additional wires (Rx, Tx, and ground), or 4 wires including +5V if you're powering with the USB-to-(logic-level)-serial adapter. You need to purchase (or already have) such an adapter, preferably one that supports 5V operation like this one: https://www.amazon.com/HiLetgo-FT232RL-C...00IJXZQ7C/

I do talk a lot more about other hardware stuff in the writeup (e.g. you need to crossover Rx/Tx), but in the end it's just a matter of soldering and connecting 4 extra wires. Once soldered, run the freely-available programmer program to actually program the chip (see the "Programming with stcgal" section).
Find all posts by this user
Quote this message in a reply
10-19-2019, 12:18 AM
Post: #7
RE: RPN scientific calculator firmware for $13 calculator kit
I haven't reflashed my controller yet but wanted to test the build before I do. I have a problem. When I switch modes, sometimes the first character of "Color Ring R C 5" is missing. If I change to "Color Ring R C 4" and back the C appears and stays lit. The R in Rled and the 1 in 10HEX are usually missing as well but not always. If I change from 10HEX <=> 16HEX to 16HEX <=> 10HEX and back, the first character (1) shows up as normal. I don't see a pattern to it. Does anyone else have this problem? If not what can I check? All my solder joints look OK to me.

Also, where to I connect to the board to reflash the chip?

TIA

Tom L
If you buy a drink for someone in order to congratulate them,
is it a Mazel Tov cocktail?
Find all posts by this user
Quote this message in a reply
10-19-2019, 11:30 AM (This post was last modified: 10-19-2019 11:32 AM by Maximilian Hohmann.)
Post: #8
RE: RPN scientific calculator firmware for $13 calculator kit
Hello!

(10-19-2019 12:18 AM)toml_12953 Wrote:  I haven't reflashed my controller yet but wanted to test the build before I do. I have a problem. When I switch modes, sometimes the first character of "Color Ring R C 5" is missing. ...

This behavior is somewhat strage because the display is a standalone unit with it's own controller and should either work OK or not work at all... The display contents are transmitted from the microcontroller through an 8-bit data bus and some handshake signals. Therefore the first character, which your display is missing sometimes, should be in no was different to all the othes. So I would suspect a fault inside the display itself. Or some weird timing problem which causes the handshake between controller and display to occasionally lose the first character. There is not much that can be done there because the controller generates it's clock internally as it looks from the schematics.

I can not see this fault on my calculator (I have bought two but assembled only one).

(10-19-2019 12:18 AM)toml_12953 Wrote:  Also, where to I connect to the board to reflash the chip?

The instructions including the connection that needs to be made are here: https://github.com/jjj11x/stc_rpncalc

On my calculator the processor is not soldered into the board but plugged into a socket. I can't remember if that socket was supllied with the kit or if I added it myself. If yours also has a socket you can remove it from the board and flash it externally on a breadboard, therefore avoiding to have to solder anything to the processor pins directly (as on the github site).

Regards
Max

NB: Myself I have not tried to reflash one of these units because all the software required for it only runs on Windows computers.
Find all posts by this user
Quote this message in a reply
10-19-2019, 01:08 PM
Post: #9
RE: RPN scientific calculator firmware for $13 calculator kit
(10-19-2019 11:30 AM)Maximilian Hohmann Wrote:  Hello!

(10-19-2019 12:18 AM)toml_12953 Wrote:  I haven't reflashed my controller yet but wanted to test the build before I do. I have a problem. When I switch modes, sometimes the first character of "Color Ring R C 5" is missing. ...

This behavior is somewhat strage because the display is a standalone unit with it's own controller and should either work OK or not work at all... The display contents are transmitted from the microcontroller through an 8-bit data bus and some handshake signals. Therefore the first character, which your display is missing sometimes, should be in no was different to all the othes. So I would suspect a fault inside the display itself. Or some weird timing problem which causes the handshake between controller and display to occasionally lose the first character. There is not much that can be done there because the controller generates it's clock internally as it looks from the schematics.

I can not see this fault on my calculator (I have bought two but assembled only one).

(10-19-2019 12:18 AM)toml_12953 Wrote:  Also, where to I connect to the board to reflash the chip?

The instructions including the connection that needs to be made are here: https://github.com/jjj11x/stc_rpncalc

On my calculator the processor is not soldered into the board but plugged into a socket. I can't remember if that socket was supllied with the kit or if I added it myself. If yours also has a socket you can remove it from the board and flash it externally on a breadboard, therefore avoiding to have to solder anything to the processor pins directly (as on the github site).

Regards
Max

NB: Myself I have not tried to reflash one of these units because all the software required for it only runs on Windows computers.

Thanks for the response! I didn't find the instructions until after I posted. The socket does come with the kit.

The flashing software is a Python script and runs in Linux.

https://github.com/grigorig/stcgal

Ubuntu recognizes the USB-Serial converter with no additional software.

Tom L
If you buy a drink for someone in order to congratulate them,
is it a Mazel Tov cocktail?
Find all posts by this user
Quote this message in a reply
10-20-2019, 02:11 PM
Post: #10
RE: RPN scientific calculator firmware for $13 calculator kit
I find the original key labels hard to read. Here's what I came up with for now (until the transcendental functions are added to the firmware)

New DIY Key Template

It's printed on a full 8.5"x 11" page so you can print it without having to resize it before cutting out the individual key labels.

Tom L
If you buy a drink for someone in order to congratulate them,
is it a Mazel Tov cocktail?
Find all posts by this user
Quote this message in a reply
10-21-2019, 04:43 AM (This post was last modified: 10-21-2019 04:48 AM by jklsadf.)
Post: #11
RE: RPN scientific calculator firmware for $13 calculator kit
The only thing I can think of that could cause LCD issues is either a connection issue or a low battery. Try checking all the solder connections again, and then reseating the LCD and also the processor in its socket. A low battery might also cause issues? I think it's unlikely though if you can actually see text, because the LCD requires 5V for good contrast, whereas the rest of the system can happily run at 3.3V. As Maximilian says, it could be a timing issue. The LCD uses a fairly standard Hitachi HD44780 clone IC controller chip, and some of these clones have slightly different timings. The firmware is supposed to poll the busy flag from the LCD, but sometimes people don't and instead just wait a fixed amount of time to simplify the firmware. (If I remember correctly, going to the first line first character takes more time than most operations.) I think a bad connection is still probably the most likely issue though...I don't remember having any trouble with the LCD back when I was using the original firmware.

The stcgal program to program the chip should work on most platforms where you can get Python and supporting libraries installed. I have tested that it works under Linux.

Thanks for making that new keyboard template. I've been meaning to, but so far haven't gotten around to change the key labels on my physical calculator. I'm curious what program you made it in, and if you have a higher resolution version?
Find all posts by this user
Quote this message in a reply
10-21-2019, 07:35 AM
Post: #12
RE: RPN scientific calculator firmware for $13 calculator kit
(10-21-2019 04:43 AM)jklsadf Wrote:  Thanks for making that new keyboard template. I've been meaning to, but so far haven't gotten around to change the key labels on my physical calculator. I'm curious what program you made it in, and if you have a higher resolution version?

I used Paint.net to clip the qt_gui.png file then just edited that. I didn't have any higher resolution but since the labels are only 1 cm on a side, I didn't see the need for any more resolution. Since you asked, however, I updated the image at the link. Download it again and see if you like it better.

Hi-Res DIY Template

Tom L
If you buy a drink for someone in order to congratulate them,
is it a Mazel Tov cocktail?
Find all posts by this user
Quote this message in a reply
10-22-2019, 03:24 AM
Post: #13
RE: RPN scientific calculator firmware for $13 calculator kit
I finally got up the courage to flash the STC RPN firmware. I have a few questions about it.

I have v1.05 is that the latest version?

Here is one anomaly I've seen:

8
Enter
3
*
Display shows
0
24
Hit x<>y
Display shows
24
0
Hit 2
Display shows
0
2
Wrong.
Display should be
24
2

There are other quirks which I'll detail in other messages when they come up.

Tom L
If you buy a drink for someone in order to congratulate them,
is it a Mazel Tov cocktail?
Find all posts by this user
Quote this message in a reply
10-22-2019, 04:37 AM
Post: #14
RE: RPN scientific calculator firmware for $13 calculator kit
I've added the missing shifted functions to my template

DIY Template with all current Shifted Functions

Tom L
If you buy a drink for someone in order to congratulate them,
is it a Mazel Tov cocktail?
Find all posts by this user
Quote this message in a reply
10-22-2019, 04:59 AM
Post: #15
RE: RPN scientific calculator firmware for $13 calculator kit
I'm trying to compile the new firmware with STO, RCL, etc. I use 64-bit Ubuntu with 8GB RAM. When I type make, I get this:

?ASlink-Error-Insufficient ROM/EPROM/FLASH memory.
make: *** [Makefile:19: main] Error 1

What am I doing wrong?

is the pre-built binary set up to use the newer shifted keys? If so, then I won't have to build the hex file.

Tom L
If you buy a drink for someone in order to congratulate them,
is it a Mazel Tov cocktail?
Find all posts by this user
Quote this message in a reply
10-22-2019, 05:01 AM
Post: #16
RE: RPN scientific calculator firmware for $13 calculator kit
Hi, that is indeed the behavior of the calculator, but I'm not sure that that's a wrong result (free 42s gives the same result, starting from a stack filled with all 0s). After "8 enter 3 *" stack lift is re-enabled. After swap, stack lift is still enabled, even though the display shows:
24
0
The zero in the x register isn't a result of CLx or some other stack-disabling operation, so when you hit 2, the stack "lifts" and you get:
0
2

I did just release a v1.06 which adds STO/RCL/LASTx, but I haven't uploaded a binary yet. I just realized that trying to take the square root of 0 will put the physical calculator into an infinite loop (can reset by holding shift and 0 to turn off, then release and press on to turn on again). I'll try to fix that bug and then upload a binary for v1.06 shortly.
Find all posts by this user
Quote this message in a reply
10-22-2019, 05:08 AM
Post: #17
RE: RPN scientific calculator firmware for $13 calculator kit
(10-22-2019 05:01 AM)jklsadf Wrote:  Hi, that is indeed the behavior of the calculator, but I'm not sure that that's a wrong result (free 42s gives the same result, starting from a stack filled with all 0s). After "8 enter 3 *" stack lift is re-enabled. After swap, stack lift is still enabled, even though the display shows:
24
0
The zero in the x register isn't a result of CLx or some other stack-disabling operation, so when you hit 2, the stack "lifts" and you get:
0
2

You're quite right! I've been using RPN since the HP-45 and never noticed that! Wow, am I slow sometimes!

Tom L
If you buy a drink for someone in order to congratulate them,
is it a Mazel Tov cocktail?
Find all posts by this user
Quote this message in a reply
10-22-2019, 05:18 AM
Post: #18
RE: RPN scientific calculator firmware for $13 calculator kit
Stack lift has been one of the hardest things to get right. I've basically just had to study/copy appendix B of the hp15c user manual, but even that manual is complete for how RCL/lastX should be handled...it's not something that you think about much until you have to implement it. I have had bugs in the past, and would not be surprised if there were stack-lift bugs still.

In some ways, having a two line display can be a mixed blessing seeing more of the stack. It seems to make more sense intuitively when you can only see one line, at least for me. I initially tried your example and also thought it was a bug until I sat down and went through the logic to try to find the bug.

I've just uploaded a new binary of v1.06 with STO/RCL/LASTx.

Thanks for putting together the template, I do like the blue shift color. Meant to print a color copy at work today, but then forgot that my job blocks Dropbox access.
Find all posts by this user
Quote this message in a reply
10-22-2019, 05:46 AM (This post was last modified: 10-22-2019 05:48 AM by jklsadf.)
Post: #19
RE: RPN scientific calculator firmware for $13 calculator kit
(10-22-2019 04:59 AM)toml_12953 Wrote:  I'm trying to compile the new firmware with STO, RCL, etc. I use 64-bit Ubuntu with 8GB RAM. When I type make, I get this:

?ASlink-Error-Insufficient ROM/EPROM/FLASH memory.
make: *** [Makefile:19: main] Error 1

What am I doing wrong?

is the pre-built binary set up to use the newer shifted keys? If so, then I won't have to build the hex file.

What version of Ubuntu/SDCC are you using to build? On Ubuntu 18.04LTS with SDCC 3.5.0 doing "make clean" and then "make" gives a binary 12,212 bytes in size, which is a bit tight (but still 1K free). I think newer versions of SDCC might be less efficient at code generation. If you do want to build it, SDCC has few dependencies, so I think it is possible to install older versions of the package. Other compilers (e.g. Keil) are probably even more efficient, but I don't have a license for the 8051, and also it's not free.
Find all posts by this user
Quote this message in a reply
10-22-2019, 06:35 AM
Post: #20
RE: RPN scientific calculator firmware for $13 calculator kit
Just uploaded a new binary v1.07 with a couple of bugfixes for:
  • stack lift after RCL/LASTx
  • exponents larger than 127 or less than -128 should give error
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)