色婷婷AⅤ一区二区三区|亚洲精品第一国产综合亚AV|久久精品官方网视频|日本28视频香蕉

          新聞中心

          UART的操作

          作者: 時間:2016-11-21 來源:網(wǎng)絡(luò) 收藏
          @******************************************************************************

          @ File:head.S
          @ 功能:設(shè)置SDRAM,將程序復(fù)制到SDRAM,然后跳到SDRAM繼續(xù)執(zhí)行
          @******************************************************************************

          .extern main
          .text
          .global _start
          _start:
          Reset:
          ldr sp, =4096 @ 設(shè)置棧指針,以下都是C函數(shù),調(diào)用前需要設(shè)好棧
          bl disable_watch_dog @ 關(guān)閉WATCHDOG,否則CPU會不斷重啟

          本文引用地址:http://cafeforensic.com/article/201611/319119.htm


          bl clock_init @ 設(shè)置MPLL,改變FCLK、HCLK、PCLK


          bl memsetup @ 設(shè)置存儲控制器以使用SDRAM
          bl copy_steppingstone_to_sdram @ 復(fù)制代碼到SDRAM中
          ldr pc, =on_sdram @ 跳到SDRAM中繼續(xù)執(zhí)行
          on_sdram:
          ldr sp, =0x34000000 @ 設(shè)置棧指針,
          ldr lr, =halt_loop @ 設(shè)置返回地址
          ldr pc, =main @ 調(diào)用main函數(shù)
          halt_loop:
          b halt_loop


          #include "s3c24xx.h"

          void disable_watch_dog(void);
          void clock_init(void);
          void memsetup(void);
          void copy_steppingstone_to_sdram(void);


          void disable_watch_dog(void)
          {
          WTCON = 0; // 關(guān)閉WATCHDOG很簡單,往這個寄存器寫0即可
          }

          #define S3C2410_MPLL_200MHZ ((0x5c<<12)|(0x04<<4)|(0x00))
          #define S3C2440_MPLL_200MHZ ((0x5c<<12)|(0x01<<4)|(0x02))

          void clock_init(void)
          {
          // LOCKTIME = 0x00ffffff; // 使用默認(rèn)值即可
          CLKDIVN = 0x03; // FCLK:HCLK:PCLK=1:2:4, HDIVN=1,PDIVN=1


          __asm__(
          "mrc p15, 0, r1, c1, c0, 0n"
          "orr r1, r1, #0xc0000000n"
          "mcr p15, 0, r1, c1, c0, 0n"
          );


          if ((GSTATUS1 == 0x32410000) || (GSTATUS1 == 0x32410002))
          {
          MPLLCON = S3C2410_MPLL_200MHZ;
          }
          else
          {
          MPLLCON = S3C2440_MPLL_200MHZ;
          }
          }


          void memsetup(void)
          {
          volatile unsigned long *p = (volatile unsigned long *)MEM_CTL_BASE;



          p[0] = 0x22011110; //BWSCON
          p[1] = 0x00000700; //BANKCON0
          p[2] = 0x00000700; //BANKCON1
          p[3] = 0x00000700; //BANKCON2
          p[4] = 0x00000700; //BANKCON3
          p[5] = 0x00000700; //BANKCON4
          p[6] = 0x00000700; //BANKCON5
          p[7] = 0x00018005; //BANKCON6
          p[8] = 0x00018005; //BANKCON7


          p[9] = 0x008C04F4;
          p[10] = 0x000000B1; //BANKSIZE
          p[11] = 0x00000030; //MRSRB6
          p[12] = 0x00000030; //MRSRB7
          }

          void copy_steppingstone_to_sdram(void)
          {
          unsigned int *pdwSrc = (unsigned int *)0;
          unsigned int *pdwDest = (unsigned int *)0x30000000;

          while (pdwSrc < (unsigned int *)4096)
          {
          *pdwDest = *pdwSrc;
          pdwDest++;
          pdwSrc++;
          }
          }

          "serial.h"

          void uart0_init(void);
          void putc(unsigned char c);
          unsigned char getc(void);
          int isDigit(unsigned char c);
          int isLetter(unsigned char c);

          #include "serial.h"

          int main()
          {
          unsigned char c;
          uart0_init(); // 波特率115200,8N1(8個數(shù)據(jù)位,無校驗位,1個停止位)

          while(1)
          {
          // 從串口接收數(shù)據(jù)后,判斷其是否數(shù)字或子母,若是則加1后輸出
          c = getc();
          if (isDigit(c) || isLetter(c))
          putc(c+1);
          }

          return 0;
          }

          #include "s3c24xx.h"
          #include "serial.h"

          #define TXD0READY (1<<2)
          #define RXD0READY (1)

          #define PCLK 50000000 // init.c中的clock_init函數(shù)設(shè)置PCLK為50MHz
          #define UART_CLK PCLK // UART0的時鐘源設(shè)為PCLK
          #define UART_BAUD_RATE 115200 // 波特率
          #define UART_BRD ((UART_CLK / (UART_BAUD_RATE * 16)) - 1)


          void uart0_init(void)
          {
          GPHCON |= 0xa0; // GPH2,GPH3用作TXD0,RXD0
          GPHUP = 0x0c; // GPH2,GPH3內(nèi)部上拉

          ULCON0 = 0x03; // 8N1(8個數(shù)據(jù)位,無較驗,1個停止位)
          UCON0 = 0x05; // 查詢方式,UART時鐘源為PCLK
          UFCON0 = 0x00; // 不使用FIFO
          UMCON0 = 0x00; // 不使用流控
          UBRDIV0 = UART_BRD; // 波特率為115200
          }


          void putc(unsigned char c)
          {

          while (!(UTRSTAT0 & TXD0READY));


          UTXH0 = c;
          }


          unsigned char getc(void)
          {

          while (!(UTRSTAT0 & RXD0READY));


          return URXH0;
          }


          int isDigit(unsigned char c)
          {
          if (c >= 0 && c <= 9)
          return 1;
          else
          return 0;
          }


          int isLetter(unsigned char c)
          {
          if (c >= a && c <= z)
          return 1;
          else if (c >= A && c <= Z)
          return 1;
          else
          return 0;
          }



          關(guān)鍵詞: UARTs3c24x

          評論


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

          關(guān)閉