Assign a char value to a port

I use FLASH memory to store a large static binary array (8192 binary bits) and I need to assign consecutive 8-bit binary value to a digital port. E.g. the binary array is “0101010100001111” and first I assign 01010101 to port A and execute some other instructions and then assign 00001111 to port A in next loop. Here is part of my code:

#include <avr/pgmspace.h>
const char signMessage[] PROGMEM  = {"10101111010110011111111110001110"};
int len = strlen_P(signMessage);
for (k = 0; k < len; k++)
{
  val =  pgm_read_byte_near(signMessage + k);
  PORTA = val;
}

In this way, I can only get 1-bit of binary value from the char array. I do not know how to modify my program so that I can get 8 consecutive bits and assign it to PORTA. Could you please help me? Thanks!

Maybe you have to understand the difference between char and binary value. Your array is char representation of binary value. You are writing characters to port A in sequence '1', '0', '1', '0', '1', '1'.... On the port A just two values take turns '0' and '1' (0x30/0x13 or 00110000b/00110001b). I think, it is not what you want. According:

I need to assign consecutive 8-bit binary value to a digital port. E.g. the binary array is "0101010100001111" and first I assign 01010101 to port A and execute some other instructions and then assign 00001111 to port A in next loop....

you need something like this:

const char signMessage[] PROGMEM = { B01010101, B00001111 ..... }

I'm a bit confused by your question;

To repeat Budvar10, the value you used in your code to initialise the array is a binary string (char type) that is each '0' and '1' is stored as its ASCII 8-bit binary representation so '0' is stored 110000 and '1' as 110001

PORTA is also 8bits I'm assuming so in you code when you do PORTA = val, 8 bits are output simultaneously but only b0 will change value while bit 6 and 7 will always be held high.

"8192" binary bits is 1024 bytes - 8 bits per byte/character.

if you till want to use to initialise the array with a string you need to used an ASCII table to determine what character you need to use to get the binary output you want.

Budvar10: you need something like this:

const char signMessage[] PROGMEM = { B01010101, B00001111 ..... }

That makes sense. But if the OP wants 8 bit values it should probably be a byte array

Separately, on an Uno one should not write all the bits on any Port as some of the bits have special purposes.

...R

The UNO has no port A, it is probably different type. Mega2560?

Budvar10: The UNO has no port A, it is probably different type.

Strictly speaking I did not suggest that it has :)

But my comment was meant more generally. The OP needs to check whether it is appropriate to write all 8 bits to any Port he may be using. I have the impression from the Original Post that he was just using Port A for illustration and that he might want to write to any Port.

...R