级别: 新手上路
UID: 5489
精华: 0
发帖: 27
金钱: 280 两
威望: 280 点
综合积分: 54 分
注册时间: 2009-04-25
最后登录: 2009-10-23
楼主  发表于: 2009-05-18 10:13

 pclk

//#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"了!
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2009-05-18 13:35
谁说"option.h"里就一定有PCLK的?
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
2楼  发表于: 2009-05-18 13:38
复制代码
  1. extern unsigned int PCLK;

PCLK是全局变量,就算是要,也不能定义在头文件里。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 5489
精华: 0
发帖: 27
金钱: 280 两
威望: 280 点
综合积分: 54 分
注册时间: 2009-04-25
最后登录: 2009-10-23
3楼  发表于: 2009-05-18 17:23

 回 2楼(kasim) 的帖子

那该怎么用啊?
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
4楼  发表于: 2009-05-18 17:37
去看光盘上提供的2440test的源代码,看人家是怎么实现的。
抄东西也要有技巧,千万别少抄了
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 32456
精华: 0
发帖: 14
金钱: 70 两
威望: 14 点
综合积分: 28 分
注册时间: 2010-11-16
最后登录: 2011-10-13
5楼  发表于: 2010-11-17 18:24
rUBRDIV0=( (int)(pclk/16./baud+0.5) -1 );  是什么意思?

用户手册是这样规定的

UBRDIVn  = (int)( UART clock / ( buad rate x 16) ) –1     (公式)

怎么等效?  高手指点…………  谢谢