EEVblog Electronics Community Forum
Products => Computers => Programming => Topic started by: metertech58761 on December 01, 2021, 02:38:34 am
-
So, I'm trying to see if I can rewrite this block of 6801 assembly into C++ so as to use something like Arduino - the assumption being I'd go with something like the Mega 2560.
I'm now at the point where I have to define and add calls to the I/O lines to replace the PIA calls currently in the code.
Getting an idea as to how to set them up will help me immensely. Here are the lines I need to define (23 in all!):
I2C_Clk and I2C_Dat - obviously, this would be for the LCD (4 rows / 20 cols)
KB_R0...R3 and KB_C0...C3 are for the 4x4 matrix keyboard (8 lines total)
Init_En is an output to control one of the features (to drive a small signal relay)
Sig_PIA is a serial data input that is sampled via an interrupt
PAI is the corresponding serial data output (manipulated by the same interrupt process)
PAE (also controlled within the interrupt process) controls a relay that puts the unit in transmit or receive mode.
RlyA... RlyD are four lines that are read as a nybble to determine the status of a set of relay outputs
SW0 / SW1 are a pair of lines to determine the test switch setting (yielding a value between 0 and 3)
Likewise, Jmp0 / JMP1 are a pair of lines that check a pair of configuration jumpers (again, yielding a value between 0 and 3)
And if possible, a 'reference' crystal oscillator input.
-
You have to set up pins in suitable modes, input, input with pullup/pulldown, output, open drain, etc. Some pins even have to be switched between modes on the fly, e.g. the I2C SDA.
-
You have to set up pins in suitable modes, input, input with pullup/pulldown, output, open drain, etc. Some pins even have to be switched between modes on the fly, e.g. the I2C SDA.
...and I accomplish this how?
All I've been able to find is a passing mention of the digitalWrite() command.
And I need to read several of the lines as bit pairs or a nybble.
-
https://www.arduino.cc/reference/en/language/functions/digital-io/pinmode/ (https://www.arduino.cc/reference/en/language/functions/digital-io/pinmode/)
For greater control and to read more than one pin at a time, you need to go lower level:
https://www.arduino.cc/en/Reference/PortManipulation (https://www.arduino.cc/en/Reference/PortManipulation)
-
Here are the lines I need to define (23 in all!):
Note that the popular Arduino Uno and Arduino Nano boards only have 20 IO pins...
I2C_Clk and I2C_Dat - obviously, this would be for the LCD (4 rows / 20 cols)
Use the Arduino "Wire" library (and the hardware I2C pins) Or perhaps just an existing LCD library.
Sig_PIA is a serial data input that is sampled via an interrupt
PAI is the corresponding serial data output (manipulated by the same interrupt process)
PAE (also controlled within the interrupt process) controls a relay that puts the unit in transmit or receive mode.
Is this UART-compatible serial data, or something custom? The Arduino chips all have a lot more peripherals built-in than a 6801, so it's hard to tell which features of your old board should be moved to hardware, and which you want to reproduce the old software-driven behavior.
Init_En is an output to control one of the features (to drive a small signal relay)KB_R0...R3 and KB_C0...C3 are for the 4x4 matrix keyboard (8 lines total)RlyA... RlyD are four lines that are read as a nybble to determine the status of a set of relay outputsSW0 / SW1 are a pair of lines to determine the test switch setting (yielding a value between 0 and 3)
Likewise, Jmp0 / JMP1 are a pair of lines that check a pair of configuration jumpers (again, yielding a value between 0 and 3)
pinMode(x, INPUT) or pinMode(x, OUTPUT)
There are also existing keypad libraries.
The Arduino API only defines functions for reading/writing single bits; to replace code that reads multiple bits, you'll need to either convert the logic, assemble the multiple-bit fields from single bits, or step out of the Arduino APIs.
-
Just forget that "arduino" rubbish and use normal I/O port register manipulation.
I/O registers are quite simple and just have three registers.
* A register to read from the inputs.
* A register to write to the outputs.
* A register for configuration.
If alternative functions are enabled (UsART, SPI, etc) then these override the the normal I/O functions.
-
Sorry for not responding sooner...
There are parts of the code that just will not translate cleanly to C++ (some math operations involving carry between successive bytes that are sent and received, as well as the process of rolling bits left or right as needed).
I also see the Arduino environment has certain failsafes built in that would play havoc with the timing (and I do agree, direct manipulation of the output lines would be the way to go, as the module would need to keep up with the ~2.4kHz input clock and 12.5kHz output clock).
All things considered, I don't really see that I have much choice but to stay with the original 68HC11 assembly code (at least I remember enough assembly language to be able to pick out all the sloppy code and do a proper rewrite).
Too big a gulf between my starting point and the various options available today.
I've invested enough time in this, and I have other non-technical projects waiting for attention. Time to get a move on.
.