The simplest S3c2440UART function test

Publisher:ching80790Latest update time:2016-05-03 Source: eefocusKeywords:S3c2440  UART Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

 

  1. /********************************************** 
  2. * File name: UART.c 
  3. * Function: the most basic UART sending and receiving 
  4. * Author: No jianqi 
  5. * Version: 1.0 
  6. ************************************************/  
  7. #include"2440addr.h" //Includes the settings of 2440 related registers  
  8. #include "def.h"  
  9.       
  10. //The four LEDs correspond to GPB5.6.7.8.  
  11. #define LED1 5    
  12. #define LED2 6  
  13. #define LED3 7  
  14. #define LED4 8  
  15.  
  16. #define BAUD 115200 //Baud rate  
  17. #define Bit(x) (1<
  18. #define Output(x) (1<<2*x) //Set the corresponding IO to output  
  19. #define LED_On(x) rGPBDAT=~Bit(x) //Light up the corresponding LED  
  20.   
  21. /********************************************** 
  22. * Name: Clk_Set 
  23. * Function: Initialization of system clock 
  24. * Entry parameters: None 
  25. * Export parameters: None 
  26. ************************************************/  
  27. void Clk_Set(void)  
  28. {  
  29.     int count;  
  30.     rUPLLCON=(56<<12)|(2<<4)|2; //UCLK is 48MHZ  
  31.     for(count=0;count<10;count++)  
  32.     {  
  33.         ;  
  34.     }  
  35.     rMPLLCON=(92<<12)|(1<<4)|1; //FCLK is 400MHZ  
  36.     rCLKDIVN=(0<<3)|(2<<1)|1; //HCLK is 100MHZ, PCLK is 50MHZ  
  37.     rCAMDIVN=(0<<9); //PCLK=HCLK/4  
  38. }  
  39.   
  40. /********************************************** 
  41. * Name: IO_init 
  42. * Function: Initialize the LED port 
  43. * Entry parameters: None 
  44. * Export parameters: None 
  45. ************************************************/  
  46. void IO_init(void)  
  47. {  
  48.     rGPBCON=Output(LED1)|Output(LED2)|Output(LED3)|Output(LED4); //Set the LED IO port to output  
  49.     rGPBDAT=0xffff; //All LEDs are off        
  50. }  
  51.   
  52. /********************************************** 
  53. * Name: UART0_init 
  54. * Function: UART0 related initialization work 
  55. * Entry parameters: None 
  56. * Export parameters: None 
  57. ************************************************/  
  58. void UART0_init(void)  
  59. {  
  60.     rGPHCON=0xa0; //IO port enables UART0 function  
  61.     rGPHUP=0xff; //Pull-up disabled  
  62.     rULCON0=0x03; // 8-bit data, no parity, 1 stop bit  
  63.     rUCON0=0x05; //pclk clock, interrupt request mode is Tx-level, Rx-pulse  
  64.     rUBRDIV0=26; //Set the baud rate  
  65.     rUFCON0=0x00; //Do not use FIFO  
  66.     rUMCON0=0x00; //Do not use flow control    
  67. }  
  68.   
  69. /********************************************** 
  70. * Name: Send_Byte 
  71. * Function: Send a character 
  72. * Input parameters: characters waiting to be sent 
  73. * Export parameters: None 
  74. ************************************************/  
  75. void Send_Byte(char data)  
  76. {  
  77.     while(!(rUTRSTAT0&0x2)); //Wait for the send buffer to be empty  
  78.     rUTXH0=data;  
  79. }  
  80.   
  81. /********************************************** 
  82. * Name: Send_String 
  83. * Function: Send string 
  84. * Input parameter: string to be sent 
  85. * Export parameters: None 
  86. ************************************************/  
  87. void Send_String(char* pt)  
  88. {  
  89.     while(*pt)  
  90.     {  
  91.         Send_Byte(*pt++);    
  92.     }  
  93. }  
  94.   
  95. /********************************************** 
  96. * Name: Uart_Getch 
  97. * Function: Receive a character 
  98. * Entry parameters: None 
  99. * Export parameter: received characters 
  100. ************************************************/  
  101. char Uart_Getch(void)  
  102. {   
  103.     while(!(rUTRSTAT0&0x1)); //Wait for the receive buffer to have data  
  104.     return (rURXH0); //Read data  
  105. }  
  106.   
  107.   
  108. /********************************************** 
  109. * Name: Main 
  110. * Function: Test UART sending and receiving functions 
  111. * Entry parameters: None 
  112. * Export parameters: None  
  113. ************************************************/   
  114. void Main(void)  
  115. {  
  116.     char temp;  
  117.     IO_init();  
  118.     UART0_init();  
  119.     Clk_Set();  
  120.     Send_String("HelloWorld"); //Send string  
  121.     while(1)  
  122.     {  
  123.         temp=Uart_Getch(); //Receive characters  
  124.         if(temp==0x01)  
  125.         {  
  126.             LED_On(LED1);  
  127.         }  
  128.     }  
  129.       
  130. }  

 

 

Keywords:S3c2440  UART Reference address:The simplest S3c2440UART function test

Previous article:Improving UART functionality using interrupts
Next article:Test the timer of S3C2440

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号