8051 Tutorial 3: I/O Port Programming in C

This tutorial will introduce you the basics about programming the input and output ports on an 8051 microcontroller using C language. Therefore, it is recommended that the reader is familiar or has basic knowledge about C programming language and electronics circuit analysis. I am going to use Atmel‘s AT89C2051 as an example for the 8051 microcontroller and the C compiler that I am going to use is the RC-51 which is included with the Free Evaluation 8051 Software Toolset of Raisonance. You may see this for more info about the toolset or you may download the free evaluation 8051 Software Toolset  here(RKit-Eval51). See this tutorial for a quick start guide with this software.

For an introduction about AT89C2051, see this.

AT89C2051 General Input and Output Ports

The original 8051 microcontroller (40 pins)  contains 4 digital input and output ports which are P0, P1, P2, and P3. Its little brother, AT89C2051 (20pins), only contains two bidirectional input and output ports which are P1 and P3. Both ports are one-byte (8-bits) wide and each pin of each port can be accessed externally (see the pin diagram below) except bit 6 of P3 or P3.6.

P3.6, however, do exist. It is hardwired internally to the output of AT89C2051′s on-chip analog comparator (see diagram below). All port pins of AT89C2051 have internal pullups except P1.0 and P1.1. Pins P1.0 and P1.1 do not have internal pullups because these pins are also used as inputs of the on-chip analog comparator.

As you can see, the pins of AT89C2051 has alternate functions and we will discuss those functions in the next series of tutorials about AT89C2051. Just for a quick view of these alternate functions, please look at the table below.

Port Pin Alternate Functions
P1.0 AIN0 (positive input) of the on-chip precision analog comparator
P1.1 AIN1 (negative input) of the on-chip precision analog comparator
P3.0 RXD (serial input port)
P3.1 TXD (serial output port)
P3.2 INT0 (external interrupt 0)
P3.3 INT1 (external interrupt 1)
P3.4 T0 (timer 0 external input)
P3.5 T1 (timer 1 external input)

Pages: 1 2 3

Speak Your Mind

*