Hi.
I’m corking on some code, but my problem is that the code is probably slow and it should be posible to speed it up a little. The problem is that my programming skills are rusty :-[
The code works that i read 8 pins, crate a byte out of it and writes it to a byte array.
Code:
static byte[] singleline = new byte[128];
static int teller = 0;
static InputPort d0;
static InputPort d1;
static InputPort d2;
static InputPort d3;
static InputPort d4;
static InputPort d5;
static InputPort d6;
static InputPort d7;
// init d0-d7
d0 = new InputPort((Cpu.Pin)FEZ_Pin.Digital.IO51, false, Port.ResistorMode.PullDown);
d1 = new InputPort((Cpu.Pin)FEZ_Pin.Digital.IO52, false, Port.ResistorMode.PullDown);
d2 = new InputPort((Cpu.Pin)FEZ_Pin.Digital.IO53, false, Port.ResistorMode.PullDown);
d3 = new InputPort((Cpu.Pin)FEZ_Pin.Digital.IO54, false, Port.ResistorMode.PullDown);
d4 = new InputPort((Cpu.Pin)FEZ_Pin.Digital.IO55, false, Port.ResistorMode.PullDown);
d5 = new InputPort((Cpu.Pin)FEZ_Pin.Digital.IO56, false, Port.ResistorMode.PullDown);
d6 = new InputPort((Cpu.Pin)FEZ_Pin.Digital.IO57, false, Port.ResistorMode.PullDown);
d7 = new InputPort((Cpu.Pin)FEZ_Pin.Digital.IO58, false, Port.ResistorMode.PullDown);
//Slow code longer down in my program..........
byte retbyte = 0;
if (d0.Read()) retbyte += 1;
if (d1.Read()) retbyte += 2;
if (d2.Read()) retbyte += 4;
if (d3.Read()) retbyte += 8;
if (d4.Read()) retbyte += 16;
if (d5.Read()) retbyte += 32;
if (d6.Read()) retbyte += 64;
if (d7.Read()) retbyte += 128;
singleline[teller] = retbyte;
teller++;
Is there a easy fix to this? i could also use HEX if that makes it easier.
/offtopic/
If it only could have port manipulation like arduino got, then i could read all 8 bits in one go.
We have added parallel port support (8bit) to next release coming in couple weeks. Using out new support will make your code runs 50 times faster or more! So yes, it is very fast
You can use Register class and read multiple pins at once, but it is an advanced technique (see documentation). We might get it on a more higher level, if GHI will include ParallelPort in their new update.
P.S. Gus you are fast! Great I was wondering if it is going to be there or not.
Gus: I’m hooked up betwene another mcu and a 8 bit lcd, trying to sniff some data. I know this chip is not ment to be a logic analycer but the speed on the lcd i slow so it may work.
Rest:
Going to try some of you’r solutions out, hope it works
Assembling the byte is not a big issue here. Reading every bit using input port is slow. As Gus said ParallelPort in the coming update will help a lot.