?? uart1.c
字號:
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: main.c
** Last modified Date: 2004-09-16
** Last Version: 1.0
** Descriptions: The main() function example template
**
**------------------------------------------------------------------------------------------------------
** Created by: Chenmingji
** Created date: 2004-09-16
** Version: 1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by: Chenxibing
** Modified date: 2005-01-17
** Version:
** Descriptions: UART0通訊實驗,中斷方式,使用FIFO。
**
********************************************************************************************************/
#include "config.h"
/*********************************************************************************************************
** 函數名稱 :IRQ_UART0()
** 函數功能 :串口0接收中斷服務程序
** 入口參數 :無
** 出口參數 :無
*********************************************************************************************************
*/
uint8 RecDat[20];
uint8 rcv_new;
uint8 rcv_i,snd_i,RecLen;
void __irq IRQ_UART1 (void)
{
uint8 i,IIR;
//i=0;
while (((IIR=U1IIR)&0x01)==0)
{
switch(IIR&0x0e)
{
case 0x02:
break;
case 0x04:
U1IER=U1IER&(~0x01);
for(i=0;i<3;i++)
RecDat[rcv_i++]=U1RBR;
U1IER=U1IER|(0x01);
break;
case 0x0c:
U1IER=U1IER&(~0x01);
for (i=0;i<15;i++)
{
if ((U1LSR&0x01)==0x01)
RecDat[rcv_i++]=U1RBR;
}
snd_i=rcv_i;
RecLen=rcv_i;
rcv_i=0;
rcv_new=1;
U1IER=U1IER|(0x01);
break;
default:
break;
}
}
VICVectAddr = 0x00; // 中斷處理結束
}
/*
*********************************************************************************************************
** 函數名稱 :UART0_SendByte()
** 函數功能 :向串口0發送1字節數據
** 入口參數 :dat 要發送的數據
** 出口參數 :無
*********************************************************************************************************
*/
void UART1_SendByte (uint8 dat)
{
U1THR = dat; // 要發送的數據
}
/*
*********************************************************************************************************
** 函數名稱 :UART0_SendBuf()
** 函數功能 :向串口發送8字節數據
** 入口參數 :dat 要發送的數據
** 出口參數 :無
*********************************************************************************************************
*/
void UART1_SendBuf (void)
{
uint8 i;
for (i=0; i<snd_i; i++)
UART1_SendByte(RecDat[i]);
while ((U1LSR & 0x20) == 0); // 等待數據發送完畢
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -