AT89C2051 I/O Port Programming in C
Note: In this series of tutorial, I am assuming that you already have a basic knowledge about programming using C language.
Some of the registers of AT80C2051 are byte accessible or bit accessible. A byte access to a register means that the whole register, if it is byte wide, is accessed at a single time. A bit access to a register means that only a single bit inside a register is accessed at a time.
The ports of AT89C2051 can be byte accessible or bit accessible. Typically, writing FF(hex) to P1(a register/port) is the same as writing 1′s to each of the pins or bits of P1 (from P1.0 to P1.7).
For example,
P1 = 0xFF; //write FF hex to P1
is the same as
P1^0 = 1; P1^1 = 1; P1^2 = 1; P1^3 = 1; P1^4 = 1; P1^5 = 1; P1^6 = 1; P1^7 = 1;
Similarly, reading the ports of AT89C2051 can be done through byte access or as bit access.
unsigned char temp; //creating a byte-size variable named tempbit my_flag; //creating a bit-size variable named my_flagtemp = P1; //reading the value of P1 and saving it to tempmy_flag = P3^0; //reading the value of P3.0 and saving it to my_flag
note: bit and unsigned char are data types













Hi there! Thank you very much for this great tutorial! I read it with interest and am sure, I am going to use an 8051 for one of my projects. The problem is, I just don’t know how to get the programm I wrote into my microcontroller. Wich kind of programmer do I nead? Thank you!