//#include "2440lib.h"
#include "def.h"
#include "option.h"
#include "2440addr.h"
//#include "2440lib.h"
#include "2440slib.h"
void Delay(int i)
{
while(i!=0)
i--;
}
void myUart_Init(int baud)
{
rGPHCON = rGPHCON & (~(0xffff)) ;
rGPHCON = rGPHCON | (0xaaa0) ;
rGPHUP = 0x0; // The pull up function is enable
rUFCON0=0x00; //不使用FIFO
rUMCON0=0x00; //不使用自动流控制
rULCON0=0x03; //不采用红外线传输模式,无奇偶校验位,1个停止位,8个数据位
rUCON0=0x245; //发送中断为电平方式,接收中断为边沿方式,禁止超时中断,允许产生错误状态中断,禁止回送模式,禁止中止 //信号,传输模式为中断请求模式,接收模式也为中断请求模式。
rUBRDIV0=( (int)(PCLK/16./baud+0.5) -1 );
Delay(10);
}
void Uart_SendByte(char ch)
{
if(ch=='\n')
{
while(!(rUTRSTAT0 & 0x2));//等待,直到发送缓冲区为空
//Delay(10); //超级中断的响应速度较慢
WrUTXH0('\r');//发送回车符
}
while(!(rUTRSTAT0 & 0x2)); //等待,直到发送缓冲区为空
Delay(100);
WrUTXH0(ch);//发送字符
}
void myUart_Send (char *str)
{
myUart_Init(115200);
while (*str)
Uart_SendByte(*str++);
}
char myUart_ReceiveByte(void)
{
while(!(rUTRSTAT0 & 0x1)); //Receive data ready
return RdURXH0();
}
void myUart_receive(char *string)
{
char *string2 = string;
char c;
myUart_Init(115200);
while((c = myUart_ReceiveByte())!='\r')
{
if(c=='\b')
{
if( (int)string2 < (int)string )
{
// Uart_Printf("\b \b");
string--;
}
}
else
{
*string++ = c;
Uart_SendByte(c);
}
}
*string='\0';
Uart_SendByte('\n');
}
extern unsigned int PCLK;
int Main(void)
{
extern unsigned int PCLK;
char *str;
char *string;
myUart_Send("Please Input a string:\n");
myUart_receive(string);
*str=*string;
Delay(500);
myUart_Send(str);
while(1);
}
编译之后错误提示没定义PCLK是咋回事呀?我已经包含"option.h"了!