Interfacing Atmega 2560 with 74ls240 inverting buffer

I am having trouble interfacing the Atmega 2560 feeding outputs from Port K pins into the inputs for the inverting chip. Regardless of whatever the arduino is outputting to the chip's inputs, the chip is always outputting low. However, if I feed ground from the arduino board as a "test" input, the chip is able to invert that low voltage into a high voltage. I have tested the arduino outputs with an oscilloscope, and they indeed output high or low voltage as desired.

Here is the software I wrote (Before anyone asks, I'm not using library functions a. for a fundamental understanding of whats going on and b. I'm not supposed to)

// Define Port B Register Pointers
volatile unsigned char* port_b = (unsigned char*) 0x25; 
volatile unsigned char* ddr_b  = (unsigned char*) 0x24; 
volatile unsigned char* pin_b  = (unsigned char*) 0x23; 

//Define Port K Register Pointers
volatile unsigned char* port_k = (unsigned char*) 0x108; 
volatile unsigned char* ddr_k  = (unsigned char*) 0x107; 
volatile unsigned char* pin_k  = (unsigned char*) 0x106; 

int A;
int B;
int C;
int D;


void setup() {
  // put your setup code here, to run once:

Serial.begin(9600);
 
 *ddr_b &= 0x00; //set all pins to input
 *port_b |= 0xFF;// enable poullup resistors

 *ddr_k &= 0xFF;
 
}

void loop() {
  // put your main code here, to run repeatedly:

if( *pin_b & 0x01 ){A = 1;} 
  else{A = 0;}

if( *pin_b & 0x02 ){B = 1;}
  else{B = 0;}  

if( *pin_b & 0x04 ){C = 1;}
  else{C = 0;}

if( *pin_b & 0x08 ){D = 1;}
  else{D = 0;} 



if((B==1 || D == 1)&&(A == 1 || C == 0)&&(B == 0 || C == 0)&&(A == 0 || D == 1)&&(A == 1 || B == 0 || D == 0)&&(A == 0 || B == 1 || C == 1)) // Boolean equation if a is 1 FIXED
{*port_k = *port_k | 0x01;} //set pk0 high
else
{*port_k = *port_k & 0xFE;} // set pk0 low

if((A==1 || B == 1)&&(B==1 || D == 1)&&(A == 1 || C == 1 || D == 1)&&(A == 1 || C == 0 || D == 0)&&(A == 0 || C == 1 || D == 0)) // Boolean equation if b = 1 FIXED
{ *port_k = *port_k | 0x02;} //set pk1 high
else
{*port_k = *port_k & 0xFD;} // set pk1 low

if((A == 1 || C == 1)&&(A == 1 || D == 0)&&(C == 1 || D == 0)&&(A == 1 || B == 0)&&(A == 0 || B == 1)) // Boolean equation if c = 1 FIXED
{*port_k = *port_k | 0x04;} // set pk2 high
else
{*port_k = *port_k & 0xFB;} // set pk2 low

if ((A == 0 || C == 1)&&(A == 1 || B == 1 || D == 1)&&(B == 1 || C == 0 || D == 0)&&(B == 0 || C == 1 || D == 0)&&(B == 0 || C == 0 || D == 1)) //Boolean equation if d = 1 FIXED
{*port_k = *port_k | 0x08;} //set pk3 high
else
{*port_k = *port_k & 0xF7;} // set pk3 low

if((B == 1 || D == 1)&&(C == 0 || D == 1)&&(A == 0 || C == 0)&&(A == 0 || B == 0))// Boolean equation if e = 1 FIXED
{*port_k = *port_k | 0x10;} // set pk4 high
else
{*port_k = *port_k & 0xEF;} // set pk4 low

if((C == 1 || D == 1)&&(B == 0 || D == 1)&&(A == 0 || B == 1)&&(A == 0 || C == 0)&&(A == 1 || B == 0 || C== 1))// Boolean equation if f = 1 FIXED
{*port_k = *port_k | 0x20;} // set pk5 high
else
{*port_k = *port_k & 0xDF;} // set pk5 low

if((B == 1 || C == 0)&&(C == 0 || D == 1)&&(A == 0 || B == 1)&&(A == 0 || D == 0)&&(A == 1 || B == 0 || C == 1))// Boolean equation if g = 1 FIXED
{*port_k = *port_k | 0x40;} // set pk6 high
else
{*port_k = *port_k & 0xBF;} // set pk6 low



Serial.print(A);
Serial.print(B);
Serial.print(C);
Serial.print(D);
Serial.write("\n");

delay(250);




}

I have attached the full and partial schematics below.

Essentially my problem boils down to: why will the chip invert a low voltage from the ground pin from the Arduino, yet it won't invert a low voltage output from one of the Port K pins?

pinout.PNG

logic table.PNG

Ok, I think I encountered the root of the problem. If I use the following code:

void setup() {
  // put your setup code here, to run once:

pinMode(A8, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:

digitalWrite(A8, LOW);

}

to make the output of the Arduino Low, the chip will effectively invert the voltage to high. However, I'm not allowed to use nor interested in using library functions to set the arduino output pins low. How can I tweak my above approach:

{*port_k = *port_k & 0xFE;}

In order to set the output to ground voltage. The code effectively stops putting out voltage, but how can I change it in order to set it to "ground" voltage?

From your drawing it is doing what I would expect, they helped a lot. Look at the data sheet you will see 1G is active high for output enable and 2G is active Low. Quick test if socketed remove chip, bend 1G (2) up and plug it in, it should work. LS normally floats to a 1 but it is not dependable. Anyhow it needs to be high. you can use the digitalwrite() to set a pin LOW,
Good Luck & Have Fun!
Gil