8051 C PROGRAMMING FOR THE 8255

SECTION 15.3: 8051 C PROGRAMMING FOR THE 8255

In this section we show how to program the 8255 using the 8051 C language. In the last chapter we showed how to use 8051 to access the external data memory space of the 8051. Since the 8255 is treated as an external data memory (memory-mapped I/O), we use XDATA[...] to access it in 8051 C. Study the next few examples to gain an understanding of 8051 C programming for the 8255.


Example 15-6
Write a C program to send 55H and AAH to all ports of the 8255 continuously. Assume the base address of the 8255 is 4000H. (See Figure 15-4)
Solution:



Example 15-7
Write a C program to get data from PA and send it to both ports B and C. Use a base address of 4000H for the 8255. (See Figure 15-4.)
Solution:


Example 15-8
Write a C program to move the stepper motor shown in Figure 15-9 clockwise. Use a base address of 4000H for the 8255.
Solution:






SUMMARY
This chapter described how to expand the I/O ports of the 8031/51 by connecting it to an 8255 chip. The 8255 could then be programmed as a simple I/O port to control interfaced devices such as stepper motors, LCDs, and ADC devices.
The 8255 has 3 ports. Ports A and B are 8-bit bidirectional ports. The 8-bit port C can be programmed as one 8-bit port or two 4-bit ports. The various operation modes of the 8255 are selected by the control register. Various address decoding techniques were demonstrated to program the 8255 control register, select ports, and set the control register. In addition, numerous program examples were given of 8051/31 instructions to control devices such as LCDs, stepper motors, and ADC devices that were interfaced via the 8255.
Accessing the 8255 using 8051 C was discussed in the last section of this chapter.

Next post:

Previous post: