GNU ARM汇编--(七)s3c2440的串口控制
UART的测试代码用C写的: 本文引用地址: //m.amcfsurvey.com/article/201611/321724.htm
uart_test.c:
[cpp]view plaincopy
- #include"uart_test.h"
- charuart_GetByte(void)
- {
- while(!(rUTRSTAT0&0x1));//WaituntilTHRisempty.
- returnRdURXH0();
- }
- voiduart_GetString(char*pt)
- {
- while(*pt)
- uart_GetByte();
- }
- voiduart_SendByte(intdata)
- {
- if(data==)
- {
- while(!(rUTRSTAT0&0x2));
- WrUTXH0();
- }
- while(!(rUTRSTAT0&0x2));//WaituntilTHRisempty.
- WrUTXH0(data);
- }
- //====================================================================
- voiduart_SendString(char*pt)
- {
- while(*pt)
- uart_SendByte(*pt++);
- }
- voiduart_test(void)
- {
- charstr[20]="helloworld";
- inta=97;
- //while(1)
- //uart_SendByte(a);
- uart_SendString(str);
- chars=uart_GetByte();
- //if(s==a)
- if(s==97)
- rGPBDAT=0x1c0;
- //uart_SendByte(a);
- //uart_SendByte(97);
- //uart_SendByte(a);
- uart_SendByte((int)s);
- uart_SendByte((int)s);
- }
[cpp]view plaincopy
- //#defineWrUTXH0(ch)(*(volatileunsignedchar*)0x50000023)=(unsignedchar)(ch)
- #defineWrUTXH0(ch)(*(volatileunsignedchar*)0x50000020)=(unsignedchar)(ch)
- #defineRdURXH0()(*(volatileunsignedchar*)0x50000024)
- #definerUTRSTAT0(*(volatileunsigned*)0x50000010)//UART0Tx/Rxstatus
- #definerGPBDAT(*(volatileunsigned*)0x56000014)
到此,使用串口的轮循模式,可以实现串口的正常收发功能了~~
中断模式还没写,这个等到后面全面研究uboot的时候再回头看,uboot用哪种模式,应该就说明那种方式好,到时侯再实现吧
评论