📄 uart.c
字号:
#include "config.h"
void UART_init()
{
UBRR1L = 15; // 57600bps at 14.7456MHz
UCSR1B = 0x18;
}
void UART_send_byte(unsigned char data)
{
while(!(UCSR1A & 0x20));
UDR1 = data;
}
unsigned char UART_recv_byte()
{
while(!(UCSR1A & 0x80));
return UDR1;
}
void UART_puts(char *pStr)
{
while(*pStr)
{
switch(*pStr)
{
case LF:
case CR:
UART_send_byte(LF); UART_send_byte(CR);
pStr++;
break;
default:
UART_send_byte(*pStr++);
}
};
}
void UART_put_hex(unsigned char hexval)
{
unsigned char temp1, temp2;
temp1 = hexval;
temp1 >>= 4;
if ( temp1 >= 0 && temp1 <= 9 )
UART_send_byte(temp1 + '0');
else
{
temp2 = temp1 - 10 + 'A';
UART_send_byte(temp2);
}
temp1 = hexval & 0x0F;
if ( temp1 >= 0 && temp1 <= 9 )
UART_send_byte(temp1 + '0');
else
{
temp2 = temp1 - 10 + 'A';
UART_send_byte(temp2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -