C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-03-2009, 11:37 PM   #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
Bladactania is offline   Reply With Quote
Old 07-04-2009, 03:49 AM   #2
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
How about inportw() ?
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 07-04-2009, 01:23 PM   #3
Registered User
 
Join Date: Feb 2009
Posts: 278
I get an undefined error for inportw()
Bladactania is offline   Reply With Quote
Old 07-04-2009, 01:36 PM   #4
Registered User
 
Join Date: Feb 2009
Posts: 278
I tried using inp(), inpw(), inport(), and inportb().
Bladactania is offline   Reply With Quote
Old 07-04-2009, 02:14 PM   #5
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
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.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 07-04-2009, 03:02 PM   #6
Registered User
 
Join Date: Feb 2009
Posts: 278
asm?
Bladactania is offline   Reply With Quote
Old 07-04-2009, 03:05 PM   #7
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline   Reply With Quote
Old 07-04-2009, 03:15 PM   #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
Bladactania is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmentation fault ith g_type_check_class_cast () from /usr/lib/libgobject-2.0.so.0 lehe Game Programming 7 02-02-2009 07:27 AM
SSH Hacker Activity!! AAHHH!! Kleid-0 A Brief History of Cprogramming.com 15 03-06-2005 03:53 PM
bit patterns of negtive numbers? chunlee C Programming 4 11-08-2004 08:20 AM
Register sean345 C Programming 7 05-08-2002 03:06 PM
16 bit colors morbuz Game Programming 13 11-10-2001 01:49 AM


All times are GMT -6. The time now is 09:04 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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