- /**********************************************
- * File name: UART.c
- * Function: the most basic UART sending and receiving
- * Author: No jianqi
- * Version: 1.0
- ************************************************/
- #include"2440addr.h" //Includes the settings of 2440 related registers
- #include "def.h"
- //The four LEDs correspond to GPB5.6.7.8.
- #define LED1 5
- #define LED2 6
- #define LED3 7
- #define LED4 8
- #define BAUD 115200 //Baud rate
- #define Bit(x) (1<
- #define Output(x) (1<<2*x) //Set the corresponding IO to output
- #define LED_On(x) rGPBDAT=~Bit(x) //Light up the corresponding LED
- /**********************************************
- * Name: Clk_Set
- * Function: Initialization of system clock
- * Entry parameters: None
- * Export parameters: None
- ************************************************/
- void Clk_Set(void)
- {
- int count;
- rUPLLCON=(56<<12)|(2<<4)|2; //UCLK is 48MHZ
- for(count=0;count<10;count++)
- {
- ;
- }
- rMPLLCON=(92<<12)|(1<<4)|1; //FCLK is 400MHZ
- rCLKDIVN=(0<<3)|(2<<1)|1; //HCLK is 100MHZ, PCLK is 50MHZ
- rCAMDIVN=(0<<9); //PCLK=HCLK/4
- }
- /**********************************************
- * Name: IO_init
- * Function: Initialize the LED port
- * Entry parameters: None
- * Export parameters: None
- ************************************************/
- void IO_init(void)
- {
- rGPBCON=Output(LED1)|Output(LED2)|Output(LED3)|Output(LED4); //Set the LED IO port to output
- rGPBDAT=0xffff; //All LEDs are off
- }
- /**********************************************
- * Name: UART0_init
- * Function: UART0 related initialization work
- * Entry parameters: None
- * Export parameters: None
- ************************************************/
- void UART0_init(void)
- {
- rGPHCON=0xa0; //IO port enables UART0 function
- rGPHUP=0xff; //Pull-up disabled
- rULCON0=0x03; // 8-bit data, no parity, 1 stop bit
- rUCON0=0x05; //pclk clock, interrupt request mode is Tx-level, Rx-pulse
- rUBRDIV0=26; //Set the baud rate
- rUFCON0=0x00; //Do not use FIFO
- rUMCON0=0x00; //Do not use flow control
- }
- /**********************************************
- * Name: Send_Byte
- * Function: Send a character
- * Input parameters: characters waiting to be sent
- * Export parameters: None
- ************************************************/
- void Send_Byte(char data)
- {
- while(!(rUTRSTAT0&0x2)); //Wait for the send buffer to be empty
- rUTXH0=data;
- }
- /**********************************************
- * Name: Send_String
- * Function: Send string
- * Input parameter: string to be sent
- * Export parameters: None
- ************************************************/
- void Send_String(char* pt)
- {
- while(*pt)
- {
- Send_Byte(*pt++);
- }
- }
- /**********************************************
- * Name: Uart_Getch
- * Function: Receive a character
- * Entry parameters: None
- * Export parameter: received characters
- ************************************************/
- char Uart_Getch(void)
- {
- while(!(rUTRSTAT0&0x1)); //Wait for the receive buffer to have data
- return (rURXH0); //Read data
- }
- /**********************************************
- * Name: Main
- * Function: Test UART sending and receiving functions
- * Entry parameters: None
- * Export parameters: None
- ************************************************/
- void Main(void)
- {
- char temp;
- IO_init();
- UART0_init();
- Clk_Set();
- Send_String("HelloWorld"); //Send string
- while(1)
- {
- temp=Uart_Getch(); //Receive characters
- if(temp==0x01)
- {
- LED_On(LED1);
- }
- }
- }
Previous article:Improving UART functionality using interrupts
Next article:Test the timer of S3C2440
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
Guess you like
- Reward: Looking for a solution to migrate hard disk recorders and surveillance cameras to the cloud platform. Is it feasible?
- 03 LED operation and general timing function
- 200 Examples of Commonly Used DC Stabilized Power Supply Circuits
- What is the best layout process for switching power supplies?
- Technology geeks, look here! Basics of Hall Effect Magnetic Sensors
- Is there anyone who has done a high frequency injection control algorithm for PMSM?
- Questions about the TIMER0 and TIMER1 clocks of the GD32F303 chip
- RIGOL launches instrument exchange activity to exchange old instruments for new ones
- How to Desolder a Stamp Hole Bluetooth Module
- SparkRoad Serial Communication