jchuang
一般會員
發表:41 回覆:36 積分:15 註冊:2003-08-08
發送簡訊給我
|
deal all:
我參考了“turbo c 週邊應用系列 串列通訊篇“這一本書照key 了以下的程式,可是compiler 後卻出現了以下的error
linker error : out of memory
實在不知道是那裡出了錯請各位大大幫我看一下,以下是程式碼
#include
#include /** local definitions **/ /** gobal definitions **/
#define RS232_INT 0x14 /*bios function call 的編號*/
/* default settings */ char com_port='2';
unsigned long baud_rate=9600;
unsigned char far *key_status=0x417; /*鍵盤狀態指標*/ /** external functions **/ /** external data **/ /** internal functions **/ /** public data **/ /** private data **/ /** public functions **/ /** private functions **/ /* */
/*Function Name:init_rs232 */
/* */
/*Parameters: */
/* */
/*Description: */
/* */
/*Returns: */
/* */
/* */ init_rs232()
{
union REGS reg;
unsigned int br;
/* 讀取傳輸速率*/
if (baud_rate<=110) br=0;
else if (baud_rate<=150) br=1;
else if (baud_rate<=300) br=2;
else if (baud_rate<=600) br=3;
else if (baud_rate<=1200) br=4;
else if (baud_rate<=2400) br=5;
else if (baud_rate<=4800) br=6;
else if (baud_rate<=9600) br=7;
else br=7; /* 起始設定*/
reg.h.ah=0; /*AH=00H 設定傳輸協定*/
reg.h.al=(br<<5) 0xb;/*odd parity ,1 stop bit ,8 data bits*/
reg.x.dx=com_port-'1';
int86(RS232_INT,®,®);
} /*---------------------------------------*/
/*
*Function Name:change_com_port()
*
*Parameters:
*
*Description:
*
*Returns:
*
*/
change_com_port()
{ char ch,pn;
unsigned int i;
char s[]="1,2,3,4";
int port_tot; port_tot=0; for ( i=0;i<4;i )
{
if ( peek(0x40,i*2) )
{
port_tot ;
pn=i '1';
}
else s[i*2]='x';
}
if (port_tot==1)
{
com_port=pn;
init_rs232();
}
else if (port_tot)
{
cprintf("\r\nWhich com port(%s)? ",s );
do
{
ch=getch();
}
while ((ch<'1')||(ch>'4')||(!strchr(s,ch)));
com_port=ch;
cprintf("COM%c\r\n",ch);
init_rs232();
}
else error("NO useful RS-232 COM port");
}
/*
*Function Name: change_baud_rate
*
*Parameters:
*
*Description:
*
*Returns: non
*
*/ change_baud_rate()
{ char ch;
unsigned int i;
do
{
cprintf("Input baud rate(110~9600) ?");
scanf(" %d ",&baud_rate);
} while ((baud_rate<110)||(baud_rate>9600));
init_rs232();
} /*
*Function Name:clear receive error()
*
*Parameters:
*
*Description:
*
*Returns:
*
*/ clear_recevie_error()
{
return(1);
} /*
*Function Name: receive_ready()
*
*Parameters:
*
*Description:
*
*Returns: 1:ready 2:not ready
*
*/ receive_ready()
{
union REGS reg;
int r;
unsigned char s; r=0;
reg.h.ah=3;
reg.x.dx=com_port-'1';
int86(RS232_INT,®,®);
s=reg.h.ah;
if ((s&0x1e)!=0) /*8250 transition error*/
{
error("8250 error");
}
else if ((s&0x01)!=0) r=1; /*ready (data in)*/
/*when user press the left and right shift button then
interrupt check action*/
if ((*key_status&0x3)==0x3)
{
error("User interrupt program");
}
return(r);
} /*
*Function Name: send_ready()
*
*Parameters:
*
*Description:
*
*Returns: 1:ready 2:not ready
*
*/ send_ready()
{
union REGS reg;
int r;
unsigned char s;
r=0;
reg.x.dx=com_port-'1';
reg.h.ah=3;
int86(RS232_INT,®,®); s=reg.h.ah=3;
if ((s&0x1e)!=0)/*8250 transmition error*/
{
error("8250 error !");
}
else if ((s&0x20) !=0) /*ready (reg.empty)*/
{
r=1;
}
return(r); }
/*
*Function Name:Receive_in()
*
*Parameters:
*
*Description: ch:want recive variable char address
*
*Returns:
*
*/ receive_in(ch)
unsigned char *ch;
{
union REGS reg;
reg.h.ah=2;
reg.x.dx=com_port-'1';
int86(RS232_INT,®,®);
*ch=reg.h.al;
} /*
*Function Name:send_out()
*
*Parameters:
*
*Description: ch : want transive char
*
*Returns: non
*
*/ send_out(ch)
unsigned char ch;
{
union REGS reg;
reg.h.ah=1;
reg.x.dx=com_port-'1';
reg.h.al=ch;
int86(RS232_INT,®,®);
}
/*
*Function Name:error()
*
*Parameters:
*
*Description: show the error message
*
*Returns: non
*
*/ error(errmsg)
char *errmsg;
{
int i;
{
printf("\n ERROR: %s \n",errmsg);
sound(500);
sleep(1);
sound(400);
sleep(1);
nosound();
sleep(1);
}
} 新手上路
------ 新手上路
|
derrenbol1
中階會員
發表:5 回覆:113 積分:93 註冊:2004-12-09
發送簡訊給我
|
To jchuang:
這個程式看起來應該沒有多大問題, 問題應該出在編譯器.
1. 你的main呢?
2. 書上的語法屬於K&R格式, 我不太確定Turbo C是否能編譯這種格式
/* K&R type */
foo(a)
int a; // 參數型別會定義在此
{
.....
}
/* ANSI C */
void foo(int a)
{
.....
} 3. 你的Memory Model是否設錯了呢? 請選擇Options
不知道對不對, 您參考看看. 附帶一點, 這個程式就算編譯出來, 它無法在Windows XP & 2000底下執行, 本站上有許多的文章都會提及.
|
taishyang
站務副站長
發表:377 回覆:5490 積分:4563 註冊:2002-10-08
發送簡訊給我
|
jchuang您好: PO程式碼的方式請參考版規說明,煩請修改謝謝您的配合
>
|
jchuang
一般會員
發表:41 回覆:36 積分:15 註冊:2003-08-08
發送簡訊給我
|
deal derrenbol1 : 1. 你的main呢? 因為這是個方便以後來控制rs232的function,就是以後要傳,還是要收,只要呼叫這個function就可以了,所以沒有main 2. 書上的語法屬於K&R格式, 我不太確定Turbo C是否能編譯這種格式 我試了另一種格式,可是出現一樣的error 3. 你的Memory Model是否設錯了呢? 請選擇Options 是要把memory mode 變大嗎?我有試了,可是還是不行,我的complier下有這六個選項不知道您指的是不是這個(tiny,small,medium,compact,large,huge) 4 附帶一點, 這個程式就算編譯出來, 它無法在Windows XP & 2000底下執行 這個程式,我是想在dos 下執行,謝謝您的提醒。
deal taishyang : 我在port的時,已有縮排,可是 port上來時確又不行,想請問一下,為何會如此呢? 新手上路
------ 新手上路
|
taishyang
站務副站長
發表:377 回覆:5490 積分:4563 註冊:2002-10-08
發送簡訊給我
|
|
jchuang
一般會員
發表:41 回覆:36 積分:15 註冊:2003-08-08
發送簡訊給我
|
deal all:
我現在就是用dos的開機片開機,complier後確變成下面的error
linker error undefined symbol '_main'in module cos. 新手上路
------ 新手上路
|
jchuang
一般會員
發表:41 回覆:36 積分:15 註冊:2003-08-08
發送簡訊給我
|
deal all:
我加了void main(void)
{}
就可以了。 新手上路
------ 新手上路
|