ARM7串口编程要点
时间:11-24
来源:互联网
点击:
[c-sharp] view plaincopyprint?
- #include "config.h"
- void DelayNS(uint32 dly)
- {
- uint32 i;
- for(; dly>0; dly--)
- {
- for(i=0; i<5000; i++);
- }
- }
- void UART0_Init(uint32 bps)
- {
- uint16 Fdiv;
- PINSEL0 = 0x00000005; //设置串口引脚
- U0LCR = 0x83; //置为除数锁存位,进行配置
- Fdiv = (Fpclk >> 4) / bps; // 设置波特率
- U0DLM = Fdiv >> 8;
- U0DLL = Fdiv & 0xff;
- U0LCR = 0x03; //清除除数锁存位,并设置工作模式
- }
- uint8 UART0_RcvByte(void)
- {
- uint8 rcv_data ;
- while((U0LSR&0X01)==0); //等待数据到达
- rcv_data = U0RBR; //从U0RBR中读出接收到的数据
- return rcv_data; //返回接收到的数据
- }
- void UART0_SendByte(uint8 data)
- {
- U0THR = data;
- while(0 == (U0LSR & 0x40));
- }
- void UART0_RecBuf (uint8 *buffer)
- {
- uint8 *pbuffer;
- uint8 i;
- for(pbuffer = buffer, i = 0;i < 8; i++)
- {
- *(pbuffer++) = UART0_RcvByte();
- }
- }
- void UART0_SendBuf(uint8 *buffer)
- {
- uint8 *pbuffer;
- uint8 i;
- for(pbuffer = buffer,i=0;i < 8; i++)
- UART0_SendByte(*(pbuffer++));
- }
- int main (void)
- {
- uint8 recver_buffer[8]; //定义接收帧缓冲区
- uint8 send_buffer[8] ={0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27}; //定义发送帧缓冲区
- UART0_Init(115200);
- while(1)
- {
- UART0_RecBuf(recver_buffer);
- DelayNS(10);
- if(0x10 ==recver_buffer[0] && 0x11 == recver_buffer[1])
- UART0_SendBuf(recver_buffer);
- else
- UART0_SendBuf(send_buffer);
- }
- return 0;
- }
ARM7串口编 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)