Thread: Parallel port interfacing

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    2

    Parallel port interfacing

    Hey guys!
    i am supposed to make a C based university first year project... i go for interfacing a parallel port with an RC car..

    i have accessed the parallel port using USERPORT... and it went fine..

    when i press any key it send respective bits on the parallel port which 'on' the transistor and Car runs... but the problem is when i press any key for example 'a' it sends the bit on the parallel port, but it is sending constantly.. means it sends a bit to parallel port untill other key is not pressed... Resulting; i can not use 2 buttons at the same time, if i want to move a car forward n left i am helpless...
    i have used the Delay command after sending each bit but it is not working... Please help!!!!
    Sorry for my bad english!
    Here is the coding..
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    344
    Keep track of the current value you're sending to the parallel port. Each keypress modifies this value (via bitwise or to set it / bitwise and to clear it / bitwise xor to toggle it), which is then sent to the parallel port after each keypress. Since you're keeping track of the current value already sent, you modify this value as needed based on keypresses so you can combine various states into one outportb call.

    An example with numbers 1 to 8 to set bits 1 through 8, and shift-1 (!) through shift-8 (*) to clear the same bits.
    Code:
    unsigned char port_val = 0;
    int ch;
    do
    {
      ch = getch();
      switch (ch)
      {
        case '1':
          port_val |= 0x01;
          break;
        case '2':
          port_val |= 0x02;
          break;
    ...
        case '8' :
          port_val |= 0x80;
          break;            
        case '!' : /* use shift-1 to clear bit 1 */
          port_val &= ~0x01;
          break;
        case '@' :
          port_val &= ~0x02;
          break;
    ...
        case '*' :
          port_val &= ~0x80;
          break;
      }
      outportb(0x378, port_val);
    }
    while (ch != 'e');

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    2
    @KCfromNC:
    Buddy, i am C beginner what ever you coded above i couldn't understand a bit...
    Can you make your words simpler? PLEASE!

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    344
    Which part didn't you understand?
    Take a look at Cprogramming.com - Tutorials - Bitwise Operators and Bit Manipulations in C and C++ for info on what the bitwise operators do. Add a "printf("%2.2x", port_val);" right before or after the outportb() call, compile my code (remove the ... for now) and see what happens.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. RS232 serial port interfacing on Mac OS X
    By Mini in forum C Programming
    Replies: 4
    Last Post: 11-23-2011, 12:52 PM
  2. Parallel Port in XP
    By torqu3e in forum C++ Programming
    Replies: 6
    Last Post: 01-30-2011, 09:33 AM
  3. problem interfacing in parallel port
    By tariq7868 in forum C Programming
    Replies: 4
    Last Post: 06-08-2009, 03:53 AM
  4. LPT Port Interfacing
    By ScriptBlue in forum Windows Programming
    Replies: 3
    Last Post: 06-10-2005, 03:13 PM
  5. parallel port interfacing
    By surdy in forum C Programming
    Replies: 3
    Last Post: 10-17-2004, 08:17 AM