当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 4 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : gcc 编译出错。。。郁闷。阿
帖子发表于 : 2009-06-10 16:52 

注册: 2009-01-18 21:38
帖子: 4
送出感谢: 0 次
接收感谢: 0 次
用到的文件 : 2440addr.h main.c uart.c

代码 : gcc main.c uart.c -o IIC

出错:
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crt1.o: In function `_start':
/build/buildd/glibc-2.9/csu/../sysdeps/i386/elf/start.S:115: undefined reference to `main'

小生第一次用GCC编译(第一次编译的是“Helloworld")
欢迎各位大虾拍砖。。。。


页首
 用户资料  
 
2 楼 
 文章标题 : Re: gcc 编译出错。。。郁闷。阿
帖子发表于 : 2009-06-10 17:43 

注册: 2009-02-24 19:39
帖子: 159
送出感谢: 0 次
接收感谢: 0 次
编译没问题,典型的链接错误。
贴代码。


页首
 用户资料  
 
3 楼 
 文章标题 : Re: gcc 编译出错。。。郁闷。阿
帖子发表于 : 2009-06-11 10:24 

注册: 2009-01-18 21:38
帖子: 4
送出感谢: 0 次
接收感谢: 0 次
#include "2440addr.h"
extern void Uart_Printf(char *fmt,...);
void Wr24C02(U32 slvAddr,U32 addr,U8 data);
void Rd24C02(U32 slvAddr,U32 addr,U8 *data);
void Run_IicPoll(void);
void IicPoll(void) ;
void Delay(int x) ;
static U8 iicData[IICBUFSIZE];
static volatile int iicDataCount;
static volatile int iicStatus;
static volatile int iicMode;
static int iicPt;




void iicMain(void)
{
unsigned int i,j;
static U8 data[256];
Uart_Printf("IIC Test(Polling) using AT24C02\n");

//设置GPE15->IICSDA 和 GPE14->IICSCL
rGPEUP |= 0xc000; //Pull-up disable
rGPECON &= ~0xf0000000;
rGPECON |= 0xa0000000; //GPE15:IICSDA , GPE14:IICSCL

//Enable ACK, Prescaler IICCLK=PCLK/16, Enable interrupt, Transmit clock value Tx clock=IICCLK/16
rIICCON = (1<<7) | (0<<6) | (1<<5) | (0xf); //0xaf
rIICADD = 0x10; //2440 slave address = [7:1]
rIICSTAT = 0x10; //IIC bus data output enable(Rx/Tx)
Uart_Printf("Write test data into AT24C02\n");


//写入一个page的数据,page的大小是256byte,
//page 的起始地址是0xa0,写入的数据是:0、1、2、...255。0xa0是AT24C02的页地址。
//AT24C02的页地址是0x00/0x20/0x40/0x60/0x80/0xa0/0xc0/0xe0。
for(i=0;i<256;i++)
Wr24C02(0xa0,(U8)i,i);//U32 slvAddr,U32 addr,U8 data


//初始化data数组的值为0。
for(i=0;i<256;i++)
data[i] = 0;
Uart_Printf("Read test data from AT24C02\n");

//读24C02的0xa0地址中数据到data数组中。
for(i=0;i<256;i++)
Rd24C02(0xa1,(U8)i,&(data[i]));
//输出data数组接收数据的值
for(i=0;i<16;i++)
{
for(j=0;j<16;j++)
Uart_Printf("%2x ",data[i*16+j]);
Uart_Printf("\n");
}
Uart_Printf("OK! Write data is same to Read data!\n");
while(1);
}

/*******************************Wr24C02*****************************************/
void Wr24C02(U32 slvAddr,U32 addr,U8 data)
{
iicMode = WRDATA;
iicPt = 0;
iicData[0] = (U8)addr;
iicData[1] = data;
iicDataCount = 2;

//8-bit data shift register for IIC-bus Tx/Rx operation.
rIICDS = slvAddr; //0xa0

//Master Tx mode, Start(Write), IIC-bus data output enable
//Bus arbitration sucessful, Address as slave status flag Cleared,
//Address zero status flag cleared, Last received bit is 0
rIICSTAT = 0xf0;

//Clearing the pending bit isn't needed because the pending bit has been cleared.
while(iicDataCount!=-1)
Run_IicPoll();

iicMode = POLLACK;
while(1)
{
rIICDS = slvAddr;
iicStatus = 0x100; //To check if _iicStatus is changed
rIICSTAT = 0xf0; //Master Tx, Start, Output Enable, Sucessful, Cleared, Cleared, 0
rIICCON = 0xe0;//0xaf; //Resumes IIC operation. //hzh
while(iicStatus==0x100)
Run_IicPoll();

if(!(iicStatus & 0x1))
break; //When ACK is received
}
rIICSTAT = 0xd0; //Master Tx condition, Stop(Write), Output Enable
rIICCON = 0xe0;//0xaf; //Resumes IIC operation. //hzh
Delay(1); //Wait until stop condtion is in effect.
//Write is completed.
}

/*******************************Rd24C02*****************************************/
void Rd24C02(U32 slvAddr,U32 addr,U8 *data)
{
iicMode = SETRDADDR;
iicPt = 0;
iicData[0] = (U8)addr;
iicDataCount = 1;

rIICDS = slvAddr;
rIICSTAT = 0xf0; //MasTx,Start

//Clearing the pending bit isn't needed because the pending bit has been cleared.
while(iicDataCount!=-1)
Run_IicPoll();

iicMode = RDDATA;
iicPt = 0;
iicDataCount = 1;

rIICDS = slvAddr;
rIICSTAT = 0xb0; //Master Rx,Start
rIICCON = 0xe0;//0xaf; //Resumes IIC operation.
while(iicDataCount!=-1)
Run_IicPoll();

*data = iicData[1];
}


void Run_IicPoll(void)
{
if(rIICCON & 0x10) //Tx/Rx Interrupt Enable
IicPoll();
}


void IicPoll(void)
{
U32 iicSt,i;
iicSt = rIICSTAT;
if(iicSt & 0x8){}; //When bus arbitration is failed. 总线仲裁失败
if(iicSt & 0x4){}; //When a slave address is matched with IICADD
if(iicSt & 0x2){}; //When a slave address is 0000000b
if(iicSt & 0x1){} ; //When ACK isn't received

switch(iicMode)
{
case POLLACK:
iicStatus = iicSt;
break;

case RDDATA:
if((iicDataCount--)==0)
{
iicData[iicPt++] = rIICDS;

rIICSTAT = 0x90; //Stop MasRx condition
rIICCON = 0xe0;//0xaf; //Resumes IIC operation.
Delay(1); //Wait until stop condtion is in effect.
//Too long time...
//The pending bit will not be set after issuing stop condition.
break;
}
iicData[iicPt++] = rIICDS;
//The last data has to be read with no ack.
if((iicDataCount)==0)
rIICCON = 0x60;//0x2f; //Resumes IIC operation with NOACK.
else
rIICCON = 0xe0;//0xaf; //Resumes IIC operation with ACK
break;

case WRDATA:
if((iicDataCount--)==0)
{
rIICSTAT = 0xd0; //stop MasTx condition
rIICCON = 0xe0;//0xaf; //resumes IIC operation.
Delay(1); //wait until stop condtion is in effect.
//The pending bit will not be set after issuing stop condition.
break;
}
rIICDS = iicData[iicPt++]; //_iicData[0] has dummy.
for(i=0;i<10;i++); //for setup time until rising edge of IICSCL
rIICCON = 0xe0;//0xaf; //resumes IIC operation.
break;

case SETRDADDR:
if((iicDataCount--)==0)
{
break; //IIC operation is stopped because of IICCON[4]
}
rIICDS = iicData[iicPt++];
for(i=0;i<10;i++); //for setup time until rising edge of IICSCL
rIICCON = 0xe0;//0xaf; //resumes IIC operation.
break;
default:
break;
}
}

void Delay(int x)
{
int k,j;
while(x)
{
for(k=0;k<=0xff;k++)
for(j=0;j<=0xff;j++);
x--;
}
}



#include <stdarg.h>
#include "2440addr.h"

void Uart_Init(int baud)
{
int i;
rUFCON0 = 0x0; //UART channel 0 FIFO control register, FIFO disable


//UART0
rULCON0 = 0x3; //Line control register : Normal,No parity,1 stop,8 bits
// [10] [9] [8] [7] [6] [5] [4] [3:2] [1:0]
// Clock Sel, Tx Int, Rx Int, Rx Time Out, Rx err, Loop-back, Send break, Transmit Mode, Receive Mode
// 0 1 0 , 0 1 0 0 , 01 01
// PCLK Level Pulse Disable Generate Normal Normal Interrupt or Polling
rUCON0 = 0x805; // Control register
rUBRDIV0=( (int)(50000000/16./baud+0.5) -1 ); //Baud rate divisior register 0
//UART1

for(i=0;i<100;i++);
}



//=====================================================================
void Uart_SendByte(int data)
{

if(data=='\n')
{
while(!(rUTRSTAT0 & 0x2));
// Delay(1); //because the slow response of hyper_terminal
WrUTXH0('\r');
}
while(!(rUTRSTAT0 & 0x2)); //Wait until THR is empty.
// Delay(1);
WrUTXH0(data);


}

//====================================================================
void Uart_SendString(char *pt)
{
while(*pt)
Uart_SendByte(*pt++);
}

//=====================================================================
//If you don't use vsprintf(), the code size is reduced very much.
void Uart_Printf(char *fmt,...)
{
va_list ap;
char str[255];

va_start(ap,fmt);
vsprintf(str,fmt,ap);
Uart_SendString(str);
va_end(ap);


页首
 用户资料  
 
4 楼 
 文章标题 : Re: gcc 编译出错。。。郁闷。阿
帖子发表于 : 2009-06-11 10:45 

注册: 2009-01-05 11:42
帖子: 57
送出感谢: 0 次
接收感谢: 0 次
没有main函数啊。

int main(void)
{
iicMain();
return 0;
}

加上试一下。


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 4 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 2 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译