Here is a simple project on how to interface 8255 with 8051 (89c51) microcontroller. The project demonstrates a simple blinking LED program. The LEDs are connected to port A of the 8255. When the bottom four bits of port A of the 8255 are high, the top four bits are low. The LEDs connected to the top end will remain off and those at the bottom will light up. After some delay, the bits are changed and the upper LEDs will light up and the lower ones will go out. This whole condition is running continuously. Making the A door bite up and down or turn the LEDs on and off.
If you are not familiar with 8255 programmable peripheral. Here is good tutorial
- PIN 8255 AND WORK DESCRIPTION .
I recommend you take the tutorial because if you are not familiar with the 8255, identify its operation and initialization. So it is very difficult to understand the code below.
The circuit is very easy. Connect port 2 of the 8051 with the data pins of the 8255. Make the CS (chip select) and RESET pins ground of the 8255. Connect A0 with port 1, pin 0 of the 8051 microcontroller, and A1 with port 1, pin 1. Connect WR (write) pin of 8255 with port 3, pin 6. Connect RD (read) pin of 8255 with port 3, pin 7. Circuit diagram is given below.
8255 interface with 8051 microcontroller(89c51,89c52)
Coding is very easy if you are fully familiar with 8051 series microcontrollers (89c51,89c52), their programming and the working of 8255 PPI. The delay function is used to generate some delay. In the main function, I first output ports 2 and 3. Then I did rd(read)=1. Doing rd=1 means I didn't want to read anything from the 8255. So I did WR(write)=0 means I want to write anything to the 8255. So I send 0x80 to the data pins of the 8255, it's my control word. It sets all ports A, B, and C of the 8255 as output. So I selected the control register because the control word is always written in the control register. So in continuous while loop I am making port A nibble high and low. Which alternatively flashes LEDs.
- P2=0xF0 -> Making four upper bites of 8255 port A high and lower low.
- P2=0x0F -> Making four lower bites of port A of the 8255 high and upper low.
These two upper conditions cause the LEDs to appear to be blinking. Delays between conditions are very important. They are used to make the LEDs stay in certain conditions for some time, for example 0xF0 should stay on port A for some time and then change to 0x0F. If you do not use delays in these two conditions you will not be able to see the LEDs blinking. The program runs so fast that it is so difficult to identify what is happening.
You can change the code as per your wish. You can use the LCD connected to the 8255 to display whatever you want. You can extend your ports by connecting 8255 to 8051 microcontroller (89c51,89c52). Download the Code (C++,HEX) project files compiled in keil u vision-3 and give us your feedback on the project. Write your questions below in the comments section.
Flashing LEDs with 8255 and 8051 microcontroller(89c51,89c52)