I am supposed to make a mux using a Dallas 8051 chip. p1.0, p1.1, and p1.2 are inputs. P1.3 is the enable line, and output are P2.0 to p2.3. All outputs work fine while debugging apart from when all inputs are zero and enable is one. (only zero should be on in the output in the Keil debugger view, but that is not the case).
#include<reg51.h>
sbit input0 = p1^0;
sbit input1 = p1^1;
sbit input2 = p1^2;
sbit enable = p1^3;
sbit output0 = p2^0;
sbit output1= p2^1;
sbit output2 = p2^2;
sbit output3 = p2^3;
sbit output4 = p2^4;
sbit output4 = p2^5;
sbit output6 = p2^6;
sbit output7 = p2^7;
void main (void) {
P2 = 0x00;
if (enable==1)
{
P1&=0x07;
switch(P1)
{
case 1: output1=1; break;
case 2: output2=1; break;
case 3: output3=1; break;
case 4: output4=1; break;
case 5: output5=1; break;
case 6: output6=1; break;
case 7: output7=1; break;
default: output0 =1; break;
}
}
else {P2&=0x07;}
}