请教下面和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的函数,除了标准输入输出以及对文件操作的一些函数,都好像都不能直接之想一个硬件地址进行操作。请教,那位能帮我写一下?
...全文
39 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() 函数不行吗?
源码来自:https://pan.quark.cn/s/a4b39357ea24 《C++ Primer》作为C++编程领域中的一部权威著作,主要服务于初学者和经验丰富的开发者,致力于帮助他们深入掌握C++的核心知识。 第一章通常会详细讲解C++语言的基础概念和语法结构,包括变量的使用、数据类型的分类、常量的定义、运算符的用以及基础的输入输出操作。 接下来,我们将对这一章中的核心知识点和可能的习题解答进行深入分析。 ### 1. 变量与数据类型在C++编程中,变量被视为存储数据的媒介。 每一个变量都必须预先声明其数据类型,常见的数据类型有整型(int)、浮点型(float)、双精度浮点型(double)以及字符型(char)。 例如:```cppint age = 25; // 声明一个整型变量age并赋予其初始值25float weight = 70.5f; // 声明一个浮点型变量weight并赋予其初始值70.5char grade = A; // 声明一个字符型变量grade并赋予其初始值A```### 2. 常量与字面量常量指的是不可更改的值,可以通过`const`关键字进行声明。 例如:```cppconst int MAX_SIZE = 100; // 声明一个整型常量MAX_SIZE,其值为100```字面量是指程序中直接书写的值,如`42`、`3.14`或`"Hello"`。 ### 3. 运算符C++提供了多种运算符,涵盖了算术运算符(+,-,*,/,%)、比较运算符(==,!=,<,>,<=,>=)、逻辑运算符(&&,||,!)以及赋值运算符(=,+=,-=,*=,/=,%=)等。 ### 4. 输入与输出在C++中,使用`std::cin`来实现输...

24,855

社区成员

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

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