Author Topic: Setting up Arduino I/O pins?  (Read 2752 times)

0 Members and 1 Guest are viewing this topic.

Offline metertech58761

  • Regular Contributor
  • *
  • Posts: 64
  • Country: us
Setting up Arduino I/O pins?
« 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.
 

Online retiredfeline

  • Frequent Contributor
  • **
  • Posts: 390
  • Country: au
Re: Setting up Arduino I/O pins?
« Reply #1 on: December 01, 2021, 03:05:28 am »
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.
 

Offline metertech58761

  • Regular Contributor
  • *
  • Posts: 64
  • Country: us
Re: Setting up Arduino I/O pins?
« Reply #2 on: December 01, 2021, 01:16:11 pm »
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.
 

Online retiredfeline

  • Frequent Contributor
  • **
  • Posts: 390
  • Country: au
Re: Setting up Arduino I/O pins?
« Reply #3 on: December 01, 2021, 02:17:12 pm »
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
 
The following users thanked this post: Ian.M

Offline westfw

  • Super Contributor
  • ***
  • Posts: 3837
  • Country: us
Re: Setting up Arduino I/O pins?
« Reply #4 on: December 02, 2021, 09:42:31 am »
Quote
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...

Quote
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.


Quote
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.

Quote
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.
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 2310
  • Country: nl
Re: Setting up Arduino I/O pins?
« Reply #5 on: December 02, 2021, 10:16:20 am »
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.
 
The following users thanked this post: Siwastaja, george.b

Offline metertech58761

  • Regular Contributor
  • *
  • Posts: 64
  • Country: us
Re: Setting up Arduino I/O pins?
« Reply #6 on: January 08, 2022, 01:33:47 am »
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.
.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf