The serial port is done a long time ago, the deepest image is the call of the sub-function leads to a good program strike. Depressed for an afternoon. Later, I had to tear down all the sub-functions and pile them directly inside the main function, then immediately, and then a few minutes. Many people encounter this problem, later Cao teacher, spent a noon finally find out the problem.
The problem is that in the makefile file, when the target file is generated, the assembly code is put. o The file was placed in part C of the. o file before the result caused an error in the link. There are two solutions:
1, the simplest of course is to put two file location swapped LED.BIN:SERIAL.O SERIALS.O
2, the first method obviously does not cure the solution, the more professional approach is to write a connector script, the connector script code is as follows:
SECTIONS
{
. = 0x20000000;
. Text: {
SERIALS.O//the. o file of the assembly code is linked first
* (. Text)
}
. BSS: {
* (. BSS)
}
. Data: {
* (. Data)
}
}
/************************************************************************************************************** ***********************/
/* Set LED light */
#define GPJ2CON (* (volatile unsigned int*) 0xe0200280)
#define GPJ2PUD (* (volatile unsigned int*) 0xe0200288)
#define GPJ2DAT (* (volatile unsigned int*) 0xe0200284)
/* Configure COM3 Port */
#define GPA1CON (* (volatile unsigned int*) 0xe0200020)
/* Configure ULCON3 and ucon3*/
#define ULCON3 (* (volatile unsigned int*) 0xe2900c00)
#define UCON3 (* (volatile unsigned int*) 0XE2900C04)
/* Used to enable fifo*/
#define UFCON3 (* (volatile unsigned int*) 0XE2900C08)
/* Set baud rate */
#define UBRDIV3 (* (volatile unsigned int*) 0xe2900c28)
#define UDIVSLOT3 (* (volatile unsigned int*) 0xe2900c2c)
Setting the status register
#define UTRSTAT3 (* (volatile unsigned int*) 0XE2900C10)
Set the Send Receive register
#define UTXH3 (* (volatile unsigned int*) 0xe2900c20)
#define URXH3 (* (volatile unsigned int*) 0xe2900c24)
The first is the initialization of the serial port, using the UART0
void init_serial (void)
{
Set GPIO to serial port mode
Gpa1con &= 0x00ff;
Gpa1con |= 0x2200;
Setting data formats and related configurations
ULCON3 = 0x3;
UCON3 = 0x5;
UFCON3 = 0x1;
Set baud rate
UBRDIV3 = 35;
UDIVSLOT3 = 0x1;
}
void Main (void)
{
Setting the LED light to on pull off mode
Gpj2con &=0xFFFF0000;
Gpj2con |=0x1111;
Gpj2pud &=0xFFFFFF00;
Gpj2pud |=0xaa;
GPJ2DAT=0XF;
Init_serial ();
gpj2dat=0x0;
/*
Set GPIO to serial port mode
Gpa1con &= 0x00ff;
Gpa1con |= 0x2200;
Setting data formats and related configurations
ULCON3 = 0x3;
UCON3 = 0x5;
UFCON3 = 0x1;
Set baud rate
UBRDIV3 = 35;
UDIVSLOT3 = 0x1;
*/
Init_serial ();
Delay (void);
char temp;
while (1)
{
Put_c (temp);
while ((UTRSTAT3 & 0x1) ==0);
temp = URXH3;
UTXH3 = temp;
if (temp = = ' 1 ')
{
Gpj2dat = Gpj2dat ^1;
}
if (temp = = ' 2 ')
{
Gpj2dat = Gpj2dat ^2;
}
if (temp = = ' 3 ')
{
Gpj2dat = Gpj2dat ^4;
}
if (temp = = ' 4 ')
{
Gpj2dat = Gpj2dat ^8;
}
}
}
Commissioning of the UART