outportb(); Variables?

This is a discussion on outportb(); Variables? within the C Programming forums, part of the General Programming Boards category; I am designing a program to work with a circuit I created. I'm just using a 16-bit base DOS compiler ...

  1. #1
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002
    Posts
    77

    outportb(); Variables?

    I am designing a program to work with a circuit I created. I'm just using a 16-bit base DOS compiler because I don't understand the CreateFile() function yet...here's the code:

    Code:
    #include <stdio.h>
    #include <dos.h>
    
    void main(void)
    {
    	int a;
    	char LPT[]="6F28767C395D5F687F7D";
    
    	printf("\n\n\tDisplay Number (0 to 9): ");
    	scanf("%i",&a);
    
    	if ((a>9) || (a<0))
    	{
    		printf("\n\tInvalid Number!  (0 to 9 Only)");
    	}
    
    		
    	a*=2;
    	outportb(0x378,0xLPT[a],LPT[a+1]);
    }
    When the outportb() function is run, what will it send to the 0x378 location? Say a=0....Would it send 0x6F to the x378 location? I know the code works with printf...it prints out the right array values...I just don't know if I can use a combination of letters, then a variable like that...?

    Last question...would using an array like that work faster than just using a switch statement and making a case for each number?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > void main(void)
    Nope, its
    int main(void)

    > outportb(0x378,0xLPT[a],LPT[a+1]);
    Read the manual page - does it take 3 params?

    Try
    outportb(0x378,LPT[a]);
    outportb(0x378,LPT[a+1]);

  3. #3
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002
    Posts
    77
    Could I just do:

    Code:
    outportb(0x378,0xLPT[a]LPT[a+1]);
    ? If i don't put 0xLPT[a] and I JUST put LPT[a] will it recognize the character has hexadecimal, and send that, or will it send the ASCII character value?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    If you really want to send those bytes as hex, then write that in the first place

    char LPT[]="\x6F\x28\x76\x7C\x39\x5D\x5F\x68\x7F\x7D";

    And drop the a*=2 bit as well, since you now have real hex bytes coded in one character, not two hex-ascii chars

    The result is simply
    outportb(0x378,LPT[a]);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  3. esbo's data sharing example
    By esbo in forum C Programming
    Replies: 49
    Last Post: 01-08-2008, 10:07 PM
  4. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  5. Craps Program with Local Variables
    By tigrfire in forum C Programming
    Replies: 12
    Last Post: 11-09-2005, 08:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21