uart0driver.c

来自「一个arm7实例」· C语言 代码 · 共 66 行

C
66
字号
#include"config.h"
//#include"UART0Driver.h"

void delayNs(uint32 x)
{
    uint32 y;
    for(;x>0;x--)
        for(y=0;y<5000;y++);
}

void UART0_init(uint32 UART_BPS)
{
    uint32 Fdiv;
    PINSEL0|=0x00000005;
    U0LCR=0x83;
    Fdiv=((Fpclk/16)/UART_BPS);
    U0DLM=Fdiv/256;
    U0DLL=Fdiv%256;
    U0LCR=0x03; 
   // U0IER = 0x00;                               /* 禁止中断 */
    U0FCR = 0x00; 
}


void    UART0_sendbyte(uint8 data)
{
    U0THR=data;
    while((U0LSR&0x20)==0);
   
}

char    UART0_revbyte(void)
{
    uint8 data;
    while((U0LSR&0x01)==0);
    data=U0RBR;
    return(data);
}

void UART0_sendstr(uint8  *str)
{  
  while(*str)
  {

    UART0_sendbyte(*str++);           //发送数据
    delayNs(1);
  }
  
}

void   UART0_revstr(uint8  *str)
{
    uint8 i;
    while(1)
    {
       
         i=UART0_revbyte();
         UART0_sendbyte(i); 
         if(i=='\r')break; 
        *str++=i;
      //  str++;
        
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?