Arm System Programming

Source: Internet
Author: User

 

# Define utxho * (volatile int *) 0x7f005020)
# Define utrstat0 * (volatile int *) 0x7f005010)
# Define urxh0 * (volatile int *) 0x7f005024)

# Define gpacon * (volatile int *) 0x7f008000)
# Define ubrdiv0 * (volatile int *) 0x7f005028)
# Define udivsloto * (volatile int *) 0x7f00502c)
# Define ulcon0 * (volatile int *) 0x7f005000)
# Define ucon0 * (volatile int *) 0x7f005004)

Initialization

Void uart_init (void)
{
Gpacon = 0x22; // uart r/T
Ubrdiv0 = 34; // configure baud rate (integer)
Udivsloto = 0x1fff; // Divisor
Ulcon0 = 0x3; // UART Line Control
Ucon0 = 0xc05; // UART Control
}

 

Several basic functions of the stdio Library

Void uart_putchar (char C)
{
While (utrstat0 & (1 <2) = 0 );
Utxho = C;

}

Char uart_getchar (void)
{
While (utrstat0 & (1 <0) = 0 );
Return urxh0;

}

Void uart_putchar (char C)
{
While (utrstat0 & (1 <2) = 0 );
Utxho = C;

}

Char uart_getchar (void)
{
While (utrstat0 & (1 <0) = 0 );
Return urxh0;

}

Char * mygets (char * s)
{
Int I = 0;
While (* (S + I) = uart_getchar ())! = '\ R ')
{


If (* (S + I) = '\ B ')
{
If (I = 0)
Continue;
Uart_putchar ('\ B ');
Uart_putchar ('');
Uart_putchar ('\ B ');
I --;
}
Else
Uart_putchar (* (S + I ));
I ++;
}
Return S;
}

 

Convert a decimal hexadecimal string to an integer

Int hex_atoi (char * s)
{
Int num = 0, I = 0;
If (* s = 'O') & (* (S + 1) = 'X '))
{
S + = 2;
While (* s)
{
If (* S <'9') & (* s> '0 '))
{
Num * = 16;
Num + = * s;
S ++;
}
Else if (* s> 'A') & (* S <'Z '))
{
Num * = 16;
Num + = * s-'A' + 10;
S ++;
}
Else if (* s> 'A') & (* S <'Z '))
{
Num * = 16;
Num + = * s-'A' + 10;
S ++;
}
}
}
Else
{
While (* s ){
Num * = 10;
Num + = * s;
S ++;
}
}

Return num;
}

Char * myputs (char * s)
{
Int I = 0;
While (* (S + I )! = '\ 0 ')
{
If (* (S + I) = '\ B ')
{
I ++;
Continue;
}
Uart_putchar (* (S + I ));
I ++;
}
Return S;
}

 

 

Functions used to parse commands

Char ** analys (char * s)
{
Char * STR [5] = {null };
Int stat = 0, I = 0, j = 0;
While (* (S + I )! = '\ 0 ')
{
If (STAT = 0) & (* (S + I )! = Space ))
{
Stat = 1;
STR [J ++] = S + I ++;
}
Else {If (STAT = 1) & (* (S + I) = space ))
{
Stat = 0;
* (S + I ++) = '\ 0 ';
}
Else I ++;
}
}
Return STR;
}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.