lpt.c File Reference

#include "includes.h"

Go to the source code of this file.

Defines

#define ECP_ECR   (0x402)
#define ECR_STANDARD   (0x0)
#define ECR_DISnERRORINT   (0x10)
#define ECR_DISDMA   (0x0)
#define ECR_DISSVCINT   (0x4)

Functions

int GetValidPpt (void)
void SetPptCompMode (void)
int InstallGiveIo (void)
void OpenLpt (void)

Variables

int validPpt


Define Documentation

#define ECP_ECR   (0x402)

Definition at line 45 of file lpt.c.

#define ECR_DISDMA   (0x0)

Definition at line 48 of file lpt.c.

#define ECR_DISnERRORINT   (0x10)

Definition at line 47 of file lpt.c.

#define ECR_DISSVCINT   (0x4)

Definition at line 49 of file lpt.c.

#define ECR_STANDARD   (0x0)

Definition at line 46 of file lpt.c.


Function Documentation

int GetValidPpt ( void   ) 

Definition at line 13 of file lpt.c.

00014 {
00015     // code can't use
00016     /*unsigned int *PtrAddr;
00017     unsigned int LptAddress;
00018 
00019     PtrAddr=(unsigned int *)0x00000408;
00020     LptAddress=*PtrAddr;
00021     printf("\n 1. %8x found at 0x%8x\n",(U32)LptAddress,(U32)PtrAddr);
00022     PtrAddr++;
00023     LptAddress=*PtrAddr;
00024     printf("\n 2. %8x found at 0x%8x\n",(U32)LptAddress,(U32)PtrAddr);
00025     PtrAddr++;
00026     LptAddress=*PtrAddr;
00027     printf("\n 3. %8x found at 0x%8x\n",(U32)LptAddress,(U32)PtrAddr);
00028     */
00029     // search for valid parallel port
00030     _outp(LPT1, 0x55);
00031     if((int)_inp(LPT1) == 0x55)
00032         return LPT1;
00033     
00034     _outp(LPT2, 0x55);
00035     if((int)_inp(LPT2) == 0x55)
00036         return LPT2;
00037     
00038     _outp(LPT3, 0x55);
00039     if((int)_inp(LPT3) == 0x55)
00040         return LPT3;
00041     
00042     return 0;   
00043 }

int InstallGiveIo ( void   ) 

Definition at line 57 of file lpt.c.

00058 {
00059     HANDLE h;
00060     OSVERSIONINFO osvi;
00061     
00062     osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
00063     GetVersionEx(&osvi);
00064     
00065     if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
00066     {
00067     //OS=NT/2000
00068     h = CreateFile("\\\\.\\giveio", GENERIC_READ, 0, NULL,
00069             OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
00070     CloseHandle(h);
00071     if(h == INVALID_HANDLE_VALUE)
00072             return 0;
00073     else
00074         return 0x2000;
00075     }
00076     else
00077     {   //OS=WIN98
00078     return 0x0098;
00079     }
00080 }

void OpenLpt ( void   ) 

Definition at line 82 of file lpt.c.

00083 {
00084     if(!InstallGiveIo())
00085     {
00086         printf("ERROR: Couldn't open giveio.sys\n");
00087         exit(0);
00088     }
00089 
00090     validPpt = GetValidPpt();
00091     if(!validPpt)
00092     {
00093     printf("ERROR: Unable to find a parallel port\n");
00094     exit(0);
00095     }
00096     SetPptCompMode();   
00097 }

void SetPptCompMode ( void   ) 

Definition at line 51 of file lpt.c.

00052 {
00053     //configure the parallel port at the compatibility mode.
00054     _outp(validPpt+ECP_ECR,(ECR_STANDARD | ECR_DISnERRORINT | ECR_DISDMA | ECR_DISSVCINT));
00055 }


Variable Documentation

int validPpt

Definition at line 11 of file lpt.c.


Generated on Sun Jul 19 00:50:39 2009 for PROGRAMER FOR PIC18F87J10 USING LPT PORT by  doxygen 1.5.9