📄 irda.c
字号:
/****************************************Copyright (c)**************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.zyinside.com
**
**--------------File Info-------------------------------------------------------------------------------
** File Name : IrDA.c
** Last modified Date: 2006-03-25
** Last Version : v1.0
** Description : S3C2410的串口软件包 (查询控制方式)
**
**------------------------------------------------------------------------------------------------------
** Created By : 甘达
** Created date : 2006-03-25
** Version : v1.0
** Descriptions :
**
**------------------------------------------------------------------------------------------------------
** Modified by :
** Modified date :
** Version :
** Description :
**
********************************************************************************************************/
#include "config.h"
/*********************************************************************************************************
** Function name: IrDA_Init
** Descriptions : 初始化串口。设置为8位数据位,1位停止位,无奇偶校验,波特率为UART_BPS,IrDA模式
** Input : 无
** Outpu : 无
** Created by : 甘达
** Created Date : 2006-03-25
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void IrDA_Init(uint32 BPS)
{
// IO口设置 (GPH3,GPH2)
rGPHCON = (rGPHCON & (~0x0000F000)) | (0x0000A000);
rGPHUP = rGPHUP | (0x03<<6);
// 串口模式设置
rUFCON2 = 0x00; // 禁止FIFO功能
rUMCON2 = 0x00; // AFC(流控制)禁能
rULCON2 = 0x03 | 1<<6; // IRDA,无奇偶校验,1位停止位,8位数据位
rUCON2 = 0x245; // 使用PCLK来生成波特率,发送中断为电平触发模式,接收中断为边沿触发模式,
// 禁止接收超时中断,使能接收错误中断,正常工作模式,中断或查询方式(非DMA)
// 串口波特率设置
rUBRDIV2=(int)(PCLK/16.0/BPS + 0.5) -1;
OSTimeDly(OS_TICKS_PER_SEC/10);
rGPBCON = rGPBCON | 0x01<<2;
rGPBUP = rGPBUP | 0x01<<1;
rGPBDAT = rGPBDAT | 0x01<<1;
}
/*********************************************************************************************************
** Function name: IrDA_SendByte
** Descriptions : 向串口发送字节数据,并等待发送完毕。
** Input : data 要发送的数据
** Output : 无
** Created by : 甘达
** Created Date : 2006-03-25
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void IrDA_SendByte(uint8 data)
{
do
{
OSTimeDly(1);
}
while(!(rUTRSTAT2 & 0x02)); // 等待发送器THR为空
OSTimeDly(1);
rUTXH2 = data; // 发送数据
}
/*********************************************************************************************************
** Function name: IrDA_ReceiveByte
** Descriptions : 向串口接收数据。
** Input : 放置接收数据的地址
** Output : TRUE成功接收, FALSE接收超时
** Created by : 甘达
** Created Date : 2006-03-25
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint8 IrDA_ReceiveByte(uint8 *data)
{ uint8 i;
for(i=0; i<1000; i++)
{
if(!(rUTRSTAT2 & 0x1))
{
i++;
}
else
{
OSTimeDly(1);
*data = rURXH2;
return(TRUE);
}
}
return(FALSE);
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -