Thread: Reading a 16 bit Register

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    278

    Reading a 16 bit Register

    Greetings all... (I'm using Borland Turbo C/C++ 3.0)

    I am using an ADC board (See Getting Started Sheet) attached to an SBC running DOS 6.2. There is only a sparse and seemingly rough documentation for the ADC. The board has a FIFO for reading the 24 channels. When I read from address BASE+0x0A (ADCFIFO), and then the internal pointers should advance to the next channel from the FIFO (Each address is actually 16-bit. I'm using inport(ADC_FIFO_REG) to read the data from the ADC. However, for some reason, the FIFO pointer actually moves 2 channels instead of 1. If I use inportb(ADC_FIFO_REG) (and therefore only get the LSB) the internal pointer only moves one channel. So I tried reading each byte of the FIFO in turn (I tried in both possible orders) which, again, caused the FIFO to advance 2 channels.

    Is there another function or method I could use to read these registers? I have a feeling that there is an issue with the board itself, but then it could just be that I feel that way because of the pretty crappy state of the "manual" that they have for this board.

    Any suggestions are welcome. I will post the full code if necessary.

    Thanks,
    Lee

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    How about inportw() ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    I get an undefined error for inportw()

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    I tried using inp(), inpw(), inport(), and inportb().

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Write your own.
    Call it inportw()
    Containing a few asm instructions to input a 16 bit value from a port.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    asm?

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    short x = inport(0x123);
    should work right.

    You will need to include "dos.h" (it may well be that it's a macro rather than a function, perhaps).

    If that doesn't work, then as Salem says, you may need to write your own inline-assembler function.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    Yeah that's what I originally tried (inport). I've never written inline assembler functions before... always fun to learn something new

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-06-2005, 03:53 PM
  3. bit patterns of negtive numbers?
    By chunlee in forum C Programming
    Replies: 4
    Last Post: 11-08-2004, 08:20 AM
  4. Register
    By sean345 in forum C Programming
    Replies: 7
    Last Post: 05-08-2002, 03:06 PM
  5. 16 bit colors
    By morbuz in forum Game Programming
    Replies: 13
    Last Post: 11-10-2001, 01:49 AM