新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > GNU ARM匯編--(七)s3c2440的串口控制

GNU ARM匯編--(七)s3c2440的串口控制

作者: 時間:2016-11-26 來源:網(wǎng)絡(luò) 收藏
  • .global_main
  • _main:
  • ldrr0,=GPBCON
  • ldrr1,=0x15400
  • strr1,[r0]
  • ldrr2,=GPBDAT
  • blclock_setup
  • bluart_init
  • bldelay
  • ldrlr,=loop
  • @bluart_testdd
  • ldrpc,_uart_test
  • _uart_test:.worduart_test
  • loop:
  • bloop@死循環(huán)
  • ledloop:
  • ldrr1,=0x1c0
  • strr1,[r2]
  • bldelay
  • ldrr1,=0x1a0
  • strr1,[r2]
  • bldelay
  • ldrr1,=0x160
  • strr1,[r2]
  • bldelay
  • ldrr1,=0x0e0
  • strr1,[r2]
  • bldelay
  • bledloop
  • clock_setup:
  • ldrr0,=LOCKTIME
  • ldrr1,=0xffffffff
  • strr1,[r0]
  • ldrr0,=CLKDIVN
  • ldrr1,=(DIVN_UPLL<<3)|(HDIVN<<1)|(PDIVN<<0)
  • strr1,[r0]
  • ldrr0,=UPLLCON
  • ldrr1,=(U_MDIV<<12)|(U_PDIV<<4)|(U_SDIV<<0)@Fin=12MUPLL=48M
  • strr1,[r0]
  • nop
  • nop
  • nop
  • nop
  • nop
  • nop
  • nop
  • ldrr0,=MPLLCON
  • ldrr1,=(M_MDIV<<12)|(M_PDIV<<4)|(M_SDIV<<0)@Fin=12MFCLK=400M
  • strr1,[r0]
  • movpc,lr
  • uart_init:
  • ldrr0,=GPHCON
  • ldrr1,=0x2aaaa@配置GPIO復(fù)用規(guī)則為串口
  • strr1,[r0]
  • ldrr0,=ULCON0
  • ldrr1,=(IR_MODE<<6)|(Parity_Mode<<3)|(Num_of_stop_bit<<2)|(Word_length<<0)@
  • strr1,[r0]
  • ldrr0,=UCON0
  • 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)
  • strr1,[r0]
  • ldrr0,=UFCON0
  • ldrr1,=(Tx_FIFO_Trig_Level<<6)|(Rx_FIFO_Trig_Level<<4)|(Tx_FIFO_Reset<<2)|(Rx_FIFO_Reset<<1)|(FIFO_Enable<<0)@
  • strr1,[r0]
  • ldrr0,=UBRDIV0
  • ldrr1,=(UBRDIV<<0)
  • strr1,[r0]
  • movpc,lr
  • delay:
  • @ldrr3,=0x4ffffff
  • ldrr3,=0xfffff
  • delay1:
  • subr3,r3,#1
  • cmpr3,#0x0
  • bnedelay1
  • movpc,lr

  • UART的測試代碼用C寫的:

    本文引用地址:http://butianyuan.cn/article/201611/321724.htm

    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)


    到此,使用串口的輪循模式,可以實現(xiàn)串口的正常收發(fā)功能了~~

    中斷模式還沒寫,這個等到后面全面研究uboot的時候再回頭看,uboot用哪種模式,應(yīng)該就說明那種方式好,到時侯再實現(xiàn)吧


    上一頁 1 2 3 下一頁

    關(guān)鍵詞: ARM匯編s3c2440串口控

    評論


    相關(guān)推薦

    技術(shù)專區(qū)

    關(guān)閉