📄 uart.c
字号:
/****************************************Copyright (c)**************************************************
** qsw
**
**
**
**--------------File Info-------------------------------------------------------------------------------
** File name:
** Last modified Date:
** Last Version:
** Descriptions:
**
**
**------------------------------------------------------------------------------------------------------
** Created by: qsw
** Created date: 2007.11.21
** Version: V1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include "..\..\main\main.h"
uint8 Uart0_RevCnt = 0;
uint8 Uart0_RevFlg = 0;
uint16 Uart0_RevOver = 0xFFFF;
uint8 Uart0_ReciveBuf[COM_BUFFER_SIZE];
uint8 Uart0_SendBuf[COM_BUFFER_SIZE];
uint8 Uart1_RevCnt = 0;
uint8 Uart1_RevFlg = 0;
uint16 Uart1_RevOver = 0xFFFF;
uint8 Uart1_ReciveBuf[COM_BUFFER_SIZE];
uint8 Uart1_SendBuf[COM_BUFFER_SIZE];
/**************************************************************************************************
**Name: void VS1003_Power()
**Function: turn off the card's power, and turn on
**Input: NULL
**Output: NULL
**************************************************************************************************/
void UART0_Init(uint32 bps)
{
uint16 Fdiv;
PINSEL0 &= 0xfffffff0; /* Select the pins for Uart 选择管脚为UART0 */
PINSEL0 |= 0x00000005;
U0LCR = 0x80; /* Enable to access the frequenc regecter 允许访问分频因子寄存器 */
Fdiv = (Fpclk / 16) / bps; /* Set the baudrate设置波特率 */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0x03; /* Disable to access the frequenc regecter 禁止访问分频因子寄存器 */
/* set to 8,1,n 且设置为8,1,n */
U0IER = 0x00;
U0FCR = 0x00;
U0FCR = 0x87; /* 初始化FIFO */
//U0FCR = 0x81; // 使能FIFO,并设置触发点为8字节
//U0IER = 0x01; // 允许RBR中断,即接收中断
//IRQEnable(); // 使能IRQ中断
/* 使能UART0中断 */
//VICIntSelect = 0x00000000; // 设置所有的通道为IRQ中断
//VICVectCntl0 = 0x20 | 0x06; // UART0分配到IRQ slot0,即最高优先级
//VICVectAddr0 = (uint32)UART0_IRQ; // 设置UART0向量地址
//VICIntEnable = 1 << 0x06; // 使能UART0中断
}
/**************************************************************************************************
**Name: void VS1003_Power()
**Function: turn off the card's power, and turn on
**Input: NULL
**Output: NULL
**************************************************************************************************/
void __irq UART0_IRQ(void)
{
if(0x04 ==(U0IIR&0x0F))
{
switch(Uart0_RevFlg)
{
case 0x00:
break;
default:
Uart0_RevFlg=0x00;
Uart0_RevCnt=0;
break;
}
if(Uart0_RevCnt >= 400)
{
Uart0_RevCnt = 0;
}
}
VICVectAddr = 0x00;
}
/**************************************************************************************************
**Name:
**Function:
**Input:
**Output:
**************************************************************************************************/
void UART0_SendByte (uint8 data)
{
OS_ENTER_CRITICAL();
U0THR = data;
while ((U0LSR & 0x40) == 0); // 等待数据发送完毕
OS_EXIT_CRITICAL();
}
/**************************************************************************************************
**Name:
**Function:
**Input:
**Output:
**************************************************************************************************/
void UART0_Sendblock(uint8 *str, uint16 len)
{
uint16 i;
for(i=0;i<len;i++)
{
UART0_SendByte(*str++);
}
}
/**************************************************************************************************
**Name:
**Function:
**Input:
**Output:
**************************************************************************************************/
void UART1_Init(uint32 bps)
{
uint16 Fdiv;
U1LCR = 0x83; // 允许访问分频因子寄存器 */
Fdiv = (Fpclk / 16) / bps; // 设置波特率 */
U1DLM = Fdiv / 256;
U1DLL = Fdiv % 256;
U1LCR = 0x03; //* 禁止访问分频因子寄存器设置字长度 */
U1FCR = 0x00;
U1IER = 0x00;
//U1FCR = 0x01;
//U1IER = 0x01;
//VICIntSelect = 0x00000000; // 设置所有的通道为IRQ中断
//VICVectCntl2 = 0x27; // uart1 中断7
//VICVectAddr1 = (uint32)UART1_IRQ; // 设置UART0向量地址
//VICIntEnable = 1 << 0x06; // 使能UART0中断
}
/**************************************************************************************************
**Name:
**Function:
**Input:
**Output:
**************************************************************************************************/
void UART1_SendByte(uint8 data)
{
OS_ENTER_CRITICAL();
U1THR = data; // 发送数据
while( (U1LSR&0x40)==0 ); // 等待数据发送完毕
OS_EXIT_CRITICAL();
}
/**************************************************************************************************
**Name:
**Function:
**Input:
**Output:
**************************************************************************************************/
void UART1_SendBlock(uint8 *str, uint16 len)
{
uint16 i;
for(i=0;i<len;i++)
{
UART1_SendByte(*str++);
}
}
/**************************************************************************************************
**Name:
**Function:
**Input:
**Output:
**************************************************************************************************/
void __irq UART1_IRQ(void)
{
if( 0x04==(U1IIR&0x0F))
{
switch (Uart1_RevFlg)
{
case 0x00:
break;
default:
Uart1_RevFlg=0x00;
Uart1_RevCnt=0;
break;
}
if(Uart1_RevCnt >= 100)
{
Uart1_RevCnt = 0;
}
VICVectAddr = 0x00;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -