📄 uart.c
字号:
#include <stdarg.h>
#include <stdio.h>
#include "bios.h"
#include "uart.h"
void uart_init(void)
{
// *pDMA7_PERIPHERAL_MAP=0x7000; //setting up the UART TX DMA regsiter
*pUART_GCTL=0x1; //enabling the UART Clocks
*pUART_LCR=0x0000; //Reset LCR regsiter
*pUART_IER=0x0000; //enabling the receive and transmit buffer full interrupt
//*pDMA7_CONFIG=0x0000; //enabling autobuffer mode
//*pDMA7_START_ADDR=buffer; //setting the pointer to the file as the starting address of the DMA
//
////there are 24 characters in the buffer[] as defined above
//*pDMA7_X_COUNT=sizeof(buffer); //setting the count
//
//*pDMA7_X_MODIFY=0x1; //modifying register
*pUART_LCR=0x0083; //enabling 8 bits,1stop bit,no parity
//see note at top for different baud rate settings
*pUART_DLL=0x48; //setting the baud rate
*pUART_LCR=0x0003; //enabling 8 bits,1stop bit,no parity
//*pDMA7_CONFIG=0x0001; //starting the DMA transfer
}
UNS8 get_char(void)
{
while( (*pUART_LSR&0x0001) == 0 ){}
return *pUART_RBR;
}
UNS8 get_char_no(void)
{
return *pUART_RBR;
}
void put_char(UNS8 ch)
{
while( (*pUART_LSR&0x0020) == 0 ){}
*pUART_THR = ch;
}
UNS8 get_ch(void)
{
UNS8 temp;
temp = get_char();
put_char(temp);
return temp;
}
void put_str(UNS8 *pStr,UNS8 size)
{
if( size != 0 )
{
for( ;size >0;size --)
{
put_char(*pStr);
pStr++;
}
}
else
{
while(*pStr)
{
put_char(*pStr);
pStr++;
}
}
}
UNS16 get_str(S8 *buf,UNS16 size)
{
S8 temp;
UNS16 i;
for(i=0;;i++)
{
temp = get_ch();
if((temp == '\r' )||(i >= size))
break;
*buf = temp;
buf++;
}
*buf='\r';
buf++;
*buf ='\0';
return i;
}
void my_printf(char *fmt, ...)
{
va_list ap;
char string[256];
va_start(ap, fmt);
vsprintf(string, fmt, ap);
put_str((UNS8 *)string,0);
va_end(ap);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -