📄 uart.c
字号:
#include "2410addr.h"
#include "2410lib.h"
int i=0;
/*****************************************
轮询 - not fifo
*****************************************/
/*void uart_init()
{
rULCON1 =3; //设置每桢长度
rUCON1 =0x25;
DisableIrq(BIT_UART1); //设置非中断模式,接收
rUBRDIV1 =0x19; //设置波特率
}
void in_out()
{
while(1)
{
while(rUTRSTAT1 & 1 == 0); //有错误---没有设置成回环模式
printf("%d\n",rURXH1);
Delay(1000);
}
}*/
/*****************************************
中断 - not fifo
*****************************************/
/*
void uart_init()
{
rULCON1 =0x3; //设置每桢长度
rUCON1 =0x25; //设置回环,中断模式
rUBRDIV1 =0x19; //设置波特率
EnableIrq(BIT_UART1); //打开中断
EnableSubIrq(BIT_SUB_ERR1 | BIT_SUB_TXD1 | BIT_SUB_RXD1);
rUTXH1 =0;
}
void __irq in_out()
{
while(rUTRSTAT1 & 2 == 0)
;
rUTXH1 =i++;
Delay(20);
if(rSUBSRCPND & BIT_SUB_TXD1)
{
printf("%d\n",rURXH1);
Delay(1000);
}
ClearPending(BIT_UART1);
ClearSubPending(BIT_SUB_ERR1 | BIT_SUB_TXD1 | BIT_SUB_RXD1);
DisableIrq(BIT_UART1);
DisableSubIrq(BIT_SUB_ERR1 | BIT_SUB_TXD1 | BIT_SUB_RXD1);
}
*/
/*******************************************
中断,fifo
*******************************************/
void uart_init()
{
rULCON1 =0x3; //设置每桢长度
rUCON1 =0x25; //设置回环,中断模式
rUBRDIV1 =0x19; //设置波特率
EnableIrq(BIT_UART1); //打开中断
EnableSubIrq(BIT_SUB_ERR1 | BIT_SUB_TXD1 | BIT_SUB_RXD1);
rUFCON1 =0x1;
}
void __irq in_out()
{
static int i =1;
while( rUFSTAT1 & 0xF )
;
if(rUFSTAT1 & (1<<9) == 0)
{
rUTXH1 =i++;
}
ClearSubPending(BIT_SUB_TXD1);
Delay(100);
if(rUFSTAT1 & 0xf)
{
printf("%d\n",rURXH1);
Delay(500);
}
ClearPending(BIT_UART1);
ClearSubPending(BIT_SUB_ERR1 | BIT_SUB_RXD1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -