• UART初始化函数

    void Uart_Init(int pclk,int baud)
    {int i;rGPHCON|=0xa0; //GPH2,GPH3 as TXD0,RXD0rGPHUP = 0x0;    //GPH2,GPH3内部上拉if(pclk == 0)pclk = PCLK;rUFCON0 = 0x0; //禁止3个通道的FIFO控制寄存器rUFCON1 = 0x0;rUFCON2 = 0x0;rUMCON0 = 0x0;rUMCON1 = 0x0;rUMCON2 = 0x0;    //初始化3个通道的MODEM控制寄存器,禁止AFC//Line control register 0: Normal,No parity,1 stop,8 bits.rULCON0=0x3;// Control register 0rUCON0  = 0x5;//Baud rate divisior register 0rUBRDIV0=( (int)(pclk/16./baud+0.5) -1 );
    }
    
  • 接收1字节数据

    //接收一字节数据
    char Uart_Getch(void)
    {while(!(rUTRSTAT0 & 0x1)); //等待就绪//读错误状态寄存器UERSTATnif ((rUERSTAT0 & 0x1)|| (rUERSTAT0 & 0x4))return -1;return RdURXH0;  //0x50000027
    }
    
  • 接收1个字符串

    //接收一个字符串
    void Uart_GetString(char *string)
    {char *string2 = string;char c;while((c = Uart_Getch())!=‘\r’)   //回车符*string++ = c;
    }
    
  • 接收1个字符串,转换为数字

    int Uart_GetIntNum(void)
    {char str[30];char *string = str;int base     = 10;  //进制int minus    = 0;   //是否负数int result   = 0;    //转换的结果int lastIndex;       //字符串长度int i;Uart_GetString(string);if(string[0]=='-'){minus = 1;string++;}if(string[0]=='0' && (string[1]=='x' || string[1]=='X')){base    = 16;string += 2;}lastIndex = strlen(string) - 1;if(lastIndex<0)return -1;if(string[lastIndex]=='h' || string[lastIndex]=='H' ){base = 16;string[lastIndex] = 0;lastIndex--;}if(base==10){result = atoi(string);result = minus ? (-1*result):result;}else {for(i=0;i<=lastIndex;i++) {if(isalpha(string[i])){if(isupper(string[i]))result = (result<<4) + string[i] - ‘A’ + 10;//之前的结果乘16,再加当前数字elseresult = (result<<4) + string[i] - 'a' + 10;}else{result = (result<<4) + string[i] - '0';}result = minus ? (-1*result):result;}return result;
    }
    
  • 发送一字节

    //发送一字节
    //#define WrUTXH0(ch)  ( * (volatile unsigned char * )0x50000023)=(unsigned char)(ch)void Uart_SendByte(int data)
    {while(!(rUTRSTAT0 & 0x4));Delay(10);  //because the slow response of hyper_terminalWrUTXH0(data);
    }
    
  • 送一个字符串

    //发送一个字符串
    void Uart_SendString(char *pt)
    {while(*pt)Uart_SendByte(*pt++);
    }
    
  • 2410addr.h 定义UART各个寄存器的头文件

    //2410addr.h  定义UART各个寄存器的头文件
    #define rULCON0 ( * (volatile unsigned * )0x50000000)  //UART 0 Line control
    #define rUCON0 ( * (volatile unsigned * )0x50000004)  //UART 0 control
    #define rUFCON0 ( * (volatile unsigned * )0x50000008)  //UART 0 FIFO control
    #define rUMCON0 ( * (volatile unsigned * )0x5000000c)  //UART 0 Modem control
    #define rUTRSTAT0 ( * (volatile unsigned * )0x50000010)  //UART 0 Tx/Rx status
    #define rUERSTAT0 ( * (volatile unsigned * )0x50000014)  //UART 0 Rx error status
    #define rUFSTAT0 ( * (volatile unsigned * )0x50000018)  //UART 0 FIFO status
    #define rUMSTAT0 ( * (volatile unsigned * )0x5000001c)  //UART 0 Modem status
    #define rUBRDIV0 ( * (volatile unsigned * )0x50000028)  //UART 0 Baud rate diviaor
    #define rULCON1 ( * (volatile unsigned * )0x50004000)  //UART 1 Line control
    #define rUCON1 ( * (volatile unsigned * )0x50004004)  //UART 1 Control
    #define rUFCON1 ( * (volatile unsigned * )0x50004008)  //UART 1 FIFO control
    #define rUMCON1 ( * (volatile unsigned * )0x5000400c)  //UART 1 Modem control
    #define rUTRSTAT1  ( * (volatile unsigned * )0x50004010)  //UART 1 Tx/Rx status
    #define rUERSTAT1  ( * (volatile unsigned * )0x50004014)  //UART 1 Rx error status
    #define rUFSTAT1 ( * (volatile unsigned * )0x50004018)  //UART 1 FIFO status
    #define rUMSTAT1  ( * (volatile unsigned * )0x5000401c)  //UART 1 Modem status
    #define rUBRDIV1  ( * (volatile unsigned * )0x50004028)  //UART 1 Baud rate divisor
    #define rULCON2  ( * (volatile unsigned * )0x50008000)  //UART 2 Line control
    #define rUCON2 ( * (volatile unsigned * )0x50008004)  //UART 2 Control
    #define rUFCON2 ( * (volatile unsigned * )0x50008008)  //UART 2 FIFO control
    #define rUMCON2 ( * (volatile unsigned * )0x5000800c)   //UART 2 Modem control
    #define rUTRSTAT2  ( * (volatile unsigned * )0x50008010)  //UART 2 Tx/Rx status
    #define rUERSTAT2  ( * (volatile unsigned * )0x50008014)  //UART 2 Rx error status
    #define rUFSTAT2 ( * (volatile unsigned * )0x50008018)  //UART 2 FIFO status
    #define rUMSTAT2  ( * (volatile unsigned * )0x5000801c)  //UART 2 Modem status
    #define rUBRDIV2  ( * (volatile unsigned * )0x50008028)  //UART 2 Baud rate divisor
    #if def_BIG_ENDIAN
    #define rUTXH0  ( * (volatile unsigned char * )0x50000023)  //UART 0 Transmission Hold
    #define rURXH0  ( * (volatile unsigned char * )0x50000027)  //UART 0 Receive buffer
    #define rUTXH1  ( * (volatile unsigned char * )0x50004023)  //UART 1 Transmission Hold
    #define rURXH1  ( * (volatile unsigned char * )0x50004027)  //UART 1 Receive buffer
    #define rUTXH2  ( * (volatile unsigned char * )0x50008023)  //UART 2 Transmission Hold
    #define rURXH2  ( * (volatile unsigned char * )0x50008027)  //UART 2 Receive buffer
    #define WrUTXH0(ch)  ( * (volatile unsigned char * )0x50000023)=(unsigned char)(ch)
    #define RdURXH0  ( * (volatile unsigned char * )0x50000027)
    #define WrUTXH1(ch)  ( * (volatile unsigned char * )0x50004023)=(unsigned char)(ch)
    #define RdURXH1()  ( * (volatile unsigned char * )0x50004027)
    #define WrUTXH20(ch)  ( * (volatile unsigned char * )0x50008023)=(unsigned char)(ch)
    #define RdURXH2()  ( * (volatile unsigned char * )0x50008027)
    #define UTXH0     (0x50000020+3)  //Byte_access address by DMA
    #define URXH0     (0x50000024+3)
    #define UTXH1     (0x50004020+3)
    #define URXH1     (0x50004024+3)
    #define UTXH2     (0x50008020+3 )
    #define URXH2     (0x50008024+3)
    #else//Little Endian
    #define rUTXH0  ( * (volatile unsigned char * )0x50000020)//UART 0 Transmission Hold
    #define rURXH0  ( * (volatile unsigned char * )0x50000024)//UART 0 Receive buffer
    #define rUTXH1  ( * (volatile unsigned char * )0x50004020)//UART 1 Transmission Hold
    #define rURXH1  ( * (volatile unsigned char * )0x50004024)//UART 1 Receive buffer
    #define rUTXH2  ( * (volatile unsigned char * )0x50000820)//UART 2 Transmission Hold
    #define rURXH2  ( * (volatile unsigned char * )0x50008024)//UART 2 Receive buffer
    #define WrUTXH0(ch)  ( * (volatile unsigned char * )0x50000020)=(unsigned char)(ch)
    #define RdURXH0  ( * (volatile unsigned char * )0x50000024)
    #define WrUTXH1(ch)  ( * (volatile unsigned char * )0x50004020)=(unsigned char)(ch)
    #define RdURXH1()  ( * (volatile unsigned char * )0x50004024)
    #define WrUTXH2(ch)  ( * (volatile unsigned char * )0x50008020)=(unsigned char)(ch)
    #define RdURXH2()  ( * (volatile unsigned char * )0x50008024)
    #define UTXH0     (0x50000020+3)  //Byte_access address by DMA
    #define URXH0     (0x50000024+3)
    #define UTXH1     (0x50004020+3)
    #define URXH1     (0x50004024+3)
    #define UTXH2     (0x50008020+3 )
    #define URXH2     (0x50008024+3)
    #endif
    

S3C2440——使用URAT0查询方式发送和接收字符串相关推荐

  1. S3C2440——使用URAT0中断方式发送和接收字符串

    设置中断向量表 ;文件ASM_Interrupt.s ;(1)设置中断向量表 Mode_USR EQU 0x50 ;IRQ中断开放,FIQ中断关闭 Mode_FIQ EQU 0xD1 ;关闭IRQ.F ...

  2. 51 32单片机使用蓝牙测RSSI值定位(包含字符串发送,接收字符串,数据解析发送,中断超时接收等)

    首先这是一篇血泪文章,当你看到这篇文章的时候,笔者已经失败了,首先笔者选用了51单片机进行编写,51单片机的一个串口难以进行相应的验证,这是其一:其二,使用AT+CWLAP调回WIFI信息的时候,你会 ...

  3. hal 双串口同时接收丢失数据_【STM32Cube_06】使用USART发送和接收数据(查询模式)...

    寻求更简洁舒适的阅读体验,请移步Mculover666的个人博客: [STM32Cube_06]使用USART发送和接收数据(查询模式)​www.mculover666.cn 本篇文章主要介绍如何使用 ...

  4. STM32L152RE实现串口发送及接收数据

    本文主要讲解用keil软件实现USART串口发送及接收数据,默认读者keil环境已经配好,且头文件已正确引入,如出现编译错误以及st-link下载问题,请自行百度解决. 串口发送和接收数据是一件看起来 ...

  5. 【2】中断方式和查询方式的区别

    1.中断方式: 接收数据时,MCU转入中断服务程序,再处理接收到的数据: CMT2300A接收数据的中断: 检测RX_FIFO_TH 中断,一旦有效表示FIFO 已经被填入预设的数据长度,就可以开始读 ...

  6. Java 用HTTP的方式发送JSON报文请求

    前言: 项目调用第三方接口时,通常是用socket或者http的通讯方式发送请求:http 为短连接,客户端发送请求都需要服务器端回送响应,请求结束后,主动释放链接.Socket为长连接:通常情况下S ...

  7. win32 串口阻塞的方式发送接收数据

    参考博文 https://blog.csdn.net/liuzhuomju/article/details/7479507 #pragma once #define RX_CHAR WM_USER+1 ...

  8. python接收http请求_python通过get,post方式发送http请求和接收http响应

    您可能感兴趣的话题: python 核心提示: 本文实例讲述了python通过get,post方式发送http请求和接收http响应的方法.分享给大家供大家参考. 本文实例讲述了python通过get ...

  9. python通过get方式,post方式发送http请求和接收http响应-urllib urllib2

    python通过get方式,post方式发送http请求和接收http响应-- import urllib模块,urllib2模块, httplib模块 http://blog.163.com/xyc ...

