This is a program for testing the 8255 interface on protocoltool. It implements a software emulation of the bidirectional mode 2 of a 8255 chip.

Dependencies:   mbed

Fork of parallel_port_tester by Jacques Pelletier

Committer:
jpelletier
Date:
Sun Oct 27 04:39:17 2013 +0000
Revision:
2:0cc974f03339
Parent:
1:51bc46468482
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jpelletier0:a5957f25b150 1#include "mbed.h"
jpelletier0:a5957f25b150 2
jpelletier0:a5957f25b150 3//#include <stdarg.h>
jpelletier0:a5957f25b150 4#include <stdio.h>
jpelletier0:a5957f25b150 5#include <stdlib.h>
jpelletier0:a5957f25b150 6#include <string.h>
jpelletier0:a5957f25b150 7
jpelletier1:51bc46468482 8/*
jpelletier0:a5957f25b150 9Instructions for use: connect the mbed to a parallel port using these connexions.
jpelletier1:51bc46468482 10use a terminal program to connect via USB to the mbed side. */
jpelletier0:a5957f25b150 11
jpelletier2:0cc974f03339 12/* This is for testing since it uses the serial port at 9600 bauds to connect to a PC */
jpelletier2:0cc974f03339 13
jpelletier1:51bc46468482 14#define PAR_INVERT_OBF_SIGNAL
jpelletier0:a5957f25b150 15
jpelletier1:51bc46468482 16#define PAR_8255_SEND_MASK 0x80
jpelletier1:51bc46468482 17#define PAR_8255_RECV_MASK 0x40
jpelletier0:a5957f25b150 18
jpelletier1:51bc46468482 19/*
jpelletier1:51bc46468482 20 8255 Parallel Pin Bit
jpelletier1:51bc46468482 21 PC7 /OBF -> /ACK 10 6
jpelletier1:51bc46468482 22 PC6 /ACK <- /SLCTIN 17 3
jpelletier1:51bc46468482 23 PC5 IBF -> BUSY 11 7
jpelletier1:51bc46468482 24 PC4 /STB <- /STB 1 0
jpelletier1:51bc46468482 25
jpelletier1:51bc46468482 2615 nError -> p9 not used
jpelletier1:51bc46468482 2713 Select -> p10 not used
jpelletier1:51bc46468482 2812 PE -> p11 not used
jpelletier1:51bc46468482 2911 Busy -> p12 IBF
jpelletier1:51bc46468482 3010 nAck -> p13 /OBF
jpelletier1:51bc46468482 31
jpelletier1:51bc46468482 32 1 nStrobe -> p14 /STB
jpelletier1:51bc46468482 3314 nAutoFeed -> p15 not used
jpelletier1:51bc46468482 3416 nInit -> p16 not used
jpelletier1:51bc46468482 3517 nSelectIn -> p17 /ACK
jpelletier0:a5957f25b150 36*/
jpelletier0:a5957f25b150 37
jpelletier1:51bc46468482 38DigitalOut IBF(p12); // IBF
jpelletier1:51bc46468482 39DigitalOut nOBF(p13); // /OBF
jpelletier0:a5957f25b150 40
jpelletier1:51bc46468482 41InterruptIn nSTB(p14);
jpelletier1:51bc46468482 42InterruptIn nACK(p17);
jpelletier0:a5957f25b150 43
jpelletier0:a5957f25b150 44/*
jpelletier0:a5957f25b150 45D0 p30 p0.4
jpelletier0:a5957f25b150 46D1 p29 p0.5
jpelletier0:a5957f25b150 47D2 p8 p0.6
jpelletier0:a5957f25b150 48D3 p7 p0.7
jpelletier0:a5957f25b150 49D4 p6 p0.8
jpelletier0:a5957f25b150 50D5 p5 p0.9
jpelletier0:a5957f25b150 51D6 p28 p0.10
jpelletier0:a5957f25b150 52D7 p27 p0.11
jpelletier0:a5957f25b150 53*/
jpelletier0:a5957f25b150 54BusInOut PtrData(p30,p29,p8,p7,p6,p5,p28,p27);
jpelletier0:a5957f25b150 55
jpelletier0:a5957f25b150 56#define __DOUTBUFSIZE 256
jpelletier0:a5957f25b150 57#define __DINBUFSIZE 256
jpelletier0:a5957f25b150 58char __outstr[__DOUTBUFSIZE];
jpelletier0:a5957f25b150 59char __instr[__DINBUFSIZE];
jpelletier0:a5957f25b150 60
jpelletier0:a5957f25b150 61Serial pc(USBTX, USBRX); // tx, rx
jpelletier0:a5957f25b150 62
jpelletier1:51bc46468482 63unsigned char rx_data;
jpelletier0:a5957f25b150 64
jpelletier1:51bc46468482 65// Peripheral should check that there is no output pending from the 8255 to the peripheral before writing to the 8255
jpelletier1:51bc46468482 66
jpelletier1:51bc46468482 67// When /STB is falling
jpelletier1:51bc46468482 68void perif2mbed(void)
jpelletier1:51bc46468482 69{
jpelletier1:51bc46468482 70 // read byte from peripheral
jpelletier1:51bc46468482 71 rx_data = PtrData;
jpelletier1:51bc46468482 72 IBF = 1;
jpelletier1:51bc46468482 73}
jpelletier1:51bc46468482 74
jpelletier1:51bc46468482 75// When /ACK is rising
jpelletier1:51bc46468482 76void mbed2perif(void)
jpelletier1:51bc46468482 77{
jpelletier1:51bc46468482 78 nOBF = 1;
jpelletier1:51bc46468482 79 PtrData.input();
jpelletier1:51bc46468482 80}
jpelletier1:51bc46468482 81
jpelletier1:51bc46468482 82void write_byte(unsigned char out)
jpelletier1:51bc46468482 83{
jpelletier1:51bc46468482 84 // wait for /OBF = 1 and no read cycle in progress for politeness
jpelletier1:51bc46468482 85 while ((nOBF == 0) || (IBF == 1));
jpelletier1:51bc46468482 86
jpelletier1:51bc46468482 87 PtrData = out;
jpelletier1:51bc46468482 88 PtrData.output();
jpelletier1:51bc46468482 89 nOBF = 0;
jpelletier1:51bc46468482 90}
jpelletier1:51bc46468482 91
jpelletier1:51bc46468482 92unsigned char read_byte(void)
jpelletier1:51bc46468482 93{
jpelletier1:51bc46468482 94 while (IBF == 0);
jpelletier1:51bc46468482 95 IBF = 0;
jpelletier1:51bc46468482 96 return rx_data;
jpelletier1:51bc46468482 97}
jpelletier1:51bc46468482 98
jpelletier1:51bc46468482 99int main()
jpelletier1:51bc46468482 100{
jpelletier1:51bc46468482 101 PtrData.input();
jpelletier1:51bc46468482 102
jpelletier1:51bc46468482 103 /* 9600 baud serial port */
jpelletier1:51bc46468482 104 pc.printf("8255 emulator on mbed\r\n\n");
jpelletier1:51bc46468482 105
jpelletier1:51bc46468482 106 IBF = 0;
jpelletier1:51bc46468482 107 nOBF = 1;
jpelletier1:51bc46468482 108 nSTB.fall(&perif2mbed);
jpelletier1:51bc46468482 109 nACK.rise(&mbed2perif);
jpelletier0:a5957f25b150 110
jpelletier0:a5957f25b150 111 PtrData.input();
jpelletier0:a5957f25b150 112
jpelletier1:51bc46468482 113 while(1)
jpelletier1:51bc46468482 114 {
jpelletier1:51bc46468482 115 // bytes from peripherals to 8255
jpelletier1:51bc46468482 116 if (IBF == 1)
jpelletier0:a5957f25b150 117 {
jpelletier1:51bc46468482 118 IBF = 0;
jpelletier1:51bc46468482 119 pc.putc(rx_data);
jpelletier1:51bc46468482 120 }
jpelletier1:51bc46468482 121 else
jpelletier1:51bc46468482 122 {
jpelletier1:51bc46468482 123 if (pc.readable())
jpelletier0:a5957f25b150 124 {
jpelletier1:51bc46468482 125 write_byte(pc.getc());
jpelletier0:a5957f25b150 126 }
jpelletier1:51bc46468482 127 }
jpelletier0:a5957f25b150 128 }
jpelletier0:a5957f25b150 129}