打印

用打印口控制8255卡的C语言原始程序码

[复制链接]
1508|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ledrgb|  楼主 | 2008-7-30 22:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/*The prupose of this simple program is to demonstrate
the use of a 8255 printer port interface card in connection
with an opto-relay card*/[龙图开发网: http://www.longtoo.com ]
/*In this program, Port A is set to input port while
Port B and Port C are set to output ports*/

#include "stdio.h"
#include "dos.h"
#include "conio.h"
#define print_address 0x378
#define controlword 0x90
/*Port A as input while Port B and C as output */
int *inputbyte=0;
void init_printer(void);
/*printer port initialisation*/
void outputbyte(int out_byte);
/*output data to Port B*/
void readbyte(void);
/*read in and convert data from Port A*/
void bitconvert(int *hbyte,int *lbyte);
/*conversion of read-in data */

void main()
{
int outbyte=0;
init_printer(); /*initialise the printer port*/
while (outbyte>=0)
{printf(" Please input the byte to be sent to Port B or a -ve vlaue to exit : " );
scanf("%d", &outbyte);
if (outbyte<0)
break;
outputbyte(outbyte); /*output control byte to 8255*/
printf(" The output byte to Port B is : %d",outbyte);
readbyte();
/*read in and convert data from Port A*/
printf(" The actual input byte is %d", *inputbyte);
}
printf(" Program ends. Thank you!");
}

void init_printer(void)
/*printer initialisation*/
{
outportb(print_address,controlword);
delay(10);
outportb(print_address+2,4);
delay(10);
outport(print_address+2,6);
delay(10);
outportb(print_address+2,4);
delay(10);
}

void outputbyte(int out_byte)
/*output data to Port B*/
{
outportb(print_address,out_byte);
outportb(print_address+2, 12);
delay(20);
outportb(print_address+2, 14);
delay(20);
outportb(print_address+2, 12);
delay(20);
}

void readbyte(void)
/*read in and convert data from Port A*/
{
int *highbyte,*lowbyte;
outportb(print_address,0);
outportb(print_address+2,8);
delay(50);
outportb(print_address+2,9);
*lowbyte=inportb(print_address+1);
outportb(print_address,1);
*highbyte=inportb(print_address+1);
outportb(print_address+2,8);
printf(" In Port A, the input highbyte is %d and the input lowbyte is %d", *highbyte, *lowbyte);
bitconvert(highbyte,lowbyte);
}

void bitconvert(int *hbyte,int *lbyte)
/*conversion of read in data */
{
*hbyte&128;
*hbyte=*hbyte<<1;/*conversion of high byte data*/
*lbyte&128;
*lbyte=*lbyte>>3;/*conversion of low byte data*/
*inputbyte=*lbyte+*hbyte;/*add both high byte and low byte data*/
}

[龙图开发网: http://www.longtoo.com ]

相关帖子

沙发
hotpower| | 2008-7-31 03:19 | 只看该作者

哈哈~~~什么年代了,还散播8255???CPLD不更好吗???

晕!!!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

16

主题

16

帖子

0

粉丝