请教下面和QBasic相对应的C语句

mesa 2003-04-09 05:25:04
我有一个很早以前,QBasic版的A/D板卡数据采集程序,现在想把它用C语言改写,下面几个语句,不知道该怎么写,请教:
QBasic语句:
10 BASE%=&H280 ,因该版是插在计算机内的槽上的(就是声卡那些插的地
方,原谅我不知道专业名字怎么说),所以,我认为H280
应该是指向一个硬件的基地址
20 INPUT "Input channel #";NUM
30 Reg=&H00
40 OUT BASE%+4,Reg
50 OUT BASE%,Num
60 OUT BASE%+1,0
70 POLL%=INP(BASE%+1)
.........................................
我的问题是,在QBasic中的OUT和INP函数,应该怎么转化为C程序(不想调用汇编语言)。我查了很多C的函数,除了标准输入输出以及对文件操作的一些函数,都好像都不能直接之想一个硬件地址进行操作。请教,那位能帮我写一下?
...全文
21 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
mesa 2003-05-17
  • 打赏
  • 举报
回复
怎么结账阿,不会
zhouzhaohan 2003-04-09
  • 打赏
  • 举报
回复
要看你的CPU对外围的芯片地址空间的访问是采用I/O方式,还是memory map方式,如果是前者的话应该可以使用我提供的函数,或者我的楼上提供的函数,如果是后者的话,你把那些地址当作普通的内存地址访问就行。
zhouzhaohan 2003-04-09
  • 打赏
  • 举报
回复

nport, inportb, outport, outportb <DOS.H>

- inport reads a word from a hardware port
- inportb reads a byte from a hardware port
- outport outputs a word to a hardware port
- outportb outputs a byte to a hardware port

Declarations

- int inport(int portid);
- unsigned char inportb(int portid);
- void outport(int portid, int value);
- void outportb(int portid, unsigned char value);

Remarks

inport works just like the 80x86 instruction IN. It reads the low byte of a word from portid, the high byte from
portid + 2.

inportb is a macro that reads a byte

outport works just like the 80x86 instruction OUT. It writes the low byte of value to portid, the high byte to
portid + 1.

outportb is a macro that writes value


Argument What It Is



portid Input port that inport and inportb read from; output port that outport and outportb
write to
value Word that outport writes to portid; byte that outportb writes to portid.


If you call inportb or outportb when DOS.H has been included, they are treated as macros that expand to
inline code.

If you don't include DOS.H, or if you do include DOS.H and #undef the macro(s), you get the function(s) of
the same name.

Return Value

inport and inportb return the value read

outport and outportb do not return

Portability

DOS UNIX Windows ANSI C C++ only
yes yes

See Also

inp, inpw
outp, outpw
leasun 2003-04-09
  • 打赏
  • 举报
回复
在VC下有个inp,你查查帮助吧
hxzhappy 2003-04-09
  • 打赏
  • 举报
回复
#include <stdio.h>

main(){

int n=0;

printf("input a string:\n");

while(getchar()!='\n') n++;

printf("%d",n);

}

hxzhappy 2003-04-09
  • 打赏
  • 举报
回复
getchar()或者 getcharb() 函数不行吗?

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