注册 登录
  • 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

C语言串口测试程序代码

OC/C/C++ 水墨上仙 2107次浏览 已收录 手机上查看

C语言串口测试程序代码

转自:http://blog.csdn.net/mao0514/

#include<stdio.h>
unsigned int UART0_ADDR = 0x20080000;
unsigned int retu=0;
int i=0;
void delay_x(unsigned short cycles)
{     
    unsigned short t;
    t = cycles;
    while ( --t != 0 );
}
int  main()
{
///////////初始化部分////////////////////////////////////////////////////
    retu = *(unsigned int *)(UART0_ADDR  + 0X30);//uart_cr
    *(unsigned int *)(UART0_ADDR  + 0X30) = 0x300;
  //  retu = *(unsigned int *)(UART0_ADDR  + 0X24);//ibrd
  //  retu = *(unsigned int *)(UART0_ADDR  + 0X28);//fbrd
   *(unsigned int *)(UART0_ADDR  + 0X24) = 1;
   *(unsigned int *)(UART0_ADDR  + 0X28) = 40;
   *(unsigned int *)(UART0_ADDR  + 0X30) = 0x300;
   
   *(unsigned int *)(UART0_ADDR  + 0X2c) = 0x60;//UART_LCR_H
   *(unsigned int *)(UART0_ADDR  + 0X34) = 0x12; //UART_IFLS
   *(unsigned int *)(UART0_ADDR  + 0X38) = 0x0;//UART_IMSC
   
   
    retu = *(unsigned int *)(UART0_ADDR  + 0X30);//uart_cr
    
    *(unsigned int *)(UART0_ADDR  + 0X30) = retu | 0x01;//使能串口
//////////////////////////////////////////////////////////    
    while(1)
    {
   // retu = *(unsigned int *)(UART0_ADDR  + 0X18);
  //  retu = retu
    if(((*(unsigned int *)(UART0_ADDR  + 0X18))&0x40)==0x40)
    {
        retu = *(unsigned int *)(UART0_ADDR  + 0X00);
        retu = retu
        *(unsigned int *)(UART0_ADDR  + 0X00) = retu;
    }
    retu = 0;
    delay_x(0X7000);
    }
    return 0;
}


喜欢 (0)
[开心洋葱]
分享 (0)
关于作者:
水墨上仙
……
加载中……