做过dos下二进制文件串口传输的进来讨论一下

zhoushengqun 2003-05-14 03:38:46
rt
...全文
110 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zhoushengqun 2003-05-14
不行,我用的环境是vc1.52,提示语法错误!!
回复
wangcx 2003-05-14
改为这样。
#ifdef __cplusplus
define INTERRUPT ...
#else
define INTERRUPT

void interrupt (*oldser1)(INTERRUPT);
void interrupt (*oldser2)(INTERRUPT);

C++中中断的函数原型是:void interrupt (*oldser2)(...);
C中中断的函数原型是:void interrupt (*oldser2)();
你看看你是不是这个错误。

回复
zhoushengqun 2003-05-14
谢谢,可是下面的两句没有通过,能否指教
void interrupt (*oldser1)();
void interrupt (*oldser2)();
回复
ftai08 2003-05-14
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <ctype.h>
#include <graphics.h>

void interrupt (*oldser1)();
void interrupt (*oldser2)();

int oldmarker;

void interrupt com1int();
void interrupt com2int();

int initscreen();

int disprx(int c);
int disptx(int c);

int getkey();

int initserport(unsigned bps);
int initserreg(unsigned base, unsigned bps);

#define COM1 0X3F8
#define VECT1 0X0C
#define VECT2 0X0B
#define INT_MARK_ADD 0X21
#define ENABLE_COMM 0XE7
#define INT_CONTROL_ADD 0X20
#define ENABLE 0X20 // write 20H to interrupt controller to enable next interr.
#define LINK_CONTROL_WORD 0X3
/* 09H open loop, 13H close loop */
#define MODEM 0X9
/* 01H enable rx int, 02H enable tx int, 03H enable rx&tx, 00H disable all */
#define INTEN 0X1
/* 04H means rx int occur, 02H means tx int occur */
#define INTOCC 0X4
/* 20H meams ready to transmit */
#define READY 0X20

/* define macro for getkey() */
#define BS 0x08
#define HT 0x09
#define ESC 0x1b
#define RETURN 0x0d
#define DEL 0x0153
#define INS 0x0152
#define LEFT 0x014b
#define RIGHT 0x014d
#define UP 0x0148
#define DOWN 0x0150
#define HOME 0x0147
#define END 0x014f
#define PGUP 0x0149
#define PGDN 0x0151
#define F1 0x013b
#define F2 0x013c
#define F3 0x013d
#define F4 0x013e
#define F5 0x013f
#define F6 0x0140
#define F7 0x0141
#define F8 0x0142
#define F9 0x0143
#define F10 0x0144
#define F11 0x0185
#define F12 0x0186

/* Size of receiving buffer */
#define RXBUFFSZ 2000
/* Size of transmiting buffer */
#define TXBUFFSZ 2000

/* row & colume of displaying windows */
#define ROWN 12
#define COLN 16

unsigned char rxbuf1[RXBUFFSZ],rxbuf2[RXBUFFSZ];
unsigned char txbuf1[TXBUFFSZ],txbuf2[TXBUFFSZ];
int rxprt1,rxprt2,pushp1,pushp2,txprt1,txprt2;
int far *scr1buf, *scr2buf;

main(int argn, char *argv[])
{
int i,j,k,n,comnum=1;
unsigned bps=0;

if (argn>1 && (argv[1][0]=='?' || argv[1][1]=='?' ||
toupper(argv[1][0])=='H' || toupper(argv[1][1])=='H')) {
printf("Usage: tt COM BAUD\n"
" COM=1\n"
" BAUD=38400,14400,9600,...,300,150\n"
" default: COM=1,BAUD=9600\n");
return 1;
}
if (argn>1) comnum=atoi(argv[1]);
printf("COM%d ", comnum);
if (argn>2) bps=atol(argv[2]);
if (bps==0) bps=9600;
printf("BAUD: %ld\n", (long)bps);
getch();
initserport(bps);

operation(comnum);

withdraw();
return 0;
}

int withdraw ()
{
setvect(VECT1,oldser1);
setvect(VECT2,oldser2);
outp(INT_MARK_ADD, oldmarker);
disable();

_setcursortype(_NORMALCURSOR);
clrscr();

return 0;
}

