Chinaunix首页 | 论坛 | 博客
  • 博客访问: 657117
  • 博文数量: 516
  • 博客积分: 4119
  • 博客等级: 上校
  • 技术积分: 4288
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-30 17:29
文章分类

全部博文(516)

文章存档

2014年(4)

2013年(160)

2012年(352)

分类:

2012-11-01 11:04:37

原文地址:串口打印字符串 作者:graylocus


点击(此处)折叠或打开

  1. #include "s3c24xx.h"
  2. #include "serial.h"

  3. #define TXD0READY (1<<2)
  4. #define RXD0READY (1)

  5. #define PCLK         50000000 //init.c中将PCLK设为50MHZ
  6. #define UART_CLK     PCLK
  7. #define UART_BAUD_RATE     115200
  8. #define UART_BRD    ((UART_CLK/(UART_BAUD_RATE*16))-1)


  9. void uart0_init(void)
  10. {
  11.     GPHCON |= 0xa0;
  12.     GPHUP = 0x0c;
  13.     
  14.     ULCON0 = 0x03; //8N1
  15.     UCON0 = 0x05; //查询方式,UART时钟源为PCLK
  16.     UFCON0 = 0x00; //不使用FIFO
  17.     UMCON0 = 0x00; //不使用流控
  18.     UBRDIV0 =UART_BRD;//波特率为115200

  19. }

  20. void putch(unsigned char c)
  21. {
  22.     /*wait,直到发送缓冲区中的数据已经全部发送出去*/
  23.     while(!(UTRSTAT0 & TXD0READY));

  24.     /*想UTXH0寄存器写入数据,UART会自动将它发送出去*/
  25.     UTXH0 = c;    
  26. }

  27. unsigned char getch(void)
  28. {
  29.     /*等待,直到接收缓冲区中有数据*/
  30.     while(!(UTRSTAT0 & RXD0READY));
  31.     
  32.     /*直接读取URXH0寄存器,即可获取接收到的数据*/
  33.     return URXH0;    
  34. }


  35. void uart_printf(char str[])
  36. {
  37.     char *p=str;
  38.     while(*p!='\0')
  39.     {
  40.      putch(*p);
  41.      p++;
  42.     }
  43.     putch('\r'); //回到行首
  44. }

阅读(331) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~