微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > GNU ARM汇编--(七)s3c2440的串口控制

GNU ARM汇编--(七)s3c2440的串口控制

时间:11-26 来源:互联网 点击:

  1. ,=GPBDAT
  2. blclock_setup
  3. bluart_init
  4. bldelay
  5. ldrlr,=loop
  6. @bluart_testdd
  7. ldrpc,_uart_test
  8. _uart_test:.worduart_test
  9. loop:
  10. bloop@死循环
  11. ledloop:
  12. ldrr1,=0x1c0
  13. strr1,[r2]
  14. bldelay
  15. ldrr1,=0x1a0
  16. strr1,[r2]
  17. bldelay
  18. ldrr1,=0x160
  19. strr1,[r2]
  20. bldelay
  21. ldrr1,=0x0e0
  22. strr1,[r2]
  23. bldelay
  24. bledloop
  25. clock_setup:
  26. ldrr0,=LOCKTIME
  27. ldrr1,=0xffffffff
  28. strr1,[r0]
  29. ldrr0,=CLKdivN
  30. ldrr1,=(divN_UPLL<3)|(HdivN<1)|(PdivN<0)
  31. strr1,[r0]
  32. ldrr0,=UPLLCON
  33. ldrr1,=(U_Mdiv<12)|(U_Pdiv<4)|(U_Sdiv<0)@Fin=12MUPLL=48M
  34. strr1,[r0]
  35. nop
  36. nop
  37. nop
  38. nop
  39. nop
  40. nop
  41. nop
  42. ldrr0,=MPLLCON
  43. ldrr1,=(M_Mdiv<12)|(M_Pdiv<4)|(M_Sdiv<0)@Fin=12MFCLK=400M
  44. strr1,[r0]
  45. movpc,lr
  46. uart_init:
  47. ldrr0,=GPHCON
  48. ldrr1,=0x2aaaa@配置GPIO复用规则为串口
  49. strr1,[r0]
  50. ldrr0,=ULCON0
  51. ldrr1,=(IR_MODE<6)|(Parity_Mode<3)|(Num_of_stop_bit<2)|(Word_length<0)@
  52. strr1,[r0]
  53. ldrr0,=UCON0
  54. ldrr1,=(FCLK_Div<12)|(Clk_select<10)|(Tx_Int_Type<9)|(Rx_Int_Type<8)|(Rx_Timeout<7)|(Rx_Error_Stat_Int<6)|(Loopback_Mode<5)|(Break_Sig<4)|(Tx_Mode<2)|(Rx_Mode<0)
  55. strr1,[r0]
  56. ldrr0,=UFCON0
  57. ldrr1,=(Tx_FIFO_Trig_Level<6)|(Rx_FIFO_Trig_Level<4)|(Tx_FIFO_Reset<2)|(Rx_FIFO_Reset<1)|(FIFO_Enable<0)@
  58. strr1,[r0]
  59. ldrr0,=UBRdiv0
  60. ldrr1,=(UBRdiv<0)
  61. strr1,[r0]
  62. movpc,lr
  63. delay:
  64. @ldrr3,=0x4ffffff
  65. ldrr3,=0xfffff
  66. delay1:
  67. subr3,r3,#1
  68. cmpr3,#0x0
  69. bnedelay1
  70. movpc,lr


UART的测试代码用C写的:

uart_test.c:

[cpp]view plaincopy

  1. #include"uart_test.h"
  2. charuart_GetByte(void)
  3. {
  4. while(!(rUTRSTAT0&0x1));//WaituntilTHRisempty.
  5. returnRdURXH0();
  6. }
  7. voiduart_GetString(char*pt)
  8. {
  9. while(*pt)
  10. uart_GetByte();
  11. }
  12. voiduart_SendByte(intdata)
  13. {
  14. if(data==)
  15. {
  16. while(!(rUTRSTAT0&0x2));
  17. WrUTXH0();
  18. }
  19. while(!(rUTRSTAT0&0x2));//WaituntilTHRisempty.
  20. WrUTXH0(data);
  21. }
  22. //====================================================================
  23. voiduart_SendString(char*pt)
  24. {
  25. while(*pt)
  26. uart_SendByte(*pt++);
  27. }
  28. voiduart_test(void)
  29. {
  30. charstr[20]="helloworld";
  31. inta=97;
  32. //while(1)
  33. //uart_SendByte(a);
  34. uart_SendString(str);
  35. chars=uart_GetByte();
  36. //if(s==a)
  37. if(s==97)
  38. rGPBDAT=0x1c0;
  39. //uart_SendByte(a);
  40. //uart_SendByte(97);
  41. //uart_SendByte(a);
  42. uart_SendByte((int)s);
  43. uart_SendByte((int)s);
  44. }

uart_test.h:

[cpp]view plaincopy

  1. //#defineWrUTXH0(ch)(*(volatileunsignedchar*)0x50000023)=(unsignedchar)(ch)
  2. #defineWrUTXH0(ch)(*(volatileunsignedchar*)0x50000020)=(unsignedchar)(ch)
  3. #defineRdURXH0()(*(volatileunsignedchar*)0x50000024)
  4. #definerUTRSTAT0(*(volatileunsigned*)0x50000010)//UART0Tx/Rxstatus
  5. #definerGPBDAT(*(volatileunsigned*)0x56000014)



到此,使用串口的轮循模式,可以实现串口的正常收发功能了~~

中断模式还没写,这个等到后面全面研究uboot的时候再回头看,uboot用哪种模式,应该就说明那种方式好,到时侯再实现吧

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top