int initserport(unsigned bps)
{

rxprt1=rxprt2=0;

oldser1=getvect(VECT1);
oldser2=getvect(VECT2);

setvect(VECT1,com1int);
setvect(VECT2,com2int);

initserreg(COM1,bps);
initserreg(COM2,bps);
oldmarker=inp(INT_MARK_ADD);
outp(INT_MARK_ADD, ENABLE_COMM & oldmarker);
enable();

return 0;
}

int initserreg(unsigned base, unsigned bps)
{
unsigned defrate=38400,factor=3;
int h,l;

factor*=(defrate/bps);
h=factor/0x100;
l=factor%0x100;
outp(base+3,0x80);
outp(base+1,h);
outp(base,l);
outp(base+3,LINK_CONTROL_WORD);
outp(base+4,MODEM);
outp(base+1,INTEN);

return 0;
}

void interrupt com1int()
{
if (inp(COM1+2) & INTOCC) {
rxbuf1[rxprt1]=inp(COM1);
rxprt1++;
if (rxprt1==RXBUFFSZ) rxprt1=0;
}
outp(INT_CONTROL_ADD,ENABLE);
}

void interrupt com2int()
{
if (inp(COM2+2) & INTOCC) {
rxbuf2[rxprt2]=inp(COM2);
rxprt2++;
rxprt2%=RXBUFFSZ;
}
outp(INT_CONTROL_ADD,ENABLE);
}

int operation (int comnum)
{
int key;
int disp=0,com2_head;
int *prt=&rxprt1,*com2_tail=&rxprt2;
unsigned char *buf=rxbuf1,*com2_buf=rxbuf2;

initscreen();

while (1) {
if (disp!=*prt) {
disprx((unsigned)buf[disp]);
disp++;
disp%=RXBUFFSZ;
}
if (com2_head!=*com2_tail)
{
disptx((unsigned)com2_buf[com2_head]);
com2_head++;
com2_head%=TXBUFFSZ;
}
if (kbhit()) key=getkey();
if (key==F12) break;
}

return 0;
}



int disprx(int c)
{
static int x=0,y=0;
unsigned char hh,ll;
char tb[5];

sprintf(tb,"%04X",c);
scr1buf[y*80+x*3]=0x0700+tb[2];
scr1buf[y*80+x*3+1]=0x0700+tb[3];
scr1buf[y*80+x+60]=0x0700+c;

x++;
if (x>=COLN) {
x=0;
y++;
if (y>=ROWN) {
y=ROWN-1;
movmem(scr1buf+80,scr1buf,2*80*(ROWN-1));
memset(scr1buf+80*(ROWN-1),0,2*80);
}
}

return 0;
}

int disptx(int c)
{
static int x=0,y=0;
unsigned char hh,ll;
char tb[5];

sprintf(tb,"%04X",c);
scr2buf[y*80+x*3]=0x0700+tb[2];
scr2buf[y*80+x*3+1]=0x0700+tb[3];
scr2buf[y*80+x+60]=0x0700+c;

x++;
if (x>=COLN) {
x=0;
y++;
if (y>=ROWN) {
y=ROWN-1;
movmem(scr2buf+80,scr2buf,2*80*(ROWN-1));
memset(scr2buf+80*(ROWN-1),0,2*80);
}
}

return 0;
}

int initscreen()
{
int gd, gm;

_setcursortype(_NOCURSOR);
clrscr();

gotoxy(1,13);
cprintf("----------- \x18 RECEIVED DATA ----"
" \x19 TRAMSMITING DATA --- (F11:null F12:exit");
detectgraph(&gd, &gm);
if (gd == HERCMONO)
scr1buf = MK_FP(0xB000, 0);
else
scr1buf = MK_FP(0xB800, 0);
scr2buf=scr1buf+13*80;

return 0;
}



int getkey()
{
int c;

c=getch();
if (!c) c=((0x0100|getch())&0x01ff);
if (c==F11) c=0;
return c;
}
回复
相关推荐
发帖
工具平台和程序库
创建于2007-09-28

2.4w+

社区成员

C/C++ 工具平台和程序库
申请成为版主
帖子事件
创建了帖子
2003-05-14 03:38
社区公告
暂无公告