uart.c
void UartInit(void)
{
SCON = 0x50;
AUXR |= 0x01;
AUXR |= 0x04;
T2L = 0x8F;
T2H = 0xFD;
AUXR |= 0x10;
ES=1;
}
void Uart_Send_String(unsigned chra *Uart_String)
{
while(*Uart_String != '\0')
{
SBUF = *Uart_String;;
while(TI==0)
TI=0;
Uart_String++;
}
}
uart.h
#ifndef __UART_H__
#define __UART_H__
#include <stc15f2s60k2.h>
void UartInit(void);
void Uart_Send_String(unsigned chra *Uart_String);
#endif
main.c 主函数中的定义
#include "uart.h"
#include "stdio.h"
unsigned char Uart_Buf[9];
unsigned char Uart_Buf_Index=0;
unsigned char Uart_Slow;
void main(void)
{
All_Init();
Timer1Init();
UartInit();
while(1)
{
Key_Proc();
Uart_Proc();
}
}
void tm1_isr() interrupt 3
{
if(++Uart_Slow==100) Uart_Slow=0;
}
void Uart() interrupt 4
{
if(RI)
{
RI=0;
Uart_Buf[Uart_Buf_Index++] = SUBF;
}
}
void Uart_Proc(void)
{
if(Uart_Slow) return;
Uart_Slow=1;
}