Hi , I am very new to MC coding , and I am trying to simulate an ouput based on this table
IP1 IP2 OP (first time) 0 0 = 1 0 1 = 1 //changing 1 1 = 0 1 0 = 0 (second time) 0 0 = 1 0 1 = 0 //changing 1 1 = 0 1 0 = 0
*** I want to read , two inputs and and I have to display the outuput *** 1.Whether I am getting the input correct as P1_0 and P1_1 , and displaying output P2_0 2. what is P1^1 ? (i got the sample code from internet and edited it , I know C program well)
I have written this code , please anybody validate and tell me , what I am missing here
======================================================= #include <REG51.H> sbit P1_0 = P1^0; /* SFR for P1.0 */ sbit P1_1 = P1^1; /* SFR for P1.1 */ sbit P2_0 = P2^0; /* SFR for P2.0 */ unsigned int count=0; void main (void) { P1_0 = 1; P1_1 = 1; while (1) { if(count==0) { if(P1_0 ==0) { P2_0=1; } else { P2_0=0; } count=1; } else { if(P1_0==0 && P1_1==0) { P2_0=0; } else { P2_0=1; } count=0; } } } ==================================================
sbit P1_0 = P1^0; sbit P1_1 = P1^1;
The above is a proprietary way of Keil in their C51 compiler to map a one-bit variable "P1_0" to the lowest bit of the 8-bit port P1, and the one-bit variable "P1_1" to the next lowest bit. This extension of the C language is needed since the C language does not contain 1-bit variables and 1-bit variables is one of the unique strong points of the 8051 architecture.
Note that for the rest of a C51 program, the ^ will return to the normal meaning of a C/C++ program.
See the section, "Language Extensions" in the Compiler Manual:
http://www.keil.com/support/man/docs/c51/c51_extensions.htm
Specifically, Bit-Addressable Objects: http://www.keil.com/support/man/docs/c51/c51_le_bitaddrobj.htm
first, there is (almost) not such a thing as a '51 any more, all modern chips I know of have uniquenesses so ALWAYS state which chip you use
I have written this code , please anybody validate and tell me , what I am missing here what is the result when you run it?
if(P1_0==0 && P1_1==0) { P1_1 is always 1 thus the test in ictalics is irrelevant
"P1_1 is always 1 thus the test in ictalics is irrelevant"
But with P0.0 and P0.1 using weak pull-up, external switches can draw one or both of P0.0 and P0.1 low allowing the user to test the full set of logic combinations of P0.0 and P0.1.
The big problem with the test program is that the "count" variable will constantly flip between test case 0 and test case 1, which means that the program will at very high speed switch between the first and the second logic table, resulting in the output LED in some situations be fully on, sometimes fully off, and sometimes be lit with 50% duty cycle resulting in a lower intensity.