Wednesday 22 February 2012






PROJECT CODE:

                              This project code is for the Visual C++ 6.0.





/******************************** PARALLEL PORT INTERFACING ********************************/


#include <iostream>                                                //Header for cout and cin.
#include <windows.h>                                            //Sleep time.
#pragma comment (lib,"./Inpout32.lib")                            //For getting access to the port.

using namespace std;                                          
void _stdcall Out32(short PortAddress, short data);              
int binEq(int control_array[]);                                    /*Function prototype for converting
                                                                  binary to decimal*/
int main()                                                        //Main function
{
    int  data=0;                                   //Creating the array and variable.

    while(!GetAsyncKeyState(VK_ESCAPE))                            //Loop for sending data until Escape is pressed.
    {          
        int control_array[8]={0,0,0,0,0,0,0,0};                    //Initializing the array to zero.
      
        cout <<"            PARALLEL PORT INTERFACING                "<<endl<<endl;
        cout <<"Controlling an RC Car via LPT1"<<endl<<"                USER GUIDE"<<endl<<endl;
        cout <<"Press UP key to move FORWARD"<<endl;            //Displaying functions of keys.
        cout <<"Press DOWN key to move BACKWARD"<<endl;            //for the help of user.
        cout <<"Press LEFT key to turn LEFT"<<endl;      
        cout <<"Press RIGHT key to turn RIGHT"<<endl;          
        cout <<"Press ESCAPE key to EXIT "<<endl<<endl;

/******************************** CHECKING THE KEY STATES ********************************/
      
        if (GetAsyncKeyState(VK_UP))                        //If key is pressed condition is true
        {                                                        //body of if will be executed.
            cout << "            FORWARD\t";                                    //display the function of the key.
            control_array[7]=1;                                    //set the corresponding value of the array
        }                                                        //to 1 i.e. give output on pin prescribed.
                      
        if (GetAsyncKeyState(VK_DOWN))                        //similarly checking other key states.
        {
            cout << "            BACKWARD";
            control_array[6]=1;
        }
        if (GetAsyncKeyState(VK_LEFT))
        {
            cout << "            LEFT";
            control_array[5]=1;
        }
        if (GetAsyncKeyState(VK_RIGHT))
        {
            cout << "            RIGHT";
            control_array[4]=1;
        }


//******************************** IF INPUT CONTRADICTS **********************************//
              
        if(control_array[7]==control_array[6])
        {                                                            //If left and right keys are pressed at the same time then nullify both.
            control_array[7]=0;
            control_array[6]=0;
        }
        if(control_array[5]==control_array[4])
        {                                                            //If forward and backward keys are pressed at the same time then nullify both.
            control_array[5]=0;
            control_array[4]=0;
        }

//********************************** SENDING DTAT TO LPT1 **********************************//
      
        data = binEq(control_array);                                //Converting into decimal equivalent.
        cout << endl << endl << "Decimal Equivalent is: " << data << endl;    //to get the number of pin activated.
        Out32(0x378,data);                                            //Sending data to LPT1(Parallel port).
      
//********************************** DISPLAYING ACTIVATED PIN NUMBER **********************************//
        {
            if (control_array[7] == 1)
            cout << endl << "Pin no. 2 is ACTIVATED" ;
            if (control_array[6] == 1)
            cout << endl << "Pin no. 3 is ACTIVATED" ;
            if (control_array[5] == 1)
            cout << endl << "Pin no. 4 is ACTIVATED" ;
            if (control_array[4] == 1)
            cout << endl << "Pin no. 5 is ACTIVATED" ;
        }

        Sleep(20);                                                    //refresh rate preventing the wastage of CPU cycles.
        system("cls");                                                //Clear the screen.
    }
    return 0;
}

int binEq(int control_array[] )                    //Function defination.
{                                                //A function to convert an 8 digit binary number into decimal
    int data=0;
    for(int n=0;n<8;n++)
    {
        data = (2*data+control_array[n]);                                  
    }                                                              
    return data;
}







PROJECT DETAILS:


There were many stages of the project so we will discuss them step by step.


STAGE-1

There are two types of remotes available in the market.
One uses a physical short circuiting and open circuiting   to control the device.
Second uses variable resistances for the same purpose
After analyzing the circuitry of remote we discovered that our RC Car used the first method to operate. Therefore we now had the direction to work in circuit design.



STAGE-2

 We used bread board to work on the circuit. In the circuit we used transistors which were so connected that they would work as a switch in the circuit. We used an n-p-n transistor in which Base was connected to the cable where as Emitter and Collector were connected to the circuit. This configuration is commonly known as use of transistor as a switch.
The circuit works such that when a signal is provided at the base, it will act as a short, making the circuit complete and allowing the remote to operate the object accordingly.











In order to have check on the performance of circuit and avoid any confusion in case of malfunction we connected LED’s with each transistor so that when a voltage is provided to the base of a transistor, LED will glow to show that which one of the four transistors is functional. Therefore we can also know immediately about any error in circuit by looking at LED’s.

STAGE-3

In the third stage we had to make a program to access the parallel port using C++. At this stage we realized that most of our instructors and seniors had only one advice for us and that was to use Turbo C. This seemed to be very unrealistic approach that developers of C++ had not made it to be able to make an application of windows. So we had a real hard time in finding the answer to this question. After we had lost all hope we accidentally came across a header file that was meant to be used for accessing parallel port C++.



The above file accessed the port directly so there was no further need of programming on Turbo C.






The above function, out32 was used to send the data to the parallel port.


The above function binEq was used to convert the input into a decimal number.
 This decimal number had then to be converted to binary by parallel port itself. Therefore the decimal number had to be such that it would result in an appropriate output at the desired pin of parallel port.


The same output will appear at the end of connecting cable thus providing voltage to the base of transistor.



The above figure shows the use of another header file windows.h for win32 applications. This file was included because we had to use its function “Sleep()” which is shown in above figure. The sleep function provides two advantages
It makes sure that cycles of c.p.u are not wasted
Screen refresh rate is slower so the input given by user is also readable


This code was used to check if a button was pressed by the user or not and if the button was pressed the array initialized in main function would get the assigned value and the further steps would take place as mentioned earlier.


RESULT


We made various circuit on WARROW BOARD, PRINTED CIRCUIT BOARD & BREAD BOARD, finally the last one worked. We also tried to use a BUFFER to make the circuit work more effectively but it did not work so we had to remove that from our circuit design. Similarly we used <conio.h> to get input from user but then discovered a better and more effective way to watch over the control keys in the form of
GetAsyncKeyState(VK_key name).


CONCLUSION


Things related to circuit were really problematic but as a result we learnt a lot. We came to know about the use of transistor as a switch and also realized that the project which seemed too difficult in the beginning was a source of speedy learning and confidence building along with the improvement in our team work abilities. Generally speaking I can say that this project was a great source of learning for all of us, it also built our interest in working on more projects related to our daily life.

REFERENCES


http://msdn.microsoft.com/library/default.aspx
http://www.electronics-project-design.com
http://en.wikipedia.org/wiki/Wikipedia
http://www.codeproject.com/kb/cpp/

No comments:

Post a Comment