最新文章

  1. 计算机房一般在办公楼建设吗,写字楼大厦机房建设技术方案.doc
  2. 资源 | 25个深度学习开源数据集,have fun !
  3. easyui是否容易上手_特色家常菜-清蒸桂鱼,肉质鲜嫩有营养,做法简单容易学...
  4. 在tomcat上部署项目需要打成jar_Spring Boot Web 项目教程,SpringBoot与传统Web 优缺对比...
  5. hnust 神奇的序列
  6. oracle数据设置为ull,IMX6ULL启动和烧写
  7. 某听书网站系统漏洞,利用抓包拼接方式获取网站资源
  8. 我的世界java怎么自制皮肤_我的世界皮肤制作教程
  9. python去除停用词_如何从gensim中的文档中删除停用词?
  10. 小米6刷android 8.0,小米小米6(安卓8.0)手机快速救砖,线刷教程分享,小白轻松救活手机...
  11. Android实现文本折叠效果
  12. 软件测试工程师需要学什么?全网最全,测试工程师技能树,吐血整理
  13. 什么叫断章取义,什么叫曲解——你被骗了多少年?
  14. 【高德地图API】Web地图开发系列(一)
  15. 数据库与开源编译器框架LLVM
  16. 微前端在平台级管理系统中的最佳实践
  17. 计算机系统结构课后习题答案
  18. Vue代码中如何开启调试模式
  19. 边缘计算:电信运营商5G时代战略转型的关键一步
  20. 语言模型评价指标 bpc(bits-per-character)和困惑度ppl(perplexity)

热门文章

  1. [python]如何优雅地自制英汉小词典
  2. 操作系统内核开发:实现定时器功能
  3. VGA SVGA XVG XVGA
  4. 阿里云的云存储服务OSS可以支持哪些企业级存储需求?如何操作和管理?
  5. JavaScript 基于栈和命令模式的撤销恢复操作
  6. 20211025-BCD码和十进制之间的相互转换
  7. 【笔记】思科路由器常用配置命令
  8. 连接板的优化设计-workbench结构优化设计
  9. 特殊符号 UNICODE编码
  10. 用poi把ppt或pptx转为图片