Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

4 by 4 keypad interfacing with parallel port and it display at computer screen

Status
Not open for further replies.

imran00

Newbie level 4
Newbie level 4
Joined
May 31, 2011
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,323
I'm supposed to design and implement a simple circuit that will scan a 4-by-4 keypad and display the key pressed on computer screen. The catch of the whole project was that this was to be done using a standard parallel PC parallel printer port (DB-25), which was connected to a 4-by-4 keypad.

My problem is that I do not know how to do the code in c++ for this!

I am confused because I do not know how to make the code in c++ for the parallel printer port to read what key was pressed on the keypad, and after reading it...to display it on the computer screen.

SO LOST! HELP!
 

Checkout this site:

KEYPAD INTERFACING
This section i will explain about connecting keypad to the parallel port. Let's see the keypad connection. A normal keypad costs around Rs.150. A keypad has a problem of keydebouncing and we have to eliminate it in our program.




If you join the author's yahoo group, he will let you down this book covering this interface for free.

It covers the project you're working on in detail.

Good Luck
 
how is your c programming skills?
I wrote, long time ago, a program that write values on parrallel port... never tried to read, but seems to be very similar.

take a look at this link: **broken link removed**

and here is my old code for a 32bits OS (windows):

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <windows.h>
 
const int LPT1 = 0x378;             //lpt1 address
 
typedef short _stdcall (*PtrInput)(short EndPorta);
typedef void _stdcall (*PtrOutput)(short EndPorta, short value);
 
PtrInput InPortB = NULL;
PtrOutput OutPortB = NULL;
HINSTANCE hLib = NULL;
 
 
void LoadDLL();
 
int main (int argc, char *args[])
{
    LoadDLL();          // function to load the dll file
 
    OutPortB(LPT1, 0);      // function to write values
    
    short value = InPortB(LPT1);  // function to read values, variable 'value' will receive the value
 
 
    return 0;
}
 
 
void LoadDLL()
{
    hLib = LoadLibrary("inpout32.dll");
    
    if (hLib == NULL)
    {
             std::cout << "cant load the .dll file\n";
             system("PAUSE");
             exit(1);
    }
    
    InPortB = (PtrInput) GetProcAddress(hLib, "Inp32");
    
    if (InPortB == NULL)
    {
             std::cout << "error in inicialization of inportb\n";
             system("PAUSE");
             exit(1);
    }
    
    OutPortB = (PtrOutput) GetProcAddress(hLib, "Out32");
    
    if (OutPortB == NULL)
    {
             std::cout << "error in inicialization of outportb\n";
             system("PAUSE");
             exit(1);
    }
}



in this case I use the inpout32.dll for a 32 bits windows, if you will use a 64 bits windows you have to download the Inpoutx64.dll ( you can find it in the link above ).

the dll file must be in the same dir as your compiled program.

if you have any questions, just ask!

Iuri~
 

how is your c programming skills?
I wrote, long time ago, a program that write values on parrallel port... never tried to read, but seems to be very similar.

take a look at this link: **broken link removed**

and here is my old code for a 32bits OS (windows):

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <windows.h>
 
const int LPT1 = 0x378;             //lpt1 address
 
typedef short _stdcall (*PtrInput)(short EndPorta);
typedef void _stdcall (*PtrOutput)(short EndPorta, short value);
 
PtrInput InPortB = NULL;
PtrOutput OutPortB = NULL;
HINSTANCE hLib = NULL;
 
 
void LoadDLL();
 
int main (int argc, char *args[])
{
    LoadDLL();          // function to load the dll file
 
    OutPortB(LPT1, 0);      // function to write values
    
    short value = InPortB(LPT1);  // function to read values, variable 'value' will receive the value
 
 
    return 0;
}
 
 
void LoadDLL()
{
    hLib = LoadLibrary("inpout32.dll");
    
    if (hLib == NULL)
    {
             std::cout << "cant load the .dll file\n";
             system("PAUSE");
             exit(1);
    }
    
    InPortB = (PtrInput) GetProcAddress(hLib, "Inp32");
    
    if (InPortB == NULL)
    {
             std::cout << "error in inicialization of inportb\n";
             system("PAUSE");
             exit(1);
    }
    
    OutPortB = (PtrOutput) GetProcAddress(hLib, "Out32");
    
    if (OutPortB == NULL)
    {
             std::cout << "error in inicialization of outportb\n";
             system("PAUSE");
             exit(1);
    }
}



in this case I use the inpout32.dll for a 32 bits windows, if you will use a 64 bits windows you have to download the Inpoutx64.dll ( you can find it in the link above ).

the dll file must be in the same dir as your compiled program.

if you have any questions, just ask!

Iuri~

thanks alot

plese guide me which pins of keypad connect with which number of pins of parallel port i mean i connect them only with data pins or i connect them with control or stadus pins too?
and have i need external supply?

---------- Post added at 10:42 ---------- Previous post was at 10:41 ----------

plese i need urgently
 

you said before that you are going to read the values pressed in key pad and send to your computer, i never done something like that before. To read values from parallel port you need to use the status pins, you have 5 status pins that you can use as input:

busy -> pin 11
ack -> pin 10
paper end -> pin 12
slct out -> pin 13
error -> pin 15

when you read from the parallel port you will get a byte (status register), with just only 5 bits valid (bits listed above ).

I need to go at class at this moment, so i have short time to help you. Take a search about db25 pins, status register and key pad interfacing. I'll able to answer your doubts later.

Iuri~
 
news? have you found the things i told you? questions? doubts? just let me know

Iuri~
 

news? have you found the things i told you? questions? doubts? just let me know

Iuri~

thank you sir i am trying after that i will tell you
 

news? have you found the things i told you? questions? doubts? just let me know

Iuri~

sir i run your program it executed but my keypad is not working..i check all data and status & control pins voltages and connect keypad's pins properly as you told me.
after that i changed connections mean i connect all keypad's pins with all data pins but still no result.
i use "LPT" for checking port working it shows that all pins are working i check them with LED's too...my keypad is also good there is no fault
actully i need a program
plese help me
 

are you using the exact code i wrote above? it's just a example of how you load and use the dll file.
which version of windows are you running it? to use the port you have to release the parallel port acess.

I'll write a code to you, and will post it here. sorry if I'm being a little confusing, i'll try to be more specific.

Iuri~
 

Ok, I wrote 2 codes, one for receive from parallel port and another to send. I havent tested those codes because I dont have a computer with parallel port.

This is for receiver. The application just keep reading status register and comparing with the last one read, if the new value is different of the last value then it write the new value in prompt


Code C++ - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <windows.h>
 
const int LPT1_DATA_REGISTER    = 0x378;            //WRITE (pins D0, D1, D2, D3, D4, D5, D6, D7)
const int LPT1_STATUS_REGISTER  = 0x379;            //READ  (pins BUSY, ACK, PAPER END, SLCT OUT, ERROR)
 
typedef short _stdcall (*PtrInput)(short EndPorta);
typedef void _stdcall (*PtrOutput)(short EndPorta, short valor);
 
PtrInput InPortB = NULL;
PtrOutput OutPortB = NULL;
HINSTANCE hLib = NULL;
 
void LoadDLL();
 
int main (int argc, char *args[])
{
    LoadDLL();
 
    unsigned char value = InPortB(LPT1_STATUS_REGISTER); // first value acquired
    std::cout << "First value acquired: " << value << "\n";
 
    while ( true )
    {
        unsigned char newValue = InPortB(LPT1_STATUS_REGISTER);         // read the new value
 
        if ( value == newValue )            // check if the value has changed
        {
            std::cout << "New value received (decimal): " << newValue << "\n";
            value = newValue;       // keep the new value
        }
    }
 
    return 0;
}
 
 
void LoadDLL()
{
    hLib = LoadLibrary("inpout32.dll");
    
    if (hLib == NULL)
    {
             std::cout << "cant load the .dll file\n";
             system("PAUSE");
             exit(1);
    }
    
    InPortB = (PtrInput) GetProcAddress(hLib, "Inp32");
    
    if (InPortB == NULL)
    {
             std::cout << "can not start inportb\n";
             system("PAUSE");
             exit(1);
    }
    
    OutPortB = (PtrOutput) GetProcAddress(hLib, "Out32");
    
    if (OutPortB == NULL)
    {
             std::cout << "can not start outportb\n";
             system("PAUSE");
             exit(1);
    }
}



I have attached a image of how is the status register format. You have to know it to build your keypad logic.

status_register.png

this one is for write data on pins D0 to D7. it is just a counter from 0 to 255 with 1000 ms of delay.


Code C++ - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <windows.h>
 
const int LPT1_DATA_REGISTER    = 0x378;            //WRITE (pins D0, D1, D2, D3, D4, D5, D6, D7)
const int LPT1_STATUS_REGISTER  = 0x379;            //READ  (pins BUSY, ACK, PAPER END, SLCT OUT, ERROR)
 
typedef short _stdcall (*PtrInput)(short EndPorta);
typedef void _stdcall (*PtrOutput)(short EndPorta, short valor);
 
PtrInput InPortB = NULL;
PtrOutput OutPortB = NULL;
HINSTANCE hLib = NULL;
 
void LoadDLL();
 
int main (int argc, char *args[])
{
    LoadDLL();
 
    OutPortB(LPT1_DATA_REGISTER, 0x00);             //Clean the data pins
 
    for (int i = 0; i < 256; i++)                   //counts 0 to 255
    {
        OutPortB(LPT1_DATA_REGISTER, i);            //Send the i value to port
        Sleep(1000);                                //Wait 1 sec
    }
 
    OutPortB(LPT1_DATA_REGISTER, 0x00);             //Clean the data pins
 
    return 0;
}
 
 
void LoadDLL()
{
    hLib = LoadLibrary("inpout32.dll");
    
    if (hLib == NULL)
    {
             std::cout << "cant load the .dll file\n";
             system("PAUSE");
             exit(1);
    }
    
    InPortB = (PtrInput) GetProcAddress(hLib, "Inp32");
    
    if (InPortB == NULL)
    {
             std::cout << "can not start inportb\n";
             system("PAUSE");
             exit(1);
    }
    
    OutPortB = (PtrOutput) GetProcAddress(hLib, "Out32");
    
    if (OutPortB == NULL)
    {
             std::cout << "can not start outportb\n";
             system("PAUSE");
             exit(1);
    }
}



to release the port access i had used an application called UserPort: The official UserPort homepage on windows XP. I dont know how to release these ports on vista and seven, you have to look for it by your self. If you have a computer with windows xp to test it, is the better option you may have now

you probaly know, but for safety let me remind you that a short-circuit or any other misuse may damage your computer hardware, so be careful!

would be nice if you let me see the schematics of your project, will help a lot.

try to implement these codes above and let me know your results and doubts.

Iuri~
 

Ok, I wrote 2 codes, one for receive from parallel port and another to send. I havent tested those codes because I dont have a computer with parallel port.

This is for receiver. The application just keep reading status register and comparing with the last one read, if the new value is different of the last value then it write the new value in prompt


Code C++ - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <windows.h>
 
const int LPT1_DATA_REGISTER    = 0x378;            //WRITE (pins D0, D1, D2, D3, D4, D5, D6, D7)
const int LPT1_STATUS_REGISTER  = 0x379;            //READ  (pins BUSY, ACK, PAPER END, SLCT OUT, ERROR)
 
typedef short _stdcall (*PtrInput)(short EndPorta);
typedef void _stdcall (*PtrOutput)(short EndPorta, short valor);
 
PtrInput InPortB = NULL;
PtrOutput OutPortB = NULL;
HINSTANCE hLib = NULL;
 
void LoadDLL();
 
int main (int argc, char *args[])
{
    LoadDLL();
 
    unsigned char value = InPortB(LPT1_STATUS_REGISTER); // first value acquired
    std::cout << "First value acquired: " << value << "\n";
 
    while ( true )
    {
        unsigned char newValue = InPortB(LPT1_STATUS_REGISTER);         // read the new value
 
        if ( value == newValue )            // check if the value has changed
        {
            std::cout << "New value received (decimal): " << newValue << "\n";
            value = newValue;       // keep the new value
        }
    }
 
    return 0;
}
 
 
void LoadDLL()
{
    hLib = LoadLibrary("inpout32.dll");
    
    if (hLib == NULL)
    {
             std::cout << "cant load the .dll file\n";
             system("PAUSE");
             exit(1);
    }
    
    InPortB = (PtrInput) GetProcAddress(hLib, "Inp32");
    
    if (InPortB == NULL)
    {
             std::cout << "can not start inportb\n";
             system("PAUSE");
             exit(1);
    }
    
    OutPortB = (PtrOutput) GetProcAddress(hLib, "Out32");
    
    if (OutPortB == NULL)
    {
             std::cout << "can not start outportb\n";
             system("PAUSE");
             exit(1);
    }
}



I have attached a image of how is the status register format. You have to know it to build your keypad logic.

View attachment 56821

this one is for write data on pins D0 to D7. it is just a counter from 0 to 255 with 1000 ms of delay.


Code C++ - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <windows.h>
 
const int LPT1_DATA_REGISTER    = 0x378;            //WRITE (pins D0, D1, D2, D3, D4, D5, D6, D7)
const int LPT1_STATUS_REGISTER  = 0x379;            //READ  (pins BUSY, ACK, PAPER END, SLCT OUT, ERROR)
 
typedef short _stdcall (*PtrInput)(short EndPorta);
typedef void _stdcall (*PtrOutput)(short EndPorta, short valor);
 
PtrInput InPortB = NULL;
PtrOutput OutPortB = NULL;
HINSTANCE hLib = NULL;
 
void LoadDLL();
 
int main (int argc, char *args[])
{
    LoadDLL();
 
    OutPortB(LPT1_DATA_REGISTER, 0x00);             //Clean the data pins
 
    for (int i = 0; i < 256; i++)                   //counts 0 to 255
    {
        OutPortB(LPT1_DATA_REGISTER, i);            //Send the i value to port
        Sleep(1000);                                //Wait 1 sec
    }
 
    OutPortB(LPT1_DATA_REGISTER, 0x00);             //Clean the data pins
 
    return 0;
}
 
 
void LoadDLL()
{
    hLib = LoadLibrary("inpout32.dll");
    
    if (hLib == NULL)
    {
             std::cout << "cant load the .dll file\n";
             system("PAUSE");
             exit(1);
    }
    
    InPortB = (PtrInput) GetProcAddress(hLib, "Inp32");
    
    if (InPortB == NULL)
    {
             std::cout << "can not start inportb\n";
             system("PAUSE");
             exit(1);
    }
    
    OutPortB = (PtrOutput) GetProcAddress(hLib, "Out32");
    
    if (OutPortB == NULL)
    {
             std::cout << "can not start outportb\n";
             system("PAUSE");
             exit(1);
    }
}



to release the port access i had used an application called UserPort: The official UserPort homepage on windows XP. I dont know how to release these ports on vista and seven, you have to look for it by your self. If you have a computer with windows xp to test it, is the better option you may have now

you probaly know, but for safety let me remind you that a short-circuit or any other misuse may damage your computer hardware, so be careful!

would be nice if you let me see the schematics of your project, will help a lot.

try to implement these codes above and let me know your results and doubts.

Iuri~



thanks
i have done it
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top