?? 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 + -