Write data to I/O Port address

This is a discussion on Write data to I/O Port address within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I want to write a function in C++ to do the "channel selection" for a hardware which is a A-to-D ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    4

    Write data to I/O Port address

    I want to write a function in C++ to do the "channel selection" for a hardware which is a A-to-D card with 16 channels.

    The information provided by the card manual is here:
    I/O port address H278: output A/D channel number (low nibble)

    I want to know how to write the code. Can you give me some examples in your explanation. Thanks

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    I'm not sure I understand what you want. So here is my feeble attempt at answering your question.

    Sound card?
    First is this a sound card? If it is then I'm not familiar with multiple channels on a sound card. Multiple channels is basically software related and not hardware. Take for example a sound system in an auditorium. You have channels for guitar, keyboard, vocals, etc. All of the data or signals is sent to the mixer board which combines all of the channels into one signal that represent the mixture of the data. The signal is then sent to the amplifier and then to the speakers, etc. This is of course barring any effects like reverb and what have you, but you get the idea. Same thing is true in software. The sound card uses DMA transfer which basically only uses one portion of memory which could be considered the final or main mix of the sounds. Each individual sound or channel is basically a portion of memory that contains the data for one sound. The software then retrieves the byte or word data from each sound and performs some type of mixing algorithm which then results in the master or main mix.
    I'm not aware of actual hard-coded channels on any sound card as this would probably be a waste of circuitry - but I'm not saying they do not exist - I just have not heard of them.

    Low and high nibbles
    A low nibble is the lower bits of a byte, word or dword.

    In real and virtual 8086 mode
    Byte: 8 bits (2 nibbles)
    Word: 16 bits (2 bytes)
    DWord: 32 bits (4 bytes, 2 words)

    The low nibble of a byte is the lower 4 bits and the high nibble is the upper 4 bits. So you need to mask out the lower 4 bits of the byte.

    In binary
    11111111
    AND
    00001111
    EQUALS
    00001111

    So 00001111 is the bitmask that will effectively mask the lower 4 bits. Convert this to hexadecimal and you have your bitmask.

    But what you want to do is even easier than that. Since your channel number will only be in the range from 0 to F (decimal 15) (16 channels counting 0) you can simply just pass that value to the port and it should work.

    Perhaps I'm not understanding what you want but the low nibble portion here seems to be irrelevant based on the information you have given because 0 to F will always be in the lower nibble of the byte.

    1*(2^0)+1*(2^1)+1*(2^2)+1*(2^3) or

    1+2+4+8 or

    15

    which is 0Fh in hex and

    00001111 in binary (0's are included to show a complete byte).

    Notice that numbers in the range 0 to 15 are always contained in the low nibble of the byte. Please give more information so that I can help you - otherwise the answer to your question is:

    outp(0x0278,channelnumber);

    where channel number is in the range 0x00 to 0x0F.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    4

    Write data to I/O Port address

    Thank you very much, Bubba, Your help is very useful!
    Here I give u more information and hope you can understand what I want to do.
    Actually, the hardward is an Analog-to-digital (A-D) conversion card with resolution 12-bit and ISA slot. It's not a sound card.
    Now, I need to develop a user programme using C/C++ to drive the card.

    The programme can be able to:
    1. select a channel (from 16 channels)
    2. clear A-D register memory and then capture the analog singal(i.e. sampling), then convert it into digital form(binary number)
    3. save the digital data into file
    4. open data file and plot it in graph
    5. adjust some setting e.g. sampling frequency, sampling time ...

    Now, the 1st function seems to be completed. I want to go on for the 2nd function:

    The manual provide me with the following information:
    I/O port address Description
    H27B Clear register
    H27C A/D conversion loop(low)
    H27D A/D conversion loop(high)


    The manual suggest a programming technique:
    Clear register
    OUT (port +3), 0

    Should I put '0' in 0x027B to clear the register. But which channel's register will be cleared by doing this? How should I know that?

    Then, to start conversion, the manual suggest:

    FOR I=1 to 5
    A = INP (port +4)
    NEXT I=1 to 9
    A = INP (port +5)
    NEXT I

    To read high byte(low nibble)
    C = INP (port +2)
    HB = (C/16 -INT(C/16))*16

    To read low byte(8 bits)
    LB = INP (port +1)

    converted data = HB*256 + LB

    I don't know what 'INP' and 'INT' is about? Please explain them to me with sample code if possible. Thanks

    Since my target system to run the programm is DOS, so where can I find a C/C++ compiler for DOS. Window based VC++ cannot compiler a exe programme executable in MS DOS.

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    What is that port variable in your code? Is that the offset of a channel? Your AD-conversion card, is it a data acquisition card with 16 channels, in other words, with 16 inputs for data acquisition?

    I don't know the language the manual uses. But I think:
    OUT - write to port
    INP - read from port
    INT - make integer of a number, such like INT (5/2) = 3

    Here you can find ports for GCC (C and C++), I'm not sure if they also have a DOS-port.

    www.delorie.com/djgpp

    Another compiler is the Pacific C compiler:

    http://www.htsoft.com/products/pacific.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Overlapped I/O and Completion Port :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 10-30-2002, 04:14 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Im so lost at . .
    By hermit in forum C Programming
    Replies: 18
    Last Post: 05-15-2002, 01:26 AM

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