标签:
#include "uart.h"
#define UART2
#define uart_115200 1
void Init_UART2(void)
{
#ifdef UART2
UART1_CR1=0x00;
UART1_CR2=0x00;
UART1_CR3=0x00;
#ifdef uart_9600
UART1_BRR2=0x03; // 16M 9600 682
UART1_BRR1=0x68;
#endif
#ifdef uart_115200
UART1_BRR2=0x0b; //16M 115200 D05
UART1_BRR1=0x08; // 8B
#endif
UART1_CR2|=0x2c;//允许接收,发送,开接收中断
#endif
}
/*
发送一个字符
*/
void UART2_sendchar(unsigned char td)
{
#ifdef UART2
while((UART1_SR & 0x80)==0x00);
UART1_DR=td;
#endif
}
/*
发送一个字符串,遇到\0结束
*/
void UART2_sendstr(unsigned char *pStr)//发送字符串
{
#ifdef UART2
while(*pStr)
{
UART2_sendchar(*pStr++);
}
#endif
}
/*
串口发送N字节数据
*/
void UART2_sendNByte(unsigned char *pStr,unsigned char len)
{
#ifdef UART2
for(;len>0;len--)
{
UART2_sendchar(*pStr++);
}
#endif
}
#pragma vector= _INT_UART1_RX//UART2_R_OR_vector//0x19
__interrupt void UART2_R_OR_IRQHandler(void)
{
volatile unsigned char i;
while(!(UART1_SR&0X20)==0X20);//UART2_SR &=~0X20;
UART1_SR&=(~0x20);
i=UART1_SR;
return;
}
标签:
原文地址:http://www.cnblogs.com/yqsqqq/p/4193949.html