Uses the mbed for testing PC's parallel port. It uses the USB serial port for displaying and controlling each pin.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 //#include <stdarg.h>
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #include <string.h>
00007 
00008 #define PAR_NEGOTIATE_EXTENSIBILITY_LINK        0x80
00009 #define PAR_NEGOTIATE_REQ_EPP_MODE              0x40
00010 #define PAR_NEGOTIATE_REQ_ECP_MODE              0x10
00011 #define PAR_NEGOTIATE_REQ_ECP_RLE_MODE          0x30
00012 #define PAR_NEGOTIATE_REQ_DEV_ID_NIBBLE_MODE    0x04
00013 #define PAR_NEGOTIATE_REQ_DEV_ID_BYTE_MODE      0x05
00014 #define PAR_NEGOTIATE_REQ_DEV_ID_ECP_MODE       0x14
00015 #define PAR_NEGOTIATE_REQ_DEV_ID_ECP_RLE_MODE   0x34
00016 #define PAR_NEGOTIATE_NIBBLE_MODE               0x00
00017 #define PAR_NEGOTIATE_BYTE_MODE                 0x01
00018 
00019 /*
00020 Instructions for use: connect the mbed to a parallel port using these connexions.
00021 use a terminal program to connect via USB to the mbed side.
00022 
00023 This program uses CR to rewrite over the status previously printed. Setup the terminal
00024 program so that CR = CR without line feed.
00025 
00026 15 nError       -> p9
00027 13 Select       -> p10
00028 12 PE           -> p11
00029 11 Busy         -> p12
00030 10 nAck         -> p13
00031 
00032  1 nStrobe      -> p14
00033 14 nAutoFeed    -> p15
00034 16 nInit        -> p16
00035 17 nSelectIn    -> p17
00036 */
00037 
00038 DigitalOut nError(p9);
00039 DigitalOut Select(p10);
00040 DigitalOut PaperOut(p11);
00041 DigitalOut Busy(p12);
00042 DigitalOut nAck(p13);
00043 
00044 DigitalIn nStrobe(p14);
00045 DigitalIn nAutoFeed(p15);
00046 DigitalIn nInit(p16);
00047 DigitalIn nSelectIn(p17);
00048 
00049 /*
00050 D0 p30  p0.4
00051 D1 p29  p0.5
00052 D2 p8   p0.6
00053 D3 p7   p0.7
00054 D4 p6   p0.8
00055 D5 p5   p0.9
00056 D6 p28  p0.10
00057 D7 p27  p0.11
00058 */
00059 BusInOut PtrData(p30,p29,p8,p7,p6,p5,p28,p27);
00060 
00061 #define __DOUTBUFSIZE 256
00062 #define __DINBUFSIZE 256
00063 char __outstr[__DOUTBUFSIZE];
00064 char __instr[__DINBUFSIZE];
00065 
00066 Serial pc(USBTX, USBRX); // tx, rx
00067 
00068 int main() {
00069 
00070 char key;
00071 bool PortIsInput = false;
00072 
00073     PtrData.input();
00074 
00075     pc.printf("Parallel port tester on mbed\r\n\n");
00076     pc.printf("Press keys 0-7,G,H,J,K and L to toggle output bits (inputs on PC)\r\n");
00077     pc.printf("Press keys I and O to toggle data direction for bits 0-7\r\n");
00078     pc.printf(" (be sure your PC and mbed don't output at the same time)\r\n\n");
00079     pc.printf("PINS 9-2     1    14    16    17     ------ 15    13    12    11    10\r\n");
00080     pc.printf("DATA 7-0   /STB  /AF  /INIT  /SEL_IN ------/ERR   SEL   PO    BUSY  /ACK\r\n");
00081     pc.printf("Keys                                 ------  G     H     J     K     L\r\n");
00082              //  XX         B     B     B     B     ------  B     B     B     B     B
00083     while(1) {
00084         pc.printf("  %02X         %c     %c     %c     %c             %c     %c     %c     %c     %c \r",
00085             PtrData & 0xff,
00086             '0'| nStrobe,
00087             '0'| nAutoFeed,
00088             '0'| nInit,
00089             '0'| nSelectIn,            
00090             '0'| nError,
00091             '0'| Select,
00092             '0'| PaperOut,
00093             '0'| Busy,
00094             '0'| nAck                                                
00095             );
00096 
00097         if (pc.readable())
00098         {
00099             key = pc.getc();
00100             switch(key)
00101             {
00102                 case 'I':
00103                     PtrData.input();
00104                     PortIsInput = true;
00105                     break;
00106                 case 'O':
00107                     PtrData.output();
00108                     PortIsInput = false;
00109                     break;
00110                 case '0':
00111                     if (!PortIsInput)
00112                     PtrData = PtrData ^ 0x01;
00113                     break;
00114                 case '1':
00115                     if (!PortIsInput)
00116                     PtrData = PtrData ^ 0x02;
00117                     break;
00118                 case '2':
00119                     if (!PortIsInput)
00120                     PtrData = PtrData ^ 0x04;
00121                     break;
00122                 case '3':
00123                     if (!PortIsInput)
00124                     PtrData = PtrData ^ 0x08;
00125                     break;
00126                 case '4':
00127                     if (!PortIsInput)
00128                     PtrData = PtrData ^ 0x10;
00129                     break;
00130                 case '5':
00131                     if (!PortIsInput)
00132                     PtrData = PtrData ^ 0x20;
00133                     break;
00134                 case '6':
00135                     if (!PortIsInput)
00136                     PtrData = PtrData ^ 0x40;
00137                     break;
00138                 case '7':
00139                     if (!PortIsInput)
00140                     PtrData = PtrData ^ 0x80;
00141                     break;
00142                 case 'G':
00143                     nError = !nError;
00144                     break;
00145                 case 'H':
00146                     Select = !Select;
00147                     break;
00148                 case 'J':
00149                     PaperOut = !PaperOut;
00150                     break;
00151                 case 'K':
00152                     Busy = !Busy;
00153                     break;
00154                 case 'L':
00155                     nAck = !nAck;
00156                     break;
00157                 default:
00158                     ; 
00159             }
00160         }
00161     }
00162 }