8255_io.c

来自「《并行口编程指南》」· C语言 代码 · 共 31 行

C
31
字号
/*8255 in I/O mode with Port A and B as Inputs and C as output*/
/*8255_io.c*/
#include<dos.h>
#include<stdio.h>

#define BASE_ADDRESS 0x300

main()
{
unsigned char control_byte, temp;

control_byte=0x92;          /*10010010*/
/*This control byte programs the 8255 in the I/O mode with all the
ports in mode 0. Port A and B as inputs and C as output*/

outportb(BASE_ADDRESS+3, control_byte);
/*this loads the control register of the 8255 with number 0x92*/

/*Now any of the 8255 ports can be used.*/
/*to read the port A and B just do the following*/

temp= inportb(BASE_ADDRESS); /*this reads port A*/

temp = inportb(BASE_ADDRESS + 1); /*this reads port B*/

outportb(BASE_ADDRESS+2, temp);
/*this write the contents of temp into port C*/

return 1;

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?