📄 uart.c
字号:
#include "config.h"
uint8 i2c_rec_buf;
uint8 i2c_rec_new;
void __irq IRQ_UART0(void)
{
uint8 i;
if((U0IIR & 0x0F) == 0x04)
{
i2c_rec_new = 1;
i2c_rec_buf = U0RBR;
}
i = U0IIR ;
VICVectAddr = 0x00;
}
int8 UART0_Init(uint32 baud,UARTMODE set)
{
uint32 bak;
if((baud == 0) || (baud >115200)) return 0;
if((set.datab < 5) || (set.datab > 8)) return 0;
if((set.stopb == 0) || (set.stopb >2)) return 0;
if(set.parity >4) return 0;
U0LCR = 0x80;
bak = (Fpclk >> 4) / baud ;
U0DLM = bak >> 8;
U0DLL = bak & 0xFF;
bak = set.datab - 5;
if(set.stopb == 2) bak |= 0x04;
if(set.parity != 0)
{
set.parity = set.parity - 1;
bak |= 0x08;
}
bak |= set.parity << 4 ;
U0LCR =bak;
PINSEL0 = (PINSEL0 & 0xFFFFFFF0) | 0x00000005;
U0FCR = 0x01;
U0IER =0x01;
VICIntSelect = 0x00000000;
VICVectCntl6 = 0x20 | 0x06 ;
VICVectAddr6 = (uint32) IRQ_UART0;
VICIntEnable = 1<<0x06;
return (1);
}
void UART0_SendByte(uint8 dat)
{
U0THR = dat ;
while((U0LSR & 0x40) == 0) ;
}
void UART0_SendBuf(void)
{
/* uint8 i;
UART0_SendByte(rec_buf) ;
while((U0LSR & 0x20) == 0) ;*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